mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
always share our profileKey on outgoing messages
This commit is contained in:
parent
01085244bd
commit
fc24df00fb
9 changed files with 39 additions and 80 deletions
|
@ -512,7 +512,6 @@ describe('Backup', () => {
|
||||||
},
|
},
|
||||||
profileKey: 'BASE64KEY',
|
profileKey: 'BASE64KEY',
|
||||||
profileName: 'Someone! 🤔',
|
profileName: 'Someone! 🤔',
|
||||||
profileSharing: true,
|
|
||||||
timestamp: 1524185933350,
|
timestamp: 1524185933350,
|
||||||
type: 'private',
|
type: 'private',
|
||||||
unreadCount: 0,
|
unreadCount: 0,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { SignUpMode, SignUpTab } from './SignUpTab';
|
|
||||||
|
|
||||||
export enum TabType {
|
export enum TabType {
|
||||||
SignUp,
|
SignUp,
|
||||||
|
|
|
@ -35,12 +35,6 @@ import {
|
||||||
fromBase64ToArrayBuffer,
|
fromBase64ToArrayBuffer,
|
||||||
} from '../session/utils/String';
|
} from '../session/utils/String';
|
||||||
|
|
||||||
export interface OurLokiProfile {
|
|
||||||
displayName: string;
|
|
||||||
avatarPointer: string;
|
|
||||||
profileKey: Uint8Array | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ConversationAttributes {
|
export interface ConversationAttributes {
|
||||||
profileName?: string;
|
profileName?: string;
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -48,7 +42,6 @@ export interface ConversationAttributes {
|
||||||
members: Array<string>;
|
members: Array<string>;
|
||||||
left: boolean;
|
left: boolean;
|
||||||
expireTimer: number;
|
expireTimer: number;
|
||||||
profileSharing: boolean;
|
|
||||||
mentionedUs: boolean;
|
mentionedUs: boolean;
|
||||||
unreadCount: number;
|
unreadCount: number;
|
||||||
lastMessageStatus: string | null;
|
lastMessageStatus: string | null;
|
||||||
|
@ -83,7 +76,6 @@ export interface ConversationAttributesOptionals {
|
||||||
members?: Array<string>;
|
members?: Array<string>;
|
||||||
left?: boolean;
|
left?: boolean;
|
||||||
expireTimer?: number;
|
expireTimer?: number;
|
||||||
profileSharing?: boolean;
|
|
||||||
mentionedUs?: boolean;
|
mentionedUs?: boolean;
|
||||||
unreadCount?: number;
|
unreadCount?: number;
|
||||||
lastMessageStatus?: string | null;
|
lastMessageStatus?: string | null;
|
||||||
|
@ -122,7 +114,6 @@ export const fillConvoAttributesWithDefaults = (
|
||||||
return _.defaults(optAttributes, {
|
return _.defaults(optAttributes, {
|
||||||
members: [],
|
members: [],
|
||||||
left: false,
|
left: false,
|
||||||
profileSharing: false,
|
|
||||||
unreadCount: 0,
|
unreadCount: 0,
|
||||||
lastMessageStatus: null,
|
lastMessageStatus: null,
|
||||||
lastJoinedTimestamp: new Date('1970-01-01Z00:00:00:000').getTime(),
|
lastJoinedTimestamp: new Date('1970-01-01Z00:00:00:000').getTime(),
|
||||||
|
@ -179,11 +170,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
||||||
this.updateAvatarOnPublicChat(avatar)
|
this.updateAvatarOnPublicChat(avatar)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Always share profile pics with public chats
|
|
||||||
if (this.isPublic()) {
|
|
||||||
this.set('profileSharing', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.typingRefreshTimer = null;
|
this.typingRefreshTimer = null;
|
||||||
this.typingPauseTimer = null;
|
this.typingPauseTimer = null;
|
||||||
|
|
||||||
|
@ -687,7 +673,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
||||||
expireTimer,
|
expireTimer,
|
||||||
preview: uploads.preview,
|
preview: uploads.preview,
|
||||||
quote: uploads.quote,
|
quote: uploads.quote,
|
||||||
lokiProfile: this.getOurProfile(),
|
lokiProfile: UserUtils.getOurProfile(true),
|
||||||
};
|
};
|
||||||
|
|
||||||
const destinationPubkey = new PubKey(destination);
|
const destinationPubkey = new PubKey(destination);
|
||||||
|
@ -834,9 +820,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
||||||
if (!this.isPublic()) {
|
if (!this.isPublic()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.get('profileSharing')) {
|
// Always share avatars on PublicChat
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (profileKey && typeof profileKey !== 'string') {
|
if (profileKey && typeof profileKey !== 'string') {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
@ -953,16 +937,10 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
let profileKey;
|
|
||||||
if (this.get('profileSharing')) {
|
|
||||||
profileKey = window.storage.get('profileKey');
|
|
||||||
}
|
|
||||||
|
|
||||||
const expireUpdate = {
|
const expireUpdate = {
|
||||||
identifier: message.id,
|
identifier: message.id,
|
||||||
timestamp,
|
timestamp,
|
||||||
expireTimer,
|
expireTimer,
|
||||||
profileKey,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!expireUpdate.expireTimer) {
|
if (!expireUpdate.expireTimer) {
|
||||||
|
@ -1565,33 +1543,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
||||||
return null;
|
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() {
|
public getNumber() {
|
||||||
if (!this.isPrivate()) {
|
if (!this.isPrivate()) {
|
||||||
return '';
|
return '';
|
||||||
|
|
|
@ -878,10 +878,6 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
|
||||||
}
|
}
|
||||||
|
|
||||||
const { body, attachments, preview, quote } = await this.uploadData();
|
const { body, attachments, preview, quote } = await this.uploadData();
|
||||||
const ourNumber = UserUtils.getOurPubKeyStrFromCache();
|
|
||||||
const ourConversation = ConversationController.getInstance().get(
|
|
||||||
ourNumber
|
|
||||||
);
|
|
||||||
|
|
||||||
const chatParams = {
|
const chatParams = {
|
||||||
identifier: this.id,
|
identifier: this.id,
|
||||||
|
@ -891,8 +887,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
|
||||||
attachments,
|
attachments,
|
||||||
preview,
|
preview,
|
||||||
quote,
|
quote,
|
||||||
lokiProfile:
|
lokiProfile: UserUtils.getOurProfile(true),
|
||||||
(ourConversation && ourConversation.getOurProfile()) || undefined,
|
|
||||||
};
|
};
|
||||||
if (!chatParams.lokiProfile) {
|
if (!chatParams.lokiProfile) {
|
||||||
delete chatParams.lokiProfile;
|
delete chatParams.lokiProfile;
|
||||||
|
|
|
@ -400,15 +400,7 @@ async function handleProfileUpdate(
|
||||||
const profileKey = StringUtils.decode(profileKeyBuffer, 'base64');
|
const profileKey = StringUtils.decode(profileKeyBuffer, 'base64');
|
||||||
|
|
||||||
if (!isIncoming) {
|
if (!isIncoming) {
|
||||||
const receiver = await ConversationController.getInstance().getOrCreateAndWait(
|
// We update our own profileKey if it's different from what we have
|
||||||
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
|
|
||||||
const ourNumber = UserUtils.getOurPubKeyStrFromCache();
|
const ourNumber = UserUtils.getOurPubKeyStrFromCache();
|
||||||
const me = await ConversationController.getInstance().getOrCreate(
|
const me = await ConversationController.getInstance().getOrCreate(
|
||||||
ourNumber,
|
ourNumber,
|
||||||
|
|
|
@ -254,12 +254,8 @@ async function processProfileKey(
|
||||||
sendingDeviceConversation: ConversationModel,
|
sendingDeviceConversation: ConversationModel,
|
||||||
profileKeyBuffer: Uint8Array
|
profileKeyBuffer: Uint8Array
|
||||||
) {
|
) {
|
||||||
const ourNumber = UserUtils.getOurPubKeyStrFromCache();
|
|
||||||
|
|
||||||
const profileKey = StringUtils.decode(profileKeyBuffer, 'base64');
|
const profileKey = StringUtils.decode(profileKeyBuffer, 'base64');
|
||||||
if (source === ourNumber) {
|
if (conversation.isPrivate()) {
|
||||||
conversation.set({ profileSharing: true });
|
|
||||||
} else if (conversation.isPrivate()) {
|
|
||||||
await conversation.setProfileKey(profileKey);
|
await conversation.setProfileKey(profileKey);
|
||||||
} else {
|
} else {
|
||||||
await sendingDeviceConversation.setProfileKey(profileKey);
|
await sendingDeviceConversation.setProfileKey(profileKey);
|
||||||
|
|
|
@ -8,18 +8,15 @@ import { Constants } from '../../../..';
|
||||||
interface ExpirationTimerUpdateMessageParams extends MessageParams {
|
interface ExpirationTimerUpdateMessageParams extends MessageParams {
|
||||||
groupId?: string | PubKey;
|
groupId?: string | PubKey;
|
||||||
expireTimer: number | null;
|
expireTimer: number | null;
|
||||||
profileKey?: Uint8Array;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ExpirationTimerUpdateMessage extends DataMessage {
|
export class ExpirationTimerUpdateMessage extends DataMessage {
|
||||||
public readonly groupId?: PubKey;
|
public readonly groupId?: PubKey;
|
||||||
public readonly expireTimer: number | null;
|
public readonly expireTimer: number | null;
|
||||||
public readonly profileKey?: Uint8Array;
|
|
||||||
|
|
||||||
constructor(params: ExpirationTimerUpdateMessageParams) {
|
constructor(params: ExpirationTimerUpdateMessageParams) {
|
||||||
super({ timestamp: params.timestamp, identifier: params.identifier });
|
super({ timestamp: params.timestamp, identifier: params.identifier });
|
||||||
this.expireTimer = params.expireTimer;
|
this.expireTimer = params.expireTimer;
|
||||||
this.profileKey = params.profileKey;
|
|
||||||
|
|
||||||
const { groupId } = params;
|
const { groupId } = params;
|
||||||
this.groupId = groupId ? PubKey.cast(groupId) : undefined;
|
this.groupId = groupId ? PubKey.cast(groupId) : undefined;
|
||||||
|
@ -52,9 +49,6 @@ export class ExpirationTimerUpdateMessage extends DataMessage {
|
||||||
if (this.expireTimer) {
|
if (this.expireTimer) {
|
||||||
data.expireTimer = this.expireTimer;
|
data.expireTimer = this.expireTimer;
|
||||||
}
|
}
|
||||||
if (this.profileKey && this.profileKey.length) {
|
|
||||||
data.profileKey = this.profileKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { getItemById } from '../../../ts/data/data';
|
||||||
import { KeyPair } from '../../../libtextsecure/libsignal-protocol';
|
import { KeyPair } from '../../../libtextsecure/libsignal-protocol';
|
||||||
import { PubKey } from '../types';
|
import { PubKey } from '../types';
|
||||||
import { toHex } from './String';
|
import { toHex } from './String';
|
||||||
|
import { ConversationController } from '../conversations';
|
||||||
|
|
||||||
export type HexKeyPair = {
|
export type HexKeyPair = {
|
||||||
pubKey: string;
|
pubKey: string;
|
||||||
|
@ -77,3 +78,36 @@ export function isRestoringFromSeed(): boolean {
|
||||||
export function setRestoringFromSeed(isRestoring: boolean) {
|
export function setRestoringFromSeed(isRestoring: boolean) {
|
||||||
window.textsecure.storage.user.setRestoringFromSeed(isRestoring);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -76,7 +76,6 @@ export class MockConversation {
|
||||||
members,
|
members,
|
||||||
left: false,
|
left: false,
|
||||||
expireTimer: 0,
|
expireTimer: 0,
|
||||||
profileSharing: true,
|
|
||||||
mentionedUs: false,
|
mentionedUs: false,
|
||||||
unreadCount: 5,
|
unreadCount: 5,
|
||||||
isKickedFromGroup: false,
|
isKickedFromGroup: false,
|
||||||
|
|
Loading…
Reference in a new issue