From 506a0b2927a0691938712f5d287edb1fce1d928a Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 29 Jul 2021 13:42:36 +1000 Subject: [PATCH] fix profileKey share in config message for base64 profileKey --- ts/session/utils/syncUtils.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ts/session/utils/syncUtils.ts b/ts/session/utils/syncUtils.ts index 9947140ca..c2fb62956 100644 --- a/ts/session/utils/syncUtils.ts +++ b/ts/session/utils/syncUtils.ts @@ -27,6 +27,7 @@ import { ExpirationTimerUpdateMessage } from '../messages/outgoing/controlMessag import { getV2OpenGroupRoom } from '../../data/opengroups'; import { getCompleteUrlFromRoom } from '../../opengroup/utils/OpenGroupUtils'; import { DURATION } from '../constants'; +import { PubKey } from '../types'; const ITEM_ID_LAST_SYNC_TIMESTAMP = 'lastSyncedTimestamp'; @@ -161,12 +162,19 @@ const getValidContacts = (convos: Array) => { const contacts = contactsModels.map(c => { try { const profileKey = c.get('profileKey'); - let profileKeyForContact; + let profileKeyForContact = null; if (typeof profileKey === 'string') { // this will throw if the profileKey is not in hex. try { + // for some reason, at some point, the saved profileKey is a string in base64 format + // this hack is here to update existing conversations with a non-hex profileKey to a hex format and save them + + if (!/^[0-9a-fA-F]+$/.test(profileKey)) { + throw new Error('Not Hex'); + } profileKeyForContact = fromHexToArray(profileKey); } catch (e) { + // if not hex, try to decode it as base64 profileKeyForContact = fromBase64ToArray(profileKey); // if the line above does not fail, update the stored profileKey for this convo void c.setProfileKey(profileKeyForContact); @@ -183,7 +191,7 @@ const getValidContacts = (convos: Array) => { publicKey: c.id, displayName: c.getLokiProfile()?.displayName, profilePictureURL: c.get('avatarPointer'), - profileKey: profileKeyForContact, + profileKey: !profileKeyForContact?.length ? undefined : profileKeyForContact, }); } catch (e) { window?.log.warn('getValidContacts', e);