Properly handle groupIds in incoming block sync
This commit is contained in:
parent
a802188f33
commit
f1586578ff
3 changed files with 58 additions and 15 deletions
|
@ -2507,6 +2507,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,
|
||||
|
|
|
@ -879,7 +879,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) {
|
||||
|
@ -899,14 +899,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) {
|
||||
|
@ -926,8 +931,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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue