diff --git a/test/backup_test.js b/test/backup_test.js index f474f4bff..f9a674856 100644 --- a/test/backup_test.js +++ b/test/backup_test.js @@ -512,7 +512,6 @@ describe('Backup', () => { }, profileKey: 'BASE64KEY', profileName: 'Someone! 🤔', - profileSharing: true, timestamp: 1524185933350, type: 'private', unreadCount: 0, diff --git a/ts/components/session/registration/TabLabel.tsx b/ts/components/session/registration/TabLabel.tsx index 49855a0e1..bb2548f43 100644 --- a/ts/components/session/registration/TabLabel.tsx +++ b/ts/components/session/registration/TabLabel.tsx @@ -1,6 +1,5 @@ import classNames from 'classnames'; import React from 'react'; -import { SignUpMode, SignUpTab } from './SignUpTab'; export enum TabType { SignUp, diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index f745d7c53..a5edbd13d 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -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; left: boolean; expireTimer: number; - profileSharing: boolean; mentionedUs: boolean; unreadCount: number; lastMessageStatus: string | null; @@ -83,7 +76,6 @@ export interface ConversationAttributesOptionals { members?: Array; 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 { 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 { 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 { 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 { 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 { 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 ''; diff --git a/ts/models/message.ts b/ts/models/message.ts index eac7138d6..b15679dc5 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -878,10 +878,6 @@ export class MessageModel extends Backbone.Model { } 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 { attachments, preview, quote, - lokiProfile: - (ourConversation && ourConversation.getOurProfile()) || undefined, + lokiProfile: UserUtils.getOurProfile(true), }; if (!chatParams.lokiProfile) { delete chatParams.lokiProfile; diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index f91cabfb4..5a8c46ba1 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -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, diff --git a/ts/receiver/queuedJob.ts b/ts/receiver/queuedJob.ts index fc06d17eb..d9505f115 100644 --- a/ts/receiver/queuedJob.ts +++ b/ts/receiver/queuedJob.ts @@ -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); diff --git a/ts/session/messages/outgoing/content/data/ExpirationTimerUpdateMessage.ts b/ts/session/messages/outgoing/content/data/ExpirationTimerUpdateMessage.ts index 180c6553d..4d68d13bf 100644 --- a/ts/session/messages/outgoing/content/data/ExpirationTimerUpdateMessage.ts +++ b/ts/session/messages/outgoing/content/data/ExpirationTimerUpdateMessage.ts @@ -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; } diff --git a/ts/session/utils/User.ts b/ts/session/utils/User.ts index 4d0a2e8f1..69443f6be 100644 --- a/ts/session/utils/User.ts +++ b/ts/session/utils/User.ts @@ -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; + } +} diff --git a/ts/test/test-utils/utils/message.ts b/ts/test/test-utils/utils/message.ts index f7116c8b5..3a4486fd9 100644 --- a/ts/test/test-utils/utils/message.ts +++ b/ts/test/test-utils/utils/message.ts @@ -76,7 +76,6 @@ export class MockConversation { members, left: false, expireTimer: 0, - profileSharing: true, mentionedUs: false, unreadCount: 5, isKickedFromGroup: false,