Properly handle groupIds in incoming block sync

Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
automated-signal 2022-01-19 17:49:52 -08:00 committed by GitHub
parent cc185159d9
commit 36a02e8e09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 15 deletions

View File

@ -2504,6 +2504,23 @@ export async function startApp(): Promise<void> {
);
return;
}
if (conversation?.isBlocked()) {
log.info(
`onTyping: conversation ${conversation.idForLogging()} is blocked, dropping typing message`
);
return;
}
const senderConversation = window.ConversationController.get(senderId);
if (!senderConversation) {
log.warn('onTyping: No conversation for sender!');
return;
}
if (senderConversation.isBlocked()) {
log.info(
`onTyping: sender ${conversation.idForLogging()} is blocked, dropping typing message`
);
return;
}
conversation.notifyTyping({
isTyping: started,

View File

@ -878,7 +878,7 @@ export class ConversationModel extends window.Backbone
block({ viaStorageServiceSync = false } = {}): void {
let blocked = false;
const isBlocked = this.isBlocked();
const wasBlocked = this.isBlocked();
const uuid = this.get('uuid');
if (uuid) {
@ -898,14 +898,19 @@ export class ConversationModel extends window.Backbone
blocked = true;
}
if (!viaStorageServiceSync && !isBlocked && blocked) {
this.captureChange('block');
if (blocked && !wasBlocked) {
// We need to force a props refresh - blocked state is not in backbone attributes
this.trigger('change', this, { force: true });
if (!viaStorageServiceSync) {
this.captureChange('block');
}
}
}
unblock({ viaStorageServiceSync = false } = {}): boolean {
let unblocked = false;
const isBlocked = this.isBlocked();
const wasBlocked = this.isBlocked();
const uuid = this.get('uuid');
if (uuid) {
@ -925,8 +930,13 @@ export class ConversationModel extends window.Backbone
unblocked = true;
}
if (!viaStorageServiceSync && isBlocked && unblocked) {
this.captureChange('unblock');
if (unblocked && wasBlocked) {
// We need to force a props refresh - blocked state is not in backbone attributes
this.trigger('change', this, { force: true });
if (!viaStorageServiceSync) {
this.captureChange('unblock');
}
}
return unblocked;

View File

@ -4,7 +4,7 @@
/* eslint-disable no-bitwise */
/* eslint-disable camelcase */
import { isNumber, map } from 'lodash';
import { isNumber } from 'lodash';
import PQueue from 'p-queue';
import { v4 as getGuid } from 'uuid';
@ -2626,24 +2626,40 @@ export default class MessageReceiver
envelope: ProcessedEnvelope,
blocked: Proto.SyncMessage.IBlocked
): Promise<void> {
log.info('Setting these numbers as blocked:', blocked.numbers);
if (blocked.numbers) {
log.info('handleBlocked: Blocking these numbers:', blocked.numbers);
await this.storage.put('blocked', blocked.numbers);
}
if (blocked.uuids) {
const uuids = blocked.uuids.map((uuid, index) => {
return normalizeUuid(uuid, `handleBlocked.uuids.${index}`);
});
log.info('Setting these uuids as blocked:', uuids);
log.info('handleBlocked: Blocking these uuids:', uuids);
await this.storage.put('blocked-uuids', uuids);
}
const groupIds = map(blocked.groupIds, groupId => Bytes.toBinary(groupId));
log.info(
'Setting these groups as blocked:',
groupIds.map(groupId => `group(${groupId})`)
);
await this.storage.put('blocked-groups', groupIds);
if (blocked.groupIds) {
const groupV1Ids: Array<string> = [];
const groupIds: Array<string> = [];
blocked.groupIds.forEach(groupId => {
if (groupId.byteLength === GROUPV1_ID_LENGTH) {
groupV1Ids.push(Bytes.toBinary(groupId));
groupIds.push(this.deriveGroupV2FromV1(groupId));
} else if (groupId.byteLength === GROUPV2_ID_LENGTH) {
groupIds.push(Bytes.toBase64(groupId));
} else {
log.error('handleBlocked: Received invalid groupId value');
}
});
log.info(
'handleBlocked: Blocking these groups - v2:',
groupIds.map(groupId => `groupv2(${groupId})`),
'v1:',
groupV1Ids.map(groupId => `group(${groupId})`)
);
await this.storage.put('blocked-groups', [...groupIds, ...groupV1Ids]);
}
this.removeFromCache(envelope);
}