|
|
|
@ -20,11 +20,12 @@ import {
|
|
|
|
|
} from '../../ts/data/data';
|
|
|
|
|
import { ConversationModel, ConversationTypeEnum } from '../models/conversation';
|
|
|
|
|
import { allowOnlyOneAtATime } from '../session/utils/Promise';
|
|
|
|
|
import { toHex } from '../session/utils/String';
|
|
|
|
|
|
|
|
|
|
export async function updateProfileOneAtATime(
|
|
|
|
|
conversation: ConversationModel,
|
|
|
|
|
profile: SignalService.DataMessage.ILokiProfile,
|
|
|
|
|
profileKey: any
|
|
|
|
|
profileKey?: Uint8Array | null // was any
|
|
|
|
|
) {
|
|
|
|
|
if (!conversation?.id) {
|
|
|
|
|
window?.log?.warn('Cannot update profile with empty convoid');
|
|
|
|
@ -39,13 +40,18 @@ export async function updateProfileOneAtATime(
|
|
|
|
|
async function updateProfile(
|
|
|
|
|
conversation: ConversationModel,
|
|
|
|
|
profile: SignalService.DataMessage.ILokiProfile,
|
|
|
|
|
profileKey: any
|
|
|
|
|
profileKey?: Uint8Array | null // was any
|
|
|
|
|
) {
|
|
|
|
|
const { dcodeIO, textsecure, Signal } = window;
|
|
|
|
|
|
|
|
|
|
// Retain old values unless changed:
|
|
|
|
|
const newProfile = conversation.get('profile') || {};
|
|
|
|
|
|
|
|
|
|
if (!profileKey) {
|
|
|
|
|
window.log.warn("No need to try to update profile. We don't have a profile key");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newProfile.displayName = profile.displayName;
|
|
|
|
|
|
|
|
|
|
if (profile.profilePicture) {
|
|
|
|
@ -79,7 +85,7 @@ async function updateProfile(
|
|
|
|
|
});
|
|
|
|
|
// Only update the convo if the download and decrypt is a success
|
|
|
|
|
conversation.set('avatarPointer', profile.profilePicture);
|
|
|
|
|
conversation.set('profileKey', profileKey);
|
|
|
|
|
conversation.set('profileKey', toHex(profileKey));
|
|
|
|
|
({ path } = upgraded);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
window?.log?.error(`Could not decrypt profile image: ${e}`);
|
|
|
|
@ -422,18 +428,15 @@ export const isDuplicate = (
|
|
|
|
|
async function handleProfileUpdate(
|
|
|
|
|
profileKeyBuffer: Uint8Array,
|
|
|
|
|
convoId: string,
|
|
|
|
|
convoType: ConversationTypeEnum,
|
|
|
|
|
isIncoming: boolean
|
|
|
|
|
) {
|
|
|
|
|
const profileKey = StringUtils.decode(profileKeyBuffer, 'base64');
|
|
|
|
|
|
|
|
|
|
if (!isIncoming) {
|
|
|
|
|
// We update our own profileKey if it's different from what we have
|
|
|
|
|
const ourNumber = UserUtils.getOurPubKeyStrFromCache();
|
|
|
|
|
const me = getConversationController().getOrCreate(ourNumber, ConversationTypeEnum.PRIVATE);
|
|
|
|
|
|
|
|
|
|
// Will do the save for us if needed
|
|
|
|
|
await me.setProfileKey(profileKey);
|
|
|
|
|
await me.setProfileKey(profileKeyBuffer);
|
|
|
|
|
} else {
|
|
|
|
|
const sender = await getConversationController().getOrCreateAndWait(
|
|
|
|
|
convoId,
|
|
|
|
@ -441,7 +444,7 @@ async function handleProfileUpdate(
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Will do the save for us
|
|
|
|
|
await sender.setProfileKey(profileKey);
|
|
|
|
|
await sender.setProfileKey(profileKeyBuffer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -582,7 +585,7 @@ export async function handleMessageEvent(event: MessageEvent): Promise<void> {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (message.profileKey?.length) {
|
|
|
|
|
await handleProfileUpdate(message.profileKey, conversationId, type, isIncoming);
|
|
|
|
|
await handleProfileUpdate(message.profileKey, conversationId, isIncoming);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const msg = createMessage(data, isIncoming);
|
|
|
|
|