Fix group updates for blocked users

This commit is contained in:
ayumi-signal 2024-01-31 12:19:47 -08:00 committed by GitHub
parent 47c9598283
commit 581594ae9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 39 deletions

View file

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

View file

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