From d2dd98cd9d9d9df96bb1bc2a1bc201ac48458afe Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 26 Nov 2024 10:03:19 +1100 Subject: [PATCH] fix: various PR reviews, fixes for integration tests --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- protos/SignalService.proto | 1 - ts/components/MemberListItem.tsx | 2 +- .../conversation/MessageRequestButtons.tsx | 6 ++++- .../overlay/OverlayRightPanelSettings.tsx | 18 ++++++------- .../disappearing-messages/TimeOptions.tsx | 2 +- ts/components/dialog/InviteContactsDialog.tsx | 4 +-- .../dialog/UpdateGroupNameDialog.tsx | 1 - .../leftpane/overlay/OverlayClosedGroup.tsx | 4 +-- ts/components/menu/Menu.tsx | 2 ++ ts/hooks/useParamSelector.ts | 2 +- ts/interactions/conversationInteractions.ts | 19 +++++++++++--- ts/models/conversation.ts | 2 ++ ts/node/hexStrings.ts | 4 +-- ts/react.d.ts | 26 +++++++++---------- .../SwarmPollingGroupConfig.ts | 10 +++---- ts/session/onions/onionPath.ts | 1 + ts/session/utils/calling/CallManager.ts | 6 ++++- .../libsession_utils_multi_encrypt.ts | 8 +++--- ts/state/ducks/metaGroups.ts | 2 +- .../browser/libsession_worker_interface.ts | 3 ++- 21 files changed, 73 insertions(+), 52 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 7e731a340..9bf0d6f2d 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -14,7 +14,7 @@ Remember, you can preview this before saving it. ### Contributor checklist: - [ ] My commits are in nice logical chunks with [good commit messages](http://chris.beams.io/posts/git-commit/) -- [ ] My changes are [rebased](https://blog.axosoft.com/golden-rule-of-rebasing-in-git/) on the latest [`clearnet`](https://github.com/session-foundation/session-desktop/tree/clearnet) branch +- [ ] My changes are [rebased](https://blog.axosoft.com/golden-rule-of-rebasing-in-git/) on the latest [`unstable`](https://github.com/session-foundation/session-desktop/tree/clearnet) branch - [ ] A `yarn ready` run passes successfully ([more about tests here](https://github.com/session-foundation/session-desktop/blob/master/CONTRIBUTING.md#tests)) - [ ] My changes are ready to be shipped to users diff --git a/protos/SignalService.proto b/protos/SignalService.proto index 853cef89b..ed9535b50 100644 --- a/protos/SignalService.proto +++ b/protos/SignalService.proto @@ -148,7 +148,6 @@ message GroupUpdateMessage { optional GroupUpdateMemberLeftNotificationMessage memberLeftNotificationMessage = 8; } - message DataMessage { // 7 = timestamp unused and should not be used diff --git a/ts/components/MemberListItem.tsx b/ts/components/MemberListItem.tsx index a7ab0ba24..6fafbf41e 100644 --- a/ts/components/MemberListItem.tsx +++ b/ts/components/MemberListItem.tsx @@ -158,7 +158,7 @@ const StyledGroupStatusText = styled.span<{ isFailure: boolean }>` font-size: var(--font-size-xs); margin-top: var(--margins-xs); min-width: 100px; // min-width so that the dialog does not resize when the status change to sending - text-align: left; + text-align: start; `; const GroupStatusText = ({ groupPk, pubkey }: { pubkey: PubkeyType; groupPk: GroupPubkeyType }) => { diff --git a/ts/components/conversation/MessageRequestButtons.tsx b/ts/components/conversation/MessageRequestButtons.tsx index 5cd21cae6..ea0afae94 100644 --- a/ts/components/conversation/MessageRequestButtons.tsx +++ b/ts/components/conversation/MessageRequestButtons.tsx @@ -17,6 +17,7 @@ import { ConversationOutgoingRequestExplanation, InvitedToGroupControlMessage, } from './SubtleNotification'; +import { NetworkTime } from '../../util/NetworkTime'; const MessageRequestContainer = styled.div` display: flex; @@ -101,7 +102,10 @@ export const ConversationMessageRequestButtons = () => { { - void handleAcceptConversationRequest({ convoId: selectedConvoId }); + void handleAcceptConversationRequest({ + convoId: selectedConvoId, + approvalMessageTimestamp: NetworkTime.now(), + }); }} text={window.i18n('accept')} dataTestId="accept-message-request" diff --git a/ts/components/conversation/right-panel/overlay/OverlayRightPanelSettings.tsx b/ts/components/conversation/right-panel/overlay/OverlayRightPanelSettings.tsx index 6db70ec2a..33906be8d 100644 --- a/ts/components/conversation/right-panel/overlay/OverlayRightPanelSettings.tsx +++ b/ts/components/conversation/right-panel/overlay/OverlayRightPanelSettings.tsx @@ -401,16 +401,14 @@ export const OverlayRightPanelSettings = () => { {isGroup && ( - <> - void deleteConvoAction()} - color={'var(--danger-color)'} - iconType={'delete'} - /> - + void deleteConvoAction()} + color={'var(--danger-color)'} + iconType={'delete'} + /> )} diff --git a/ts/components/conversation/right-panel/overlay/disappearing-messages/TimeOptions.tsx b/ts/components/conversation/right-panel/overlay/disappearing-messages/TimeOptions.tsx index 3ffcb1bdf..26e269805 100644 --- a/ts/components/conversation/right-panel/overlay/disappearing-messages/TimeOptions.tsx +++ b/ts/components/conversation/right-panel/overlay/disappearing-messages/TimeOptions.tsx @@ -39,7 +39,7 @@ export const TimeOptions = (props: TimerOptionsProps) => { setSelected(option.value); }} disabled={disabled} - dataTestId={`time-option-${option.value}`} // we want "time-option-3600", etc as accessibility id + dataTestId={`time-option-${option.value}-seconds`} // we want "time-option-3600-seconds", etc as accessibility id /> ); })} diff --git a/ts/components/dialog/InviteContactsDialog.tsx b/ts/components/dialog/InviteContactsDialog.tsx index fe4294324..f28f66f07 100644 --- a/ts/components/dialog/InviteContactsDialog.tsx +++ b/ts/components/dialog/InviteContactsDialog.tsx @@ -30,7 +30,7 @@ import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/S import { SessionSpinner } from '../loading'; import { SessionToggle } from '../basic/SessionToggle'; import { GroupInviteRequiredVersionBanner } from '../NoticeBanner'; -import { isDevProd } from '../../shared/env_vars'; +import { hasClosedGroupV2QAButtons } from '../../shared/env_vars'; import { ConversationTypeEnum } from '../../models/types'; import { Localizer } from '../basic/Localizer'; @@ -188,7 +188,7 @@ const InviteContactsDialogInner = (props: Props) => { {/* TODO: localize those strings once out releasing those buttons for real Remove after QA */} - {isGroupV2 && isDevProd() && ( + {isGroupV2 && hasClosedGroupV2QAButtons() && ( <> Share History?{' '} diff --git a/ts/components/dialog/UpdateGroupNameDialog.tsx b/ts/components/dialog/UpdateGroupNameDialog.tsx index 8f3e23fd4..410b214b4 100644 --- a/ts/components/dialog/UpdateGroupNameDialog.tsx +++ b/ts/components/dialog/UpdateGroupNameDialog.tsx @@ -153,7 +153,6 @@ export function UpdateGroupNameDialog(props: { conversationId: string }) { const cancelText = window.i18n('cancel'); const isAdmin = !isCommunity; - // return null; return ( { {/* TODO: localize those strings once out releasing those buttons for real Remove after QA */} - {isDevProd() && ( + {hasClosedGroupV2QAButtons() && ( <> Invite as admin?{' '} diff --git a/ts/components/menu/Menu.tsx b/ts/components/menu/Menu.tsx index 2e20402f7..64c1741d8 100644 --- a/ts/components/menu/Menu.tsx +++ b/ts/components/menu/Menu.tsx @@ -63,6 +63,7 @@ import { ConversationInteractionType, } from '../../interactions/types'; import { useLibGroupDestroyed } from '../../state/selectors/userGroups'; +import { NetworkTime } from '../../util/NetworkTime'; /** Menu items standardized */ @@ -446,6 +447,7 @@ export const AcceptMsgRequestMenuItem = () => { onClick={async () => { await handleAcceptConversationRequest({ convoId, + approvalMessageTimestamp: NetworkTime.now(), }); }} dataTestId="accept-menu-item" diff --git a/ts/hooks/useParamSelector.ts b/ts/hooks/useParamSelector.ts index 3ce69a42f..a4003f0c6 100644 --- a/ts/hooks/useParamSelector.ts +++ b/ts/hooks/useParamSelector.ts @@ -309,7 +309,7 @@ export function useIsOutgoingRequest(convoId?: string) { /** * Note: NOT to be exported: - * This selector is too generic and needs to be broken node in individual fields selectors. + * This selector is too generic and needs to be broken down into individual fields selectors. * Make sure when writing a selector that you fetch the data from libsession if needed. * (check useSortedGroupMembers() as an example) */ diff --git a/ts/interactions/conversationInteractions.ts b/ts/interactions/conversationInteractions.ts index 365ce475b..67b97e7d6 100644 --- a/ts/interactions/conversationInteractions.ts +++ b/ts/interactions/conversationInteractions.ts @@ -96,7 +96,20 @@ export async function unblockConvoById(conversationId: string) { ); } -export const handleAcceptConversationRequest = async ({ convoId }: { convoId: string }) => { +/** + * Accept if needed the message request from this user. + * Note: approvalMessageTimestamp is provided to be able to insert the "You've accepted the message request" at the right place. + * When accepting a message request by sending a message, we need to make sure the "You've accepted the message request" is before the + * message we are sending to the user. + * + */ +export const handleAcceptConversationRequest = async ({ + convoId, + approvalMessageTimestamp, +}: { + convoId: string; + approvalMessageTimestamp: number; +}) => { const convo = ConvoHub.use().get(convoId); if (!convo || (!convo.isPrivate() && !convo.isClosedGroupV2())) { return null; @@ -111,7 +124,7 @@ export const handleAcceptConversationRequest = async ({ convoId }: { convoId: st if (convo.isPrivate()) { // we only need the approval message (and sending a reply) when we are accepting a message request. i.e. someone sent us a message already and we didn't accept it yet. if (!previousIsApproved && previousDidApprovedMe) { - await convo.addOutgoingApprovalMessage(Date.now()); + await convo.addOutgoingApprovalMessage(approvalMessageTimestamp); await convo.sendMessageRequestResponse(); } @@ -993,7 +1006,7 @@ export async function promoteUsersInGroup({ return; } - // push one group change message were initial members are added to the group + // push one group change message where initial members are added to the group const membersHex = uniq(toPromote); const sentAt = NetworkTime.now(); const us = UserUtils.getOurPubKeyStrFromCache(); diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 6bbda4f52..8efbcc4ff 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -622,6 +622,7 @@ export class ConversationModel extends Backbone.Model { // handleAcceptConversationRequest will take care of sending response depending on the type of conversation, if needed await handleAcceptConversationRequest({ convoId: this.id, + approvalMessageTimestamp: NetworkTime.now() - 100, }); if (this.isOpenGroupV2()) { @@ -2109,6 +2110,7 @@ export class ConversationModel extends Backbone.Model { // handleAcceptConversationRequest will take care of sending response depending on the type of conversation await handleAcceptConversationRequest({ convoId: this.id, + approvalMessageTimestamp: NetworkTime.now() - 100, }); if (this.isOpenGroupV2()) { diff --git a/ts/node/hexStrings.ts b/ts/node/hexStrings.ts index 782da7a1d..bf907c509 100644 --- a/ts/node/hexStrings.ts +++ b/ts/node/hexStrings.ts @@ -9,12 +9,12 @@ const isHexString = (maybeHex: string) => /** * Returns the Uint8Array corresponding to the given string. * Note: this is different than the libsodium.from_hex(). - * This takes a string like "0102" and converts it to an UIin8Array like [1, 2] whereare + * This takes a string like "0102" and converts it to an UInt8Array like [1, 2] where * the libsodium one returns [0, 1, 0, 2] * * Throws an error if this string is not a hex string. * @param hexString the string to convert from - * @returns the Uint8Arrat + * @returns the Uint8Array */ const fromHexString = (hexString: string): Uint8Array => { if (!isHexString(hexString)) { diff --git a/ts/react.d.ts b/ts/react.d.ts index bb1859af3..b94435bf3 100644 --- a/ts/react.d.ts +++ b/ts/react.d.ts @@ -82,19 +82,19 @@ declare module 'react' { | 'accept-menu-item' // timer options - | 'time-option-0' - | 'time-option-5' - | 'time-option-10' - | 'time-option-30' - | 'time-option-60' - | 'time-option-300' - | 'time-option-1800' - | 'time-option-3600' - | 'time-option-21600' - | 'time-option-43200' - | 'time-option-86400' - | 'time-option-604800' - | 'time-option-1209600' + | 'time-option-0-seconds' + | 'time-option-5-seconds' + | 'time-option-10-seconds' + | 'time-option-30-seconds' + | 'time-option-60-seconds' + | 'time-option-300-seconds' + | 'time-option-1800-seconds' + | 'time-option-3600-seconds' + | 'time-option-21600-seconds' + | 'time-option-43200-seconds' + | 'time-option-86400-seconds' + | 'time-option-604800-seconds' + | 'time-option-1209600-seconds' // generic readably message (not control message) | 'message-content' diff --git a/ts/session/apis/snode_api/swarm_polling_config/SwarmPollingGroupConfig.ts b/ts/session/apis/snode_api/swarm_polling_config/SwarmPollingGroupConfig.ts index c4562bc78..5ab2a9a60 100644 --- a/ts/session/apis/snode_api/swarm_polling_config/SwarmPollingGroupConfig.ts +++ b/ts/session/apis/snode_api/swarm_polling_config/SwarmPollingGroupConfig.ts @@ -124,12 +124,10 @@ async function handleMetaMergeResults(groupPk: GroupPubkeyType) { ); } } - // mark ourselves as accepting the invite if needed - if (usMember?.memberStatus === 'INVITE_SENT' && keysAlreadyHaveAdmin) { - await MetaGroupWrapperActions.memberSetAccepted(groupPk, us); - } - // mark ourselves as accepting the promotion if needed - if (usMember?.memberStatus === 'PROMOTION_SENT' && keysAlreadyHaveAdmin) { + // Note: this call won't change anything if we are already an "accepted" admin, but will + // overwrite any other states for promotion. + if (keysAlreadyHaveAdmin && usMember) { + // mark ourselves as accepting the promotion if needed. await MetaGroupWrapperActions.memberSetPromotionAccepted(groupPk, us); } // this won't do anything if there is no need for a sync, so we can safely plan one diff --git a/ts/session/onions/onionPath.ts b/ts/session/onions/onionPath.ts index a7b792153..926a1f84c 100644 --- a/ts/session/onions/onionPath.ts +++ b/ts/session/onions/onionPath.ts @@ -526,6 +526,7 @@ async function buildNewOnionPathsWorker() { } window?.log?.info(`Built ${onionPaths.length} onion paths`); + window?.log?.debug(`onionPaths:`, JSON.stringify(onionPaths)); }, { retries: 3, // 4 total diff --git a/ts/session/utils/calling/CallManager.ts b/ts/session/utils/calling/CallManager.ts index 925ec2f88..ee8f738c3 100644 --- a/ts/session/utils/calling/CallManager.ts +++ b/ts/session/utils/calling/CallManager.ts @@ -535,7 +535,10 @@ export async function USER_callRecipient(recipient: string) { weAreCallerOnCurrentCall = true; // initiating a call is analogous to sending a message request - await handleAcceptConversationRequest({ convoId: recipient }); + await handleAcceptConversationRequest({ + convoId: recipient, + approvalMessageTimestamp: NetworkTime.now() - 100, + }); // Note: we do the sending of the preoffer manually as the sendTo1o1NonDurably rely on having a message saved to the db for MessageSentSuccess // which is not the case for a pre offer message (the message only exists in memory) @@ -936,6 +939,7 @@ export async function USER_acceptIncomingCallRequest(fromSender: string) { // consider the conversation completely approved await handleAcceptConversationRequest({ convoId: fromSender, + approvalMessageTimestamp: NetworkTime.now() - 100, }); } diff --git a/ts/session/utils/libsession/libsession_utils_multi_encrypt.ts b/ts/session/utils/libsession/libsession_utils_multi_encrypt.ts index efdf6b810..cc75b22a3 100644 --- a/ts/session/utils/libsession/libsession_utils_multi_encrypt.ts +++ b/ts/session/utils/libsession/libsession_utils_multi_encrypt.ts @@ -1,7 +1,7 @@ -import { EncryptionDomain } from 'libsession_util_nodejs'; -import { MultiEncryptWrapperActions } from '../../../webworker/workers/browser/libsession_worker_interface'; - -const allKnownEncryptionDomains: Array = ['SessionGroupKickedMessage']; +import { + allKnownEncryptionDomains, + MultiEncryptWrapperActions, +} from '../../../webworker/workers/browser/libsession_worker_interface'; /** * Try to decrypt the content with any type of encryption domains we know. diff --git a/ts/state/ducks/metaGroups.ts b/ts/state/ducks/metaGroups.ts index a9225198c..3147dd894 100644 --- a/ts/state/ducks/metaGroups.ts +++ b/ts/state/ducks/metaGroups.ts @@ -193,7 +193,7 @@ const initNewGroupInWrapper = createAsyncThunk( await convo.setIsApproved(true, false); await convo.commit(); // commit here too, as the poll needs it to be approved let groupMemberChange: GroupUpdateMemberChangeMessage | null = null; - // push one group change message were initial members are added to the group + // push one group change message where initial members are added to the group if (membersFromWrapper.length) { const membersHex = uniq(membersFromWrapper.map(m => m.pubkeyHex)); const sentAt = NetworkTime.now(); diff --git a/ts/webworker/workers/browser/libsession_worker_interface.ts b/ts/webworker/workers/browser/libsession_worker_interface.ts index 19a08691a..550799bee 100644 --- a/ts/webworker/workers/browser/libsession_worker_interface.ts +++ b/ts/webworker/workers/browser/libsession_worker_interface.ts @@ -21,6 +21,7 @@ import { UserGroupsGet, UserGroupsSet, UserGroupsWrapperActionsCalls, + EncryptionDomain, } from 'libsession_util_nodejs'; // eslint-disable-next-line import/order import { join } from 'path'; @@ -758,7 +759,7 @@ export const MultiEncryptWrapperActions: MultiEncryptActionsCalls = { >, }; -export const EncryptionDomains = ['SessionGroupKickedMessage'] as const; +export const allKnownEncryptionDomains: Array = ['SessionGroupKickedMessage']; export const BlindingActions: BlindingActionsCalls = { blindVersionPubkey: async (opts: Parameters[0]) =>