Skip to content

Commit

Permalink
Fix group updates for blocked users
Browse files Browse the repository at this point in the history
Co-authored-by: ayumi-signal <143036029+ayumi-signal@users.noreply.github.com>
  • Loading branch information
automated-signal and ayumi-signal committed Jan 31, 2024
1 parent 70a4dea commit 11a86ee
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
68 changes: 35 additions & 33 deletions ts/groups.ts
Expand Up @@ -3133,38 +3133,6 @@ async function updateGroup(
);
}

if (changeMessagesToSave.length > 0) {
try {
if (contactsWithoutProfileKey && contactsWithoutProfileKey.length > 0) {
await Promise.race([profileFetches, sleep(30 * SECOND)]);
log.info(
`updateGroup/${logId}: timed out or finished fetching ${contactsWithoutProfileKey.length} profiles`
);
}
} catch (error) {
log.error(
`updateGroup/${logId}: failed to fetch missing profiles`,
Errors.toLogFormat(error)
);
}
await appendChangeMessages(conversation, changeMessagesToSave);
}

// We update group membership last to ensure that all notifications are in place before
// the group updates happen on the model.

conversation.set({
...newAttributes,
active_at: activeAt,
});

if (idChanged) {
conversation.trigger('idUpdated', conversation, 'groupId', previousId);
}

// Save these most recent updates to conversation
await updateConversation(conversation.attributes);

// If we've been added by a blocked contact, then schedule a task to leave group
const justAdded = !wasMemberOrPending && isMemberOrPending;
const addedBy =
Expand Down Expand Up @@ -3193,9 +3161,43 @@ async function updateGroup(
};

// Cannot await here, would infinitely block queue
void waitThenLeave();
drop(waitThenLeave());

// Return early to discard group changes resulting from the blocked user's action.
return;
}
}

// We update group membership last to ensure that all notifications are in place before
// the group updates happen on the model.
if (changeMessagesToSave.length > 0) {
try {
if (contactsWithoutProfileKey && contactsWithoutProfileKey.length > 0) {
await Promise.race([profileFetches, sleep(30 * SECOND)]);
log.info(
`updateGroup/${logId}: timed out or finished fetching ${contactsWithoutProfileKey.length} profiles`
);
}
} catch (error) {
log.error(
`updateGroup/${logId}: failed to fetch missing profiles`,
Errors.toLogFormat(error)
);
}
await appendChangeMessages(conversation, changeMessagesToSave);
}

conversation.set({
...newAttributes,
active_at: activeAt,
});

if (idChanged) {
conversation.trigger('idUpdated', conversation, 'groupId', previousId);
}

// Save these most recent updates to conversation
await updateConversation(conversation.attributes);
}

// Exported for testing
Expand Down
10 changes: 4 additions & 6 deletions ts/textsecure/MessageReceiver.ts
Expand Up @@ -1602,14 +1602,12 @@ export default class MessageReceiver
);
}

// We want to process GroupV2 updates, even from blocked users. We'll drop them later.
if (
!isGroupV2 &&
((envelope.source && this.isBlocked(envelope.source)) ||
(envelope.sourceServiceId &&
this.isServiceIdBlocked(envelope.sourceServiceId)))
(envelope.source && this.isBlocked(envelope.source)) ||
(envelope.sourceServiceId &&
this.isServiceIdBlocked(envelope.sourceServiceId))
) {
log.info(`${logId}: Dropping non-GV2 message from blocked sender`);
log.info(`${logId}: Dropping message from blocked sender`);
this.removeFromCache(envelope);
return { plaintext: undefined, envelope };
}
Expand Down

0 comments on commit 11a86ee

Please sign in to comment.