update avatar on convo only if DL+decrypt is OK

pull/1508/head
Audric Ackermann 4 years ago
parent 720922cc71
commit a34720501c

@ -34,9 +34,6 @@ export async function updateProfile(
!prevPointer || !_.isEqual(prevPointer, profile.profilePicture); !prevPointer || !_.isEqual(prevPointer, profile.profilePicture);
if (needsUpdate) { if (needsUpdate) {
conversation.set('avatarPointer', profile.profilePicture);
conversation.set('profileKey', profileKey);
const downloaded = await downloadAttachment({ const downloaded = await downloadAttachment({
url: profile.profilePicture, url: profile.profilePicture,
isRaw: true, isRaw: true,
@ -60,6 +57,9 @@ export async function updateProfile(
...downloaded, ...downloaded,
data: decryptedData, 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); ({ path } = upgraded);
} catch (e) { } catch (e) {
window.log.error(`Could not decrypt profile image: ${e}`); window.log.error(`Could not decrypt profile image: ${e}`);

@ -72,9 +72,16 @@ export class ChatMessage extends DataMessage {
this.quote = params.quote; this.quote = params.quote;
this.expireTimer = params.expireTimer; this.expireTimer = params.expireTimer;
if (params.lokiProfile && params.lokiProfile.profileKey) { if (params.lokiProfile && params.lokiProfile.profileKey) {
this.profileKey = new Uint8Array( if (
ByteBuffer.wrap(params.lokiProfile.profileKey).toArrayBuffer() 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; this.displayName = params.lokiProfile && params.lokiProfile.displayName;
@ -88,8 +95,11 @@ export class ChatMessage extends DataMessage {
syncTarget: string, syncTarget: string,
sentTimestamp: number sentTimestamp: number
) { ) {
// the dataMessage.profileKey is of type ByteBuffer. We need to make it a Uint8Array
const lokiProfile: any = { const lokiProfile: any = {
profileKey: dataMessage.profileKey, profileKey: new Uint8Array(
(dataMessage.profileKey as any).toArrayBuffer()
),
}; };
if ((dataMessage as any)?.$type?.name !== 'DataMessage') { if ((dataMessage as any)?.$type?.name !== 'DataMessage') {

Loading…
Cancel
Save