Skip to content

Commit

Permalink
Migrate and add migration/removed events if GV2 migration removed us
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Feb 28, 2022
1 parent 9b269cb commit dbed3cb
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions ts/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
approvalRequired,
conversation,
Expand Down Expand Up @@ -2339,8 +2351,7 @@ export async function respondToGroupV2Migration({
}

const ourUuid = window.storage.user.getCheckedUuid().toString();
const wereWePreviouslyAMember =
!conversation.get('left') && conversation.hasMember(ourUuid);
const wereWePreviouslyAMember = conversation.hasMember(ourUuid);

// Derive GroupV2 fields
const groupV1IdBuffer = Bytes.fromBinary(previousGroupV1Id);
Expand Down Expand Up @@ -2423,22 +2434,30 @@ export async function respondToGroupV2Migration({
`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) {
log.info(
`respondToGroupV2Migration/${logId}: Upgrading group with migration/removed events`
);
const ourNumber = window.textsecure.storage.user.getNumber();
await updateGroup({
conversation,
receivedAt,
sentAt,
updates: {
newAttributes: {
...conversation.attributes,
// Because we're using attributes here, we upgrade this to a v2 group
...attributes,
left: true,
members: (conversation.get('members') || []).filter(
item => item !== ourUuid && item !== ourNumber
),
},
groupChangeMessages: [
getBasicMigrationBubble(),
{
...generateBasicMessage(),
type: 'group-v2-change',
Expand All @@ -2457,6 +2476,21 @@ export async function respondToGroupV2Migration({
});
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;
}
Expand Down

0 comments on commit dbed3cb

Please sign in to comment.