Show 'you were removed from group' if dropped during migration

This commit is contained in:
Scott Nonnenberg 2021-01-12 07:44:44 -08:00
parent fd7b18e382
commit d1355d5874
5 changed files with 79 additions and 13 deletions

View File

@ -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;

View File

@ -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 (
<GroupV1DisabledActions
i18n={i18n}

View File

@ -705,7 +705,7 @@ export async function hasV1GroupBeenMigrated(
return true;
} catch (error) {
const { code } = error;
return code !== GROUP_NONEXISTENT_CODE && code !== GROUP_ACCESS_DENIED_CODE;
return code !== GROUP_NONEXISTENT_CODE;
}
}
@ -806,6 +806,13 @@ export async function getGroupMigrationMembers(
`getGroupMigrationMembers/${logId}: membersV2 - missing local contact for ${e164}, skipping.`
);
}
if (!contact.isMe() && window.GV2_MIGRATION_DISABLE_ADD) {
window.log.warn(
`getGroupMigrationMembers/${logId}: membersV2 - skipping ${e164} due to GV2_MIGRATION_DISABLE_ADD flag`
);
return null;
}
if (!contact.get('uuid')) {
window.log.warn(
`getGroupMigrationMembers/${logId}: membersV2 - missing uuid for ${e164}, skipping.`
@ -886,6 +893,14 @@ export async function getGroupMigrationMembers(
return null;
}
if (!contact.isMe() && window.GV2_MIGRATION_DISABLE_INVITE) {
window.log.warn(
`getGroupMigrationMembers/${logId}: pendingMembersV2 - skipping ${e164} due to GV2_MIGRATION_DISABLE_INVITE flag`
);
droppedGV2MemberIds.push(conversationId);
return null;
}
if (!contact.get('uuid')) {
window.log.warn(
`getGroupMigrationMembers/${logId}: pendingMembersV2 - missing uuid for ${e164}, skipping.`
@ -1251,11 +1266,10 @@ export async function respondToGroupV2Migration({
!conversation.get('left') &&
ourConversationId &&
conversation.hasMember(ourConversationId);
if (!ourConversationId || !wereWePreviouslyAMember) {
window.log.info(
`respondToGroupV2Migration: Not currently a member of ${conversation.idForLogging()}, returning early.`
if (!ourConversationId) {
throw new Error(
`respondToGroupV2Migration: No conversationId when attempting to migrate ${conversation.idForLogging()}. Returning early.`
);
return;
}
// Derive GroupV2 fields
@ -1317,12 +1331,56 @@ export async function respondToGroupV2Migration({
window.log.info(
`respondToGroupV2Migration/${logId}: Failed to access log endpoint; fetching full group state`
);
firstGroupState = await makeRequestWithTemporalRetry({
logId: `getGroup/${logId}`,
publicParams,
secretParams,
request: (sender, options) => 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;
}

View File

@ -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"

2
ts/window.d.ts vendored
View File

@ -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 {