From 316f37ae3d024e016e8ce5f1e8eafef15fe7adc5 Mon Sep 17 00:00:00 2001 From: audric Date: Tue, 27 Jul 2021 16:41:46 +1000 Subject: [PATCH] fix a bug of attachment not loading in one to one chats --- js/modules/types/conversation.js | 2 +- ts/components/ConversationListItem.tsx | 1 - ts/components/conversation/Image.tsx | 1 + ts/hooks/useEncryptedFileFetch.ts | 3 ++- ts/session/utils/syncUtils.ts | 18 ++++++++++++++---- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/js/modules/types/conversation.js b/js/modules/types/conversation.js index fc66a6e7a..efca69dfd 100644 --- a/js/modules/types/conversation.js +++ b/js/modules/types/conversation.js @@ -1,6 +1,6 @@ /* global crypto */ -const { isFunction, isNumber } = require('lodash'); +const { isFunction } = require('lodash'); const { createLastMessageUpdate } = require('../../../ts/types/Conversation'); const { arrayBufferToBase64 } = require('../crypto'); diff --git a/ts/components/ConversationListItem.tsx b/ts/components/ConversationListItem.tsx index 9c8eff3cb..58938d68c 100644 --- a/ts/components/ConversationListItem.tsx +++ b/ts/components/ConversationListItem.tsx @@ -210,7 +210,6 @@ const AvatarItem = (props: { }; const ConversationListItem = (props: Props) => { - // console.warn('ConversationListItem', props.id.substr(-1), ': ', props); const { activeAt, unreadCount, diff --git a/ts/components/conversation/Image.tsx b/ts/components/conversation/Image.tsx index 1e0a5b087..1dd4f9a0e 100644 --- a/ts/components/conversation/Image.tsx +++ b/ts/components/conversation/Image.tsx @@ -62,6 +62,7 @@ export const Image = (props: Props) => { const role = canClick ? 'button' : undefined; const { loading, urlToLoad } = useEncryptedFileFetch(url, attachment.contentType); + // data will be url if loading is finished and '' if not const srcData = !loading ? urlToLoad : ''; diff --git a/ts/hooks/useEncryptedFileFetch.ts b/ts/hooks/useEncryptedFileFetch.ts index 0b3162980..b6912c742 100644 --- a/ts/hooks/useEncryptedFileFetch.ts +++ b/ts/hooks/useEncryptedFileFetch.ts @@ -19,12 +19,13 @@ export const useEncryptedFileFetch = (url: string, contentType: string) => { } useEffect(() => { + setLoading(true); + mountedRef.current = true; void fetchUrl(); return () => { mountedRef.current = false; }; }, [url]); - return { urlToLoad, loading }; }; diff --git a/ts/session/utils/syncUtils.ts b/ts/session/utils/syncUtils.ts index affe3a963..9947140ca 100644 --- a/ts/session/utils/syncUtils.ts +++ b/ts/session/utils/syncUtils.ts @@ -14,7 +14,7 @@ import { ConfigurationMessageContact, } from '../messages/outgoing/controlMessage/ConfigurationMessage'; import { ConversationModel } from '../../models/conversation'; -import { fromBase64ToArray, fromHexToArray } from './String'; +import { fromBase64ToArray, fromHexToArray, toHex } from './String'; import { SignalService } from '../../protobuf'; import _ from 'lodash'; import { @@ -163,10 +163,20 @@ const getValidContacts = (convos: Array) => { const profileKey = c.get('profileKey'); let profileKeyForContact; if (typeof profileKey === 'string') { - profileKeyForContact = fromHexToArray(profileKey); + // this will throw if the profileKey is not in hex. + try { + profileKeyForContact = fromHexToArray(profileKey); + } catch (e) { + profileKeyForContact = fromBase64ToArray(profileKey); + // if the line above does not fail, update the stored profileKey for this convo + void c.setProfileKey(profileKeyForContact); + } } else if (profileKey) { - console.warn('AUDRIC migration todo'); - debugger; + window.log.warn( + 'Got a profileKey for a contact in another format than string. Contact: ', + c.id + ); + return null; } return new ConfigurationMessageContact({