always share profileKey if it is set

This commit is contained in:
Audric Ackermann 2021-02-26 16:07:13 +11:00
parent 619a894b52
commit b6ff4dc186
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4
3 changed files with 10 additions and 16 deletions

View File

@ -673,7 +673,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
expireTimer,
preview: uploads.preview,
quote: uploads.quote,
lokiProfile: UserUtils.getOurProfile(true),
lokiProfile: UserUtils.getOurProfile(),
};
const destinationPubkey = new PubKey(destination);

View File

@ -887,7 +887,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
attachments,
preview,
quote,
lokiProfile: UserUtils.getOurProfile(true),
lokiProfile: UserUtils.getOurProfile(),
};
if (!chatParams.lokiProfile) {
delete chatParams.lokiProfile;

View File

@ -85,27 +85,21 @@ export interface OurLokiProfile {
profileKey: Uint8Array | null;
}
/**
* Returns
* displayName: string;
* avatarPointer: string;
* profileKey: Uint8Array;
*/
export function getOurProfile(
shareAvatar: boolean
): OurLokiProfile | undefined {
export function getOurProfile(): OurLokiProfile | undefined {
try {
// Secondary devices have their profile stored
// in their primary device's conversation
const ourNumber = window.storage.get('primaryDevicePubKey');
const ourConversation = ConversationController.getInstance().get(ourNumber);
let profileKey = null;
if (shareAvatar) {
profileKey = new Uint8Array(window.storage.get('profileKey'));
}
const profileKey = new Uint8Array(window.storage.get('profileKey'));
const avatarPointer = ourConversation.get('avatarPointer');
const { displayName } = ourConversation.getLokiProfile();
return { displayName, avatarPointer, profileKey };
return {
displayName,
avatarPointer,
profileKey: profileKey.length ? profileKey : null,
};
} catch (e) {
window.log.error(`Failed to get our profile: ${e}`);
return undefined;