From adcf2212e5fcd46d0d688b3ca86ea26d61104244 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 10 Oct 2024 09:20:57 +1000 Subject: [PATCH] Ensure that non-ACIs are excluded from the blocked UUIDs list --- ts/background.ts | 13 +++++++++++++ ts/models/conversations.ts | 8 ++++++-- ts/textsecure/storage/Blocked.ts | 6 +++--- ts/util/isBlocked.ts | 3 ++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/ts/background.ts b/ts/background.ts index 7b36cc129b68..a46bc69620e4 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -197,6 +197,7 @@ import { DataReader, DataWriter } from './sql/Client'; import { restoreRemoteConfigFromStorage } from './RemoteConfig'; import { getParametersForRedux, loadAll } from './services/allLoaders'; import { checkFirstEnvelope } from './util/checkFirstEnvelope'; +import { BLOCKED_UUIDS_ID } from './textsecure/storage/Blocked'; export function isOverHourIntoPast(timestamp: number): boolean { return isNumber(timestamp) && isOlderThan(timestamp, HOUR); @@ -1360,6 +1361,18 @@ export async function startApp(): Promise { initializeExpiringMessageService(singleProtoJobQueue); + log.info('Blocked uuids cleanup: starting...'); + const blockedUuids = window.storage.get(BLOCKED_UUIDS_ID, []); + const blockedAcis = blockedUuids.filter(isAciString); + const diff = blockedUuids.length - blockedAcis.length; + if (diff > 0) { + log.warn( + `Blocked uuids cleanup: Found ${diff} non-ACIs in blocked list. Removing.` + ); + await window.storage.put(BLOCKED_UUIDS_ID, blockedAcis); + } + log.info('Blocked uuids cleanup: complete'); + log.info('Expiration start timestamp cleanup: starting...'); const messagesUnexpectedlyMissingExpirationStartTimestamp = await DataReader.getMessagesUnexpectedlyMissingExpirationStartTimestamp(); diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index 2bde5b38d517..02f2a8a34b0b 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -930,7 +930,7 @@ export class ConversationModel extends window.Backbone const wasBlocked = this.isBlocked(); const serviceId = this.getServiceId(); - if (serviceId) { + if (serviceId && isAciString(serviceId)) { drop(window.storage.blocked.addBlockedServiceId(serviceId)); blocked = true; } @@ -962,7 +962,7 @@ export class ConversationModel extends window.Backbone const wasBlocked = this.isBlocked(); const serviceId = this.getServiceId(); - if (serviceId) { + if (serviceId && isAciString(serviceId)) { drop(window.storage.blocked.removeBlockedServiceId(serviceId)); unblocked = true; } @@ -2344,6 +2344,10 @@ export class ConversationModel extends window.Backbone ourAci: window.textsecure.storage.user.getCheckedAci(), forceSave: true, }); + if (!this.get('active_at')) { + this.set({ active_at: Date.now() }); + await DataWriter.updateConversation(this.attributes); + } window.MessageCache.toMessageAttributes(message); this.trigger('newmessage', message); drop(this.updateLastMessage()); diff --git a/ts/textsecure/storage/Blocked.ts b/ts/textsecure/storage/Blocked.ts index 181c5246ba95..e46d9d5f075c 100644 --- a/ts/textsecure/storage/Blocked.ts +++ b/ts/textsecure/storage/Blocked.ts @@ -7,9 +7,9 @@ import type { StorageInterface } from '../../types/Storage.d'; import type { ServiceIdString } from '../../types/ServiceId'; import * as log from '../../logging/log'; -const BLOCKED_NUMBERS_ID = 'blocked'; -const BLOCKED_UUIDS_ID = 'blocked-uuids'; -const BLOCKED_GROUPS_ID = 'blocked-groups'; +export const BLOCKED_NUMBERS_ID = 'blocked'; +export const BLOCKED_UUIDS_ID = 'blocked-uuids'; +export const BLOCKED_GROUPS_ID = 'blocked-groups'; export class Blocked { constructor(private readonly storage: StorageInterface) {} diff --git a/ts/util/isBlocked.ts b/ts/util/isBlocked.ts index 35ddb5cef15a..27f67e336fed 100644 --- a/ts/util/isBlocked.ts +++ b/ts/util/isBlocked.ts @@ -2,12 +2,13 @@ // SPDX-License-Identifier: AGPL-3.0-only import type { ConversationAttributesType } from '../model-types'; +import { isAciString } from './isAciString'; export function isBlocked( attributes: Pick ): boolean { const { e164, groupId, serviceId } = attributes; - if (serviceId) { + if (isAciString(serviceId)) { return window.storage.blocked.isServiceIdBlocked(serviceId); }