fix a bug of attachment not loading in one to one chats

This commit is contained in:
audric 2021-07-27 16:41:46 +10:00
parent fce86989f0
commit 316f37ae3d
5 changed files with 18 additions and 7 deletions

View file

@ -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');

View file

@ -210,7 +210,6 @@ const AvatarItem = (props: {
};
const ConversationListItem = (props: Props) => {
// console.warn('ConversationListItem', props.id.substr(-1), ': ', props);
const {
activeAt,
unreadCount,

View file

@ -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 : '';

View file

@ -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 };
};

View file

@ -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<ConversationModel>) => {
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({