From d1355d5874f53339d8e2a4ecca68dce780f12a6d Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 12 Jan 2021 07:44:44 -0800 Subject: [PATCH] Show 'you were removed from group' if dropped during migration --- preload.js | 3 ++ ts/components/CompositionArea.tsx | 5 +- ts/groups.ts | 80 ++++++++++++++++++++++++++----- ts/util/lint/exceptions.json | 2 +- ts/window.d.ts | 2 + 5 files changed, 79 insertions(+), 13 deletions(-) diff --git a/preload.js b/preload.js index 984c56c8a..1b5b14e6c 100644 --- a/preload.js +++ b/preload.js @@ -32,6 +32,9 @@ try { window.GV2_ENABLE_CHANGE_PROCESSING = true; window.GV2_ENABLE_STATE_PROCESSING = true; + window.GV2_MIGRATION_DISABLE_ADD = false; + window.GV2_MIGRATION_DISABLE_INVITE = false; + window.platform = process.platform; window.getTitle = () => title; window.getEnvironment = () => config.environment; diff --git a/ts/components/CompositionArea.tsx b/ts/components/CompositionArea.tsx index 7dc68e988..7ff18cd14 100644 --- a/ts/components/CompositionArea.tsx +++ b/ts/components/CompositionArea.tsx @@ -33,6 +33,7 @@ export type OwnProps = { readonly groupVersion?: 1 | 2; readonly isGroupV1AndDisabled?: boolean; readonly isMissingMandatoryProfileSharing?: boolean; + readonly left?: boolean; readonly messageRequestsEnabled?: boolean; readonly acceptedMessageRequest?: boolean; readonly compositionApi?: React.MutableRefObject<{ @@ -131,6 +132,7 @@ export const CompositionArea = ({ groupVersion, isBlocked, isMissingMandatoryProfileSharing, + left, messageRequestsEnabled, name, onAccept, @@ -370,6 +372,7 @@ export const CompositionArea = ({ // If no message request, but we haven't shared profile yet, we show profile-sharing UI if ( + !left && (conversationType === 'direct' || (conversationType === 'group' && groupVersion === 1)) && isMissingMandatoryProfileSharing @@ -391,7 +394,7 @@ export const CompositionArea = ({ } // If this is a V1 group, now disabled entirely, we show UI to help them upgrade - if (isGroupV1AndDisabled) { + if (!left && isGroupV1AndDisabled) { return ( sender.getGroup(options), - }); + try { + firstGroupState = await makeRequestWithTemporalRetry({ + logId: `getGroup/${logId}`, + publicParams, + secretParams, + request: (sender, options) => sender.getGroup(options), + }); + } catch (secondError) { + if (secondError.code === GROUP_ACCESS_DENIED_CODE) { + window.log.info( + `respondToGroupV2Migration/${logId}: Failed to access state endpoint; user is no longer part of group` + ); + + // We don't want to add another event to the timeline + if (wereWePreviouslyAMember) { + const ourNumber = window.textsecure.storage.user.getNumber(); + await updateGroup({ + conversation, + receivedAt, + sentAt, + updates: { + newAttributes: { + ...conversation.attributes, + left: true, + members: (conversation.get('members') || []).filter( + item => item !== ourConversationId && item !== ourNumber + ), + }, + groupChangeMessages: [ + { + ...generateBasicMessage(), + type: 'group-v2-change', + groupV2Change: { + details: [ + { + type: 'member-remove' as const, + conversationId: ourConversationId, + }, + ], + }, + }, + ], + members: [], + }, + }); + return; + } + } + throw secondError; + } } else { throw error; } diff --git a/ts/util/lint/exceptions.json b/ts/util/lint/exceptions.json index 395d93a9c..091f07cf6 100644 --- a/ts/util/lint/exceptions.json +++ b/ts/util/lint/exceptions.json @@ -14455,7 +14455,7 @@ "rule": "DOM-innerHTML", "path": "ts/components/CompositionArea.tsx", "line": " el.innerHTML = '';", - "lineNumber": 91, + "lineNumber": 92, "reasonCategory": "usageTrusted", "updated": "2020-06-03T19:23:21.195Z", "reasonDetail": "Our code, no user input, only clearing out the dom" diff --git a/ts/window.d.ts b/ts/window.d.ts index 72a6128b0..f12fa3920 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -497,6 +497,8 @@ declare global { GV2_ENABLE_SINGLE_CHANGE_PROCESSING: boolean; GV2_ENABLE_CHANGE_PROCESSING: boolean; GV2_ENABLE_STATE_PROCESSING: boolean; + GV2_MIGRATION_DISABLE_ADD: boolean; + GV2_MIGRATION_DISABLE_INVITE: boolean; } interface Error {