Properly handle groupIds in incoming block sync

This commit is contained in:
Scott Nonnenberg 2022-01-19 16:39:27 -08:00 committed by GitHub
parent a802188f33
commit f1586578ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 15 deletions

View file

@ -2507,6 +2507,23 @@ export async function startApp(): Promise<void> {
); );
return; 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({ conversation.notifyTyping({
isTyping: started, isTyping: started,

View file

@ -879,7 +879,7 @@ export class ConversationModel extends window.Backbone
block({ viaStorageServiceSync = false } = {}): void { block({ viaStorageServiceSync = false } = {}): void {
let blocked = false; let blocked = false;
const isBlocked = this.isBlocked(); const wasBlocked = this.isBlocked();
const uuid = this.get('uuid'); const uuid = this.get('uuid');
if (uuid) { if (uuid) {
@ -899,14 +899,19 @@ export class ConversationModel extends window.Backbone
blocked = true; blocked = true;
} }
if (!viaStorageServiceSync && !isBlocked && blocked) { if (blocked && !wasBlocked) {
this.captureChange('block'); // 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 { unblock({ viaStorageServiceSync = false } = {}): boolean {
let unblocked = false; let unblocked = false;
const isBlocked = this.isBlocked(); const wasBlocked = this.isBlocked();
const uuid = this.get('uuid'); const uuid = this.get('uuid');
if (uuid) { if (uuid) {
@ -926,8 +931,13 @@ export class ConversationModel extends window.Backbone
unblocked = true; unblocked = true;
} }
if (!viaStorageServiceSync && isBlocked && unblocked) { if (unblocked && wasBlocked) {
this.captureChange('unblock'); // 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; return unblocked;

View file

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