diff --git a/ts/background.ts b/ts/background.ts index 6daa36f61d..a9f342b16c 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -2507,6 +2507,23 @@ export async function startApp(): Promise { ); 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, diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index 9bbc71fc1d..9d25a63824 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -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; diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index 7aa8a0ddc6..021ae4e674 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -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 { - 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 = []; + const groupIds: Array = []; + + 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); }