From a34720501c640ea417f066e0b9e98c8786aa7ebe Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 16 Feb 2021 14:22:22 +1100 Subject: [PATCH] update avatar on convo only if DL+decrypt is OK --- ts/receiver/dataMessage.ts | 6 +++--- .../outgoing/content/data/ChatMessage.ts | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index 153b63560..e6b64d5b3 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -34,9 +34,6 @@ export async function updateProfile( !prevPointer || !_.isEqual(prevPointer, profile.profilePicture); if (needsUpdate) { - conversation.set('avatarPointer', profile.profilePicture); - conversation.set('profileKey', profileKey); - const downloaded = await downloadAttachment({ url: profile.profilePicture, isRaw: true, @@ -60,6 +57,9 @@ export async function updateProfile( ...downloaded, data: decryptedData, }); + // Only update the convo if the download and decrypt is a success + conversation.set('avatarPointer', profile.profilePicture); + conversation.set('profileKey', profileKey); ({ path } = upgraded); } catch (e) { window.log.error(`Could not decrypt profile image: ${e}`); diff --git a/ts/session/messages/outgoing/content/data/ChatMessage.ts b/ts/session/messages/outgoing/content/data/ChatMessage.ts index 147f65dff..2a661c2ed 100644 --- a/ts/session/messages/outgoing/content/data/ChatMessage.ts +++ b/ts/session/messages/outgoing/content/data/ChatMessage.ts @@ -72,9 +72,16 @@ export class ChatMessage extends DataMessage { this.quote = params.quote; this.expireTimer = params.expireTimer; if (params.lokiProfile && params.lokiProfile.profileKey) { - this.profileKey = new Uint8Array( - ByteBuffer.wrap(params.lokiProfile.profileKey).toArrayBuffer() - ); + if ( + params.lokiProfile.profileKey instanceof Uint8Array || + (params.lokiProfile.profileKey as any) instanceof ByteBuffer + ) { + this.profileKey = new Uint8Array(params.lokiProfile.profileKey); + } else { + this.profileKey = new Uint8Array( + ByteBuffer.wrap(params.lokiProfile.profileKey).toArrayBuffer() + ); + } } this.displayName = params.lokiProfile && params.lokiProfile.displayName; @@ -88,8 +95,11 @@ export class ChatMessage extends DataMessage { syncTarget: string, sentTimestamp: number ) { + // the dataMessage.profileKey is of type ByteBuffer. We need to make it a Uint8Array const lokiProfile: any = { - profileKey: dataMessage.profileKey, + profileKey: new Uint8Array( + (dataMessage.profileKey as any).toArrayBuffer() + ), }; if ((dataMessage as any)?.$type?.name !== 'DataMessage') {