always share our profileKey on outgoing messages

This commit is contained in:
Audric Ackermann 2021-02-26 11:48:08 +11:00
parent 01085244bd
commit fc24df00fb
No known key found for this signature in database
GPG key ID: 999F434D76324AD4
9 changed files with 39 additions and 80 deletions

View file

@ -512,7 +512,6 @@ describe('Backup', () => {
},
profileKey: 'BASE64KEY',
profileName: 'Someone! 🤔',
profileSharing: true,
timestamp: 1524185933350,
type: 'private',
unreadCount: 0,

View file

@ -1,6 +1,5 @@
import classNames from 'classnames';
import React from 'react';
import { SignUpMode, SignUpTab } from './SignUpTab';
export enum TabType {
SignUp,

View file

@ -35,12 +35,6 @@ import {
fromBase64ToArrayBuffer,
} from '../session/utils/String';
export interface OurLokiProfile {
displayName: string;
avatarPointer: string;
profileKey: Uint8Array | null;
}
export interface ConversationAttributes {
profileName?: string;
id: string;
@ -48,7 +42,6 @@ export interface ConversationAttributes {
members: Array<string>;
left: boolean;
expireTimer: number;
profileSharing: boolean;
mentionedUs: boolean;
unreadCount: number;
lastMessageStatus: string | null;
@ -83,7 +76,6 @@ export interface ConversationAttributesOptionals {
members?: Array<string>;
left?: boolean;
expireTimer?: number;
profileSharing?: boolean;
mentionedUs?: boolean;
unreadCount?: number;
lastMessageStatus?: string | null;
@ -122,7 +114,6 @@ export const fillConvoAttributesWithDefaults = (
return _.defaults(optAttributes, {
members: [],
left: false,
profileSharing: false,
unreadCount: 0,
lastMessageStatus: null,
lastJoinedTimestamp: new Date('1970-01-01Z00:00:00:000').getTime(),
@ -179,11 +170,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
this.updateAvatarOnPublicChat(avatar)
);
// Always share profile pics with public chats
if (this.isPublic()) {
this.set('profileSharing', true);
}
this.typingRefreshTimer = null;
this.typingPauseTimer = null;
@ -687,7 +673,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
expireTimer,
preview: uploads.preview,
quote: uploads.quote,
lokiProfile: this.getOurProfile(),
lokiProfile: UserUtils.getOurProfile(true),
};
const destinationPubkey = new PubKey(destination);
@ -834,9 +820,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
if (!this.isPublic()) {
return;
}
if (!this.get('profileSharing')) {
return;
}
// Always share avatars on PublicChat
if (profileKey && typeof profileKey !== 'string') {
// eslint-disable-next-line no-param-reassign
@ -953,16 +937,10 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
return message;
}
let profileKey;
if (this.get('profileSharing')) {
profileKey = window.storage.get('profileKey');
}
const expireUpdate = {
identifier: message.id,
timestamp,
expireTimer,
profileKey,
};
if (!expireUpdate.expireTimer) {
@ -1565,33 +1543,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
return null;
}
/**
* Returns
* displayName: string;
* avatarPointer: string;
* profileKey: Uint8Array;
*/
public 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 (this.get('profileSharing')) {
profileKey = new Uint8Array(window.storage.get('profileKey'));
}
const avatarPointer = ourConversation.get('avatarPointer');
const { displayName } = ourConversation.getLokiProfile();
return { displayName, avatarPointer, profileKey };
} catch (e) {
window.log.error(`Failed to get our profile: ${e}`);
return undefined;
}
}
public getNumber() {
if (!this.isPrivate()) {
return '';

View file

@ -878,10 +878,6 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
}
const { body, attachments, preview, quote } = await this.uploadData();
const ourNumber = UserUtils.getOurPubKeyStrFromCache();
const ourConversation = ConversationController.getInstance().get(
ourNumber
);
const chatParams = {
identifier: this.id,
@ -891,8 +887,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
attachments,
preview,
quote,
lokiProfile:
(ourConversation && ourConversation.getOurProfile()) || undefined,
lokiProfile: UserUtils.getOurProfile(true),
};
if (!chatParams.lokiProfile) {
delete chatParams.lokiProfile;

View file

@ -400,15 +400,7 @@ async function handleProfileUpdate(
const profileKey = StringUtils.decode(profileKeyBuffer, 'base64');
if (!isIncoming) {
const receiver = await ConversationController.getInstance().getOrCreateAndWait(
convoId,
convoType
);
// First set profileSharing = true for the conversation we sent to
receiver.set({ profileSharing: true });
await receiver.commit();
// Then we update our own profileKey if it's different from what we have
// We update our own profileKey if it's different from what we have
const ourNumber = UserUtils.getOurPubKeyStrFromCache();
const me = await ConversationController.getInstance().getOrCreate(
ourNumber,

View file

@ -254,12 +254,8 @@ async function processProfileKey(
sendingDeviceConversation: ConversationModel,
profileKeyBuffer: Uint8Array
) {
const ourNumber = UserUtils.getOurPubKeyStrFromCache();
const profileKey = StringUtils.decode(profileKeyBuffer, 'base64');
if (source === ourNumber) {
conversation.set({ profileSharing: true });
} else if (conversation.isPrivate()) {
if (conversation.isPrivate()) {
await conversation.setProfileKey(profileKey);
} else {
await sendingDeviceConversation.setProfileKey(profileKey);

View file

@ -8,18 +8,15 @@ import { Constants } from '../../../..';
interface ExpirationTimerUpdateMessageParams extends MessageParams {
groupId?: string | PubKey;
expireTimer: number | null;
profileKey?: Uint8Array;
}
export class ExpirationTimerUpdateMessage extends DataMessage {
public readonly groupId?: PubKey;
public readonly expireTimer: number | null;
public readonly profileKey?: Uint8Array;
constructor(params: ExpirationTimerUpdateMessageParams) {
super({ timestamp: params.timestamp, identifier: params.identifier });
this.expireTimer = params.expireTimer;
this.profileKey = params.profileKey;
const { groupId } = params;
this.groupId = groupId ? PubKey.cast(groupId) : undefined;
@ -52,9 +49,6 @@ export class ExpirationTimerUpdateMessage extends DataMessage {
if (this.expireTimer) {
data.expireTimer = this.expireTimer;
}
if (this.profileKey && this.profileKey.length) {
data.profileKey = this.profileKey;
}
return data;
}

View file

@ -4,6 +4,7 @@ import { getItemById } from '../../../ts/data/data';
import { KeyPair } from '../../../libtextsecure/libsignal-protocol';
import { PubKey } from '../types';
import { toHex } from './String';
import { ConversationController } from '../conversations';
export type HexKeyPair = {
pubKey: string;
@ -77,3 +78,36 @@ export function isRestoringFromSeed(): boolean {
export function setRestoringFromSeed(isRestoring: boolean) {
window.textsecure.storage.user.setRestoringFromSeed(isRestoring);
}
export interface OurLokiProfile {
displayName: string;
avatarPointer: string;
profileKey: Uint8Array | null;
}
/**
* Returns
* displayName: string;
* avatarPointer: string;
* profileKey: Uint8Array;
*/
export function getOurProfile(
shareAvatar: boolean
): 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 avatarPointer = ourConversation.get('avatarPointer');
const { displayName } = ourConversation.getLokiProfile();
return { displayName, avatarPointer, profileKey };
} catch (e) {
window.log.error(`Failed to get our profile: ${e}`);
return undefined;
}
}

View file

@ -76,7 +76,6 @@ export class MockConversation {
members,
left: false,
expireTimer: 0,
profileSharing: true,
mentionedUs: false,
unreadCount: 5,
isKickedFromGroup: false,