Migrate and add migration/removed events if GV2 migration removed us

This commit is contained in:
Scott Nonnenberg 2022-02-28 14:32:50 -08:00 committed by GitHub
parent 9b269cb43f
commit dbed3cbd2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2228,6 +2228,18 @@ export function buildMigrationBubble(
}; };
} }
export function getBasicMigrationBubble(): MessageAttributesType {
return {
...generateBasicMessage(),
type: 'group-v1-migration',
groupMigration: {
areWeInvited: false,
invitedMembers: [],
droppedMemberIds: [],
},
};
}
export async function joinGroupV2ViaLinkAndMigrate({ export async function joinGroupV2ViaLinkAndMigrate({
approvalRequired, approvalRequired,
conversation, conversation,
@ -2339,8 +2351,7 @@ export async function respondToGroupV2Migration({
} }
const ourUuid = window.storage.user.getCheckedUuid().toString(); const ourUuid = window.storage.user.getCheckedUuid().toString();
const wereWePreviouslyAMember = const wereWePreviouslyAMember = conversation.hasMember(ourUuid);
!conversation.get('left') && conversation.hasMember(ourUuid);
// Derive GroupV2 fields // Derive GroupV2 fields
const groupV1IdBuffer = Bytes.fromBinary(previousGroupV1Id); const groupV1IdBuffer = Bytes.fromBinary(previousGroupV1Id);
@ -2423,8 +2434,14 @@ export async function respondToGroupV2Migration({
`respondToGroupV2Migration/${logId}: Failed to access state endpoint; user is no longer part of group` `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 (window.storage.blocked.isGroupBlocked(previousGroupV1Id)) {
window.storage.blocked.addBlockedGroup(groupId);
}
if (wereWePreviouslyAMember) { if (wereWePreviouslyAMember) {
log.info(
`respondToGroupV2Migration/${logId}: Upgrading group with migration/removed events`
);
const ourNumber = window.textsecure.storage.user.getNumber(); const ourNumber = window.textsecure.storage.user.getNumber();
await updateGroup({ await updateGroup({
conversation, conversation,
@ -2432,13 +2449,15 @@ export async function respondToGroupV2Migration({
sentAt, sentAt,
updates: { updates: {
newAttributes: { newAttributes: {
...conversation.attributes, // Because we're using attributes here, we upgrade this to a v2 group
...attributes,
left: true, left: true,
members: (conversation.get('members') || []).filter( members: (conversation.get('members') || []).filter(
item => item !== ourUuid && item !== ourNumber item => item !== ourUuid && item !== ourNumber
), ),
}, },
groupChangeMessages: [ groupChangeMessages: [
getBasicMigrationBubble(),
{ {
...generateBasicMessage(), ...generateBasicMessage(),
type: 'group-v2-change', type: 'group-v2-change',
@ -2457,6 +2476,21 @@ export async function respondToGroupV2Migration({
}); });
return; return;
} }
log.info(
`respondToGroupV2Migration/${logId}: Upgrading group with migration event; no removed event`
);
await updateGroup({
conversation,
receivedAt,
sentAt,
updates: {
newAttributes: attributes,
groupChangeMessages: [getBasicMigrationBubble()],
members: [],
},
});
return;
} }
throw secondError; throw secondError;
} }