diff --git a/package.json b/package.json index 87f41bf3e73..230b20c7a5c 100644 --- a/package.json +++ b/package.json @@ -189,7 +189,7 @@ "@electron/fuses": "1.5.0", "@formatjs/intl": "2.6.7", "@mixer/parallel-prettier": "2.0.3", - "@signalapp/mock-server": "2.20.0", + "@signalapp/mock-server": "2.21.1", "@storybook/addon-a11y": "6.5.6", "@storybook/addon-actions": "6.5.6", "@storybook/addon-controls": "6.5.6", diff --git a/ts/ConversationController.ts b/ts/ConversationController.ts index ebc7239c1bd..eba52d0dede 100644 --- a/ts/ConversationController.ts +++ b/ts/ConversationController.ts @@ -30,6 +30,7 @@ import { MINUTE, SECOND } from './util/durations'; import { getUuidsForE164s } from './util/getUuidsForE164s'; import { SIGNAL_ACI, SIGNAL_AVATAR_PATH } from './types/SignalConversation'; import { getTitleNoDefault } from './util/getTitle'; +import * as StorageService from './services/storage'; type ConvoMatchType = | { @@ -1088,6 +1089,20 @@ export class ConversationController { log.warn(`${logId}: Delete the obsolete conversation from the database`); await removeConversation(obsoleteId); + const obsoleteStorageID = obsolete.get('storageID'); + + if (obsoleteStorageID) { + log.warn( + `${logId}: Obsolete conversation was in storage service, scheduling removal` + ); + + const obsoleteStorageVersion = obsolete.get('storageVersion'); + StorageService.addPendingDelete({ + storageID: obsoleteStorageID, + storageVersion: obsoleteStorageVersion, + }); + } + log.warn(`${logId}: Update cached messages in MessageController`); window.MessageController.update((message: MessageModel) => { if (message.get('conversationId') === obsoleteId) { diff --git a/ts/services/storage.ts b/ts/services/storage.ts index 5dc0ec293a3..6ac78a97398 100644 --- a/ts/services/storage.ts +++ b/ts/services/storage.ts @@ -1999,3 +1999,16 @@ export const runStorageServiceSyncJob = debounce(() => { }, `sync v${window.storage.get('manifestVersion')}`) ); }, 500); + +export const addPendingDelete = (item: ExtendedStorageID): void => { + void storageJobQueue(async () => { + const storedPendingDeletes = window.storage.get( + 'storage-service-pending-deletes', + [] + ); + await window.storage.put('storage-service-pending-deletes', [ + ...storedPendingDeletes, + item, + ]); + }, `addPendingDelete(${redactExtendedStorageID(item)})`); +}; diff --git a/ts/test-mock/pnp/pni_signature_test.ts b/ts/test-mock/pnp/pni_signature_test.ts index 1e4d461d117..7f01c50adba 100644 --- a/ts/test-mock/pnp/pni_signature_test.ts +++ b/ts/test-mock/pnp/pni_signature_test.ts @@ -358,6 +358,8 @@ describe('pnp/PNI Signature', function needsName() { // No notifications const notifications = window.locator('.SystemMessage'); assert.strictEqual(await notifications.count(), 0, 'notifications'); + + assert.isEmpty(await phone.getOrphanedStorageKeys()); } }); }); diff --git a/yarn.lock b/yarn.lock index bd96fc8a6b8..047ec2a7836 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2280,10 +2280,10 @@ node-gyp-build "^4.2.3" uuid "^8.3.0" -"@signalapp/mock-server@2.20.0": - version "2.20.0" - resolved "https://registry.yarnpkg.com/@signalapp/mock-server/-/mock-server-2.20.0.tgz#073e0ef1a4c077d638440003a66be05feafb8bd3" - integrity sha512-RdwGZOlZLdsNfM3uzpaU/RkpCAhswF74NC96F7Sw1yOE05Ig/4Cpdx9M9gU6XE6ZWLhjPJ/Kll1GaKK+WPSwBw== +"@signalapp/mock-server@2.21.1": + version "2.21.1" + resolved "https://registry.yarnpkg.com/@signalapp/mock-server/-/mock-server-2.21.1.tgz#31ac756a8db0509cf6065b7c6b8139c7dc54c24d" + integrity sha512-pycdxIyv8/vPJSl5GZkTTbeFHVq3keefpfuqhVN6ZnP7UfKc0EJ5n3STcTN1V6AdNkdntK82pt47836ln9Wmrg== dependencies: "@signalapp/libsignal-client" "^0.24.0" debug "^4.3.2"