Erase storage service state on key change
This commit is contained in:
parent
4de30786ec
commit
bbe56e0811
3 changed files with 23 additions and 5 deletions
|
@ -3539,9 +3539,21 @@ export async function startApp(): Promise<void> {
|
|||
}
|
||||
|
||||
if (storageServiceKey) {
|
||||
log.info('onKeysSync: received keys');
|
||||
const storageServiceKeyBase64 = Bytes.toBase64(storageServiceKey);
|
||||
window.storage.put('storageKey', storageServiceKeyBase64);
|
||||
if (window.storage.get('storageKey') === storageServiceKeyBase64) {
|
||||
log.info(
|
||||
"onKeysSync: storage service key didn't change, " +
|
||||
'fetching manifest anyway'
|
||||
);
|
||||
} else {
|
||||
log.info(
|
||||
'onKeysSync: updated storage service key, erasing state and fetching'
|
||||
);
|
||||
await window.storage.put('storageKey', storageServiceKeyBase64);
|
||||
await window.Signal.Services.eraseAllStorageServiceState({
|
||||
keepUnknownFields: true,
|
||||
});
|
||||
}
|
||||
|
||||
await window.Signal.Services.runStorageServiceSyncJob();
|
||||
}
|
||||
|
|
|
@ -1195,11 +1195,15 @@ export function enableStorageService(): void {
|
|||
|
||||
// Note: this function is meant to be called before ConversationController is hydrated.
|
||||
// It goes directly to the database, so in-memory conversations will be out of date.
|
||||
export async function eraseAllStorageServiceState(): Promise<void> {
|
||||
export async function eraseAllStorageServiceState({
|
||||
keepUnknownFields = false,
|
||||
}: { keepUnknownFields?: boolean } = {}): Promise<void> {
|
||||
log.info('storageService.eraseAllStorageServiceState: starting...');
|
||||
await Promise.all([
|
||||
window.storage.remove('manifestVersion'),
|
||||
window.storage.remove('storage-service-unknown-records'),
|
||||
keepUnknownFields
|
||||
? Promise.resolve()
|
||||
: window.storage.remove('storage-service-unknown-records'),
|
||||
window.storage.remove('storageCredentials'),
|
||||
]);
|
||||
await eraseStorageServiceStateFromConversations();
|
||||
|
|
4
ts/window.d.ts
vendored
4
ts/window.d.ts
vendored
|
@ -285,7 +285,9 @@ declare global {
|
|||
Services: {
|
||||
calling: CallingClass;
|
||||
enableStorageService: () => boolean;
|
||||
eraseAllStorageServiceState: () => Promise<void>;
|
||||
eraseAllStorageServiceState: (options?: {
|
||||
keepUnknownFields?: boolean;
|
||||
}) => Promise<void>;
|
||||
initializeGroupCredentialFetcher: () => void;
|
||||
initializeNetworkObserver: (network: ReduxActions['network']) => void;
|
||||
initializeUpdateListener: (updates: ReduxActions['updates']) => void;
|
||||
|
|
Loading…
Reference in a new issue