From 850e7595797fc38e53134230ecc9e43135cbb944 Mon Sep 17 00:00:00 2001 From: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com> Date: Thu, 18 Mar 2021 19:25:19 -0500 Subject: [PATCH] Keeping profile data around longer in the face of errors --- ts/background.ts | 2 - ts/model-types.d.ts | 1 - ts/models/conversations.ts | 78 +++++++++++++++----------------------- 3 files changed, 31 insertions(+), 50 deletions(-) diff --git a/ts/background.ts b/ts/background.ts index b7bbf8f787..35b3de2a48 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -2356,8 +2356,6 @@ export async function startApp(): Promise { details.profileKey ); conversation.setProfileKey(profileKey); - } else { - conversation.dropProfileKey(); } if (typeof details.blocked !== 'undefined') { diff --git a/ts/model-types.d.ts b/ts/model-types.d.ts index b34ec5f457..41a9d4bba9 100644 --- a/ts/model-types.d.ts +++ b/ts/model-types.d.ts @@ -207,7 +207,6 @@ export type ConversationAttributesType = { profileFamilyName?: string; profileKey?: string; profileName?: string; - storageProfileKey?: string; verified?: number; profileLastFetchedAt?: number; diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index 851bae22ea..d78359be03 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -4450,6 +4450,8 @@ export class ConversationModel extends window.Backbone.Model< ); c.set('about', stringFromBytes(trimForDisplay(decrypted))); } + } else { + c.unset('about'); } if (profile.aboutEmoji) { @@ -4462,11 +4464,16 @@ export class ConversationModel extends window.Backbone.Model< ); c.set('aboutEmoji', stringFromBytes(trimForDisplay(decrypted))); } + } else { + c.unset('aboutEmoji'); } if (profile.capabilities) { c.set({ capabilities: profile.capabilities }); + } else { + c.unset('capabilities'); } + if (profileCredentialRequestContext && profile.credential) { const profileKeyCredential = handleProfileKeyCredential( clientZkProfileCipher, @@ -4474,18 +4481,28 @@ export class ConversationModel extends window.Backbone.Model< profile.credential ); c.set({ profileKeyCredential }); + } else { + c.unset('profileKeyCredential'); } } catch (error) { - if (error.code !== 403 && error.code !== 404) { - window.log.warn( - 'getProfile failure:', - c.idForLogging(), - error && error.stack ? error.stack : error - ); - } else { - await c.dropProfileKey(); + switch (error?.code) { + case 403: + throw error; + case 404: + window.log.warn( + `getProfile failure: failed to find a profile for ${c.idForLogging()}`, + error && error.stack ? error.stack : error + ); + c.setUnregistered(); + return; + default: + window.log.warn( + 'getProfile failure:', + c.idForLogging(), + error && error.stack ? error.stack : error + ); + return; } - return; } try { @@ -4496,7 +4513,10 @@ export class ConversationModel extends window.Backbone.Model< c.idForLogging(), error && error.stack ? error.stack : error ); - await c.dropProfileKey(); + await c.set({ + profileName: undefined, + profileFamilyName: undefined, + }); } try { @@ -4621,10 +4641,7 @@ export class ConversationModel extends window.Backbone.Model< sealedSender: SEALED_SENDER.UNKNOWN, }); - if ( - !viaStorageServiceSync && - profileKey !== this.get('storageProfileKey') - ) { + if (!viaStorageServiceSync) { this.captureChange('profileKey'); } @@ -4637,39 +4654,6 @@ export class ConversationModel extends window.Backbone.Model< Conversation: window.Whisper.Conversation, }); } - - if (viaStorageServiceSync) { - this.set({ - storageProfileKey: profileKey, - }); - } - } - - async dropProfileKey(): Promise { - if (this.get('profileKey')) { - window.log.info( - `Dropping profileKey, setting sealedSender to UNKNOWN for conversation ${this.idForLogging()}` - ); - const profileAvatar = this.get('profileAvatar'); - if (profileAvatar && profileAvatar.path) { - await deleteAttachmentData(profileAvatar.path); - } - - this.set({ - about: undefined, - aboutEmoji: undefined, - profileKey: undefined, - profileKeyVersion: undefined, - profileKeyCredential: null, - accessKey: null, - profileName: undefined, - profileFamilyName: undefined, - profileAvatar: null, - sealedSender: SEALED_SENDER.UNKNOWN, - }); - - window.Signal.Data.updateConversation(this.attributes); - } } async deriveAccessKeyIfNeeded(): Promise {