Remove old multi device functions

pull/1176/head
Mikunj 5 years ago
parent 7b7d8c0e2a
commit ae44f0da0f

@ -4,7 +4,6 @@
ConversationController, ConversationController,
MessageController, MessageController,
_, _,
libloki,
*/ */
/* eslint-disable more/no-then */ /* eslint-disable more/no-then */
@ -36,7 +35,9 @@
return null; return null;
} }
const primary = await window.libsession.Protocols.MultiDeviceProtocol.getPrimaryDevice(originalSource); const primary = await window.libsession.Protocols.MultiDeviceProtocol.getPrimaryDevice(
originalSource
);
const source = primary.key; const source = primary.key;
const message = messages.find( const message = messages.find(

@ -211,7 +211,9 @@
return true; return true;
} }
const ourDevices = await window.libsession.Protocols.MultiDeviceProtocol.getAllDevices(this.ourNumber); const ourDevices = await window.libsession.Protocols.MultiDeviceProtocol.getAllDevices(
this.ourNumber
);
return ourDevices.some(device => device.key === this.id); return ourDevices.some(device => device.key === this.id);
}, },

@ -1,4 +1,3 @@
type MessageModelType = 'incoming' | 'outgoing' | 'friend-request'; type MessageModelType = 'incoming' | 'outgoing' | 'friend-request';
export type EndSessionType = 'done' | 'ongoing'; export type EndSessionType = 'done' | 'ongoing';

@ -642,14 +642,6 @@ async function removePairingAuthorisationsFor(pubKey) {
await channels.removePairingAuthorisationsFor(pubKey); await channels.removePairingAuthorisationsFor(pubKey);
} }
function getAuthorisationForSecondaryPubKey(pubKey) {
return channels.getAuthorisationForSecondaryPubKey(pubKey);
}
function getSecondaryDevicesFor(primaryDevicePubKey) {
return channels.getSecondaryDevicesFor(primaryDevicePubKey);
}
function getGuardNodes() { function getGuardNodes() {
return channels.getGuardNodes(); return channels.getGuardNodes();
} }
@ -658,14 +650,6 @@ function updateGuardNodes(nodes) {
return channels.updateGuardNodes(nodes); return channels.updateGuardNodes(nodes);
} }
function getPrimaryDeviceFor(secondaryDevicePubKey) {
return channels.getPrimaryDeviceFor(secondaryDevicePubKey);
}
function getPairedDevicesFor(pubKey) {
return channels.getPairedDevicesFor(pubKey);
}
// Items // Items
const ITEM_KEYS = { const ITEM_KEYS = {

@ -1,4 +1,4 @@
/* global Whisper, i18n, textsecure, libloki, _ */ /* global Whisper, i18n, textsecure, _ */
// eslint-disable-next-line func-names // eslint-disable-next-line func-names
(function() { (function() {

@ -1,5 +1,4 @@
/* global window, libsignal, textsecure, /* global window, libsignal, textsecure */
lokiFileServerAPI, */
// eslint-disable-next-line func-names // eslint-disable-next-line func-names
(function() { (function() {

@ -574,8 +574,12 @@
secondaryDevicePubKey, secondaryDevicePubKey,
libloki.crypto.PairingType.GRANT libloki.crypto.PairingType.GRANT
); );
const authorisations = await libsession.Protocols.MultiDeviceProtocol.getPairingAuthorisations(secondaryDevicePubKey); const authorisations = await libsession.Protocols.MultiDeviceProtocol.getPairingAuthorisations(
const existingAuthorisation = authorisations.some(pairing => pairing.secondaryDevicePubKey === secondaryDevicePubKey); secondaryDevicePubKey
);
const existingAuthorisation = authorisations.some(
pairing => pairing.secondaryDevicePubKey === secondaryDevicePubKey
);
if (!existingAuthorisation) { if (!existingAuthorisation) {
throw new Error( throw new Error(
'authoriseSecondaryDevice: request signature missing from database!' 'authoriseSecondaryDevice: request signature missing from database!'
@ -590,7 +594,9 @@
}; };
// Update authorisation in database with the new grant signature // Update authorisation in database with the new grant signature
await libsession.Protocols.MultiDeviceProtocol.savePairingAuthorisation(authorisation); await libsession.Protocols.MultiDeviceProtocol.savePairingAuthorisation(
authorisation
);
// Try to upload to the file server and then send a message // Try to upload to the file server and then send a message
try { try {

@ -968,7 +968,9 @@ MessageReceiver.prototype.extend({
if (valid) { if (valid) {
// Pairing dialog is open and is listening // Pairing dialog is open and is listening
if (Whisper.events.isListenedTo('devicePairingRequestReceived')) { if (Whisper.events.isListenedTo('devicePairingRequestReceived')) {
await window.libsession.Protocols.MultiDeviceProtocol.savePairingAuthorisation(pairingRequest); await window.libsession.Protocols.MultiDeviceProtocol.savePairingAuthorisation(
pairingRequest
);
Whisper.events.trigger( Whisper.events.trigger(
'devicePairingRequestReceived', 'devicePairingRequestReceived',
pairingRequest.secondaryDevicePubKey pairingRequest.secondaryDevicePubKey
@ -1014,7 +1016,9 @@ MessageReceiver.prototype.extend({
window.storage.remove('secondaryDeviceStatus'); window.storage.remove('secondaryDeviceStatus');
window.storage.put('isSecondaryDevice', true); window.storage.put('isSecondaryDevice', true);
window.storage.put('primaryDevicePubKey', primaryDevicePubKey); window.storage.put('primaryDevicePubKey', primaryDevicePubKey);
await window.libsession.Protocols.MultiDeviceProtocol.savePairingAuthorisation(pairingAuthorisation); await window.libsession.Protocols.MultiDeviceProtocol.savePairingAuthorisation(
pairingAuthorisation
);
const primaryConversation = await ConversationController.getOrCreateAndWait( const primaryConversation = await ConversationController.getOrCreateAndWait(
primaryDevicePubKey, primaryDevicePubKey,
'private' 'private'

@ -431,7 +431,9 @@ OutgoingMessage.prototype = {
const ourPubKey = textsecure.storage.user.getNumber(); const ourPubKey = textsecure.storage.user.getNumber();
const ourPrimaryPubkey = window.storage.get('primaryDevicePubKey'); const ourPrimaryPubkey = window.storage.get('primaryDevicePubKey');
const secondaryPubKeys = const secondaryPubKeys =
(await window.libsession.Protocols.MultiDeviceProtocol.getSecondaryDevices(ourPubKey)) || []; (await window.libsession.Protocols.MultiDeviceProtocol.getSecondaryDevices(
ourPubKey
)) || [];
let aliasedPubkey = devicePubKey; let aliasedPubkey = devicePubKey;
if (devicePubKey === ourPubKey) { if (devicePubKey === ourPubKey) {
aliasedPubkey = 'OUR_PUBKEY'; // should not happen aliasedPubkey = 'OUR_PUBKEY'; // should not happen

@ -7,6 +7,9 @@ import {
SessionButtonColor, SessionButtonColor,
SessionButtonType, SessionButtonType,
} from '../SessionButton'; } from '../SessionButton';
import { UserUtil } from '../../../util';
import { MultiDeviceProtocol } from '../../../session/protocols';
import { PubKey } from '../../../session/types';
export enum SessionSettingCategory { export enum SessionSettingCategory {
Appearance = 'appearance', Appearance = 'appearance',
@ -644,16 +647,14 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
} }
} }
private refreshLinkedDevice() { private async refreshLinkedDevice() {
const ourPubKey = window.textsecure.storage.user.getNumber(); const ourPubKey = await UserUtil.getCurrentDevicePubKey();
if (ourPubKey) {
const pubKey = new PubKey(ourPubKey);
const devices = await MultiDeviceProtocol.getSecondaryDevices(pubKey);
window.libloki.storage this.setState({ linkedPubKeys: devices.map(d => d.key) });
.getSecondaryDevicesFor(ourPubKey) }
.then((pubKeys: any) => {
this.setState({
linkedPubKeys: pubKeys,
});
});
} }
private async onKeyUp(event: any) { private async onKeyUp(event: any) {

@ -3,6 +3,9 @@ import { SessionIconButton, SessionIconSize, SessionIconType } from '../icon';
import { SessionSettingCategory, SettingsViewProps } from './SessionSettings'; import { SessionSettingCategory, SettingsViewProps } from './SessionSettings';
import { SessionButton } from '../SessionButton'; import { SessionButton } from '../SessionButton';
import { UserUtil } from '../../../util';
import { PubKey } from '../../../session/types';
import { MultiDeviceProtocol } from '../../../session/protocols';
interface Props extends SettingsViewProps { interface Props extends SettingsViewProps {
// showLinkDeviceButton is used to completely hide the button while the settings password lock is displayed // showLinkDeviceButton is used to completely hide the button while the settings password lock is displayed
@ -37,22 +40,20 @@ export class SettingsHeader extends React.Component<Props, any> {
public componentDidMount() { public componentDidMount() {
if (!this.props.isSecondaryDevice) { if (!this.props.isSecondaryDevice) {
window.Whisper.events.on('refreshLinkedDeviceList', async () => { window.Whisper.events.on('refreshLinkedDeviceList', async () => {
this.refreshLinkedDevice(); void this.refreshLinkedDevice();
}); });
this.refreshLinkedDevice(); void this.refreshLinkedDevice();
} }
} }
public refreshLinkedDevice() { public async refreshLinkedDevice() {
const ourPubKey = window.textsecure.storage.user.getNumber(); const ourPubKey = await UserUtil.getCurrentDevicePubKey();
if (ourPubKey) {
const pubKey = new PubKey(ourPubKey);
const devices = await MultiDeviceProtocol.getSecondaryDevices(pubKey);
window.libloki.storage this.setState({ disableLinkDeviceButton: devices.length > 0 });
.getSecondaryDevicesFor(ourPubKey) }
.then((pubKeys: any) => {
this.setState({
disableLinkDeviceButton: pubKeys && pubKeys.length > 0,
});
});
} }
public componentWillUnmount() { public componentWillUnmount() {

@ -605,9 +605,9 @@ export async function handleDataMessage(
const isOwnDevice = async (device: string) => { const isOwnDevice = async (device: string) => {
const pubKey = new PubKey(device); const pubKey = new PubKey(device);
const allDevices = await MultiDeviceProtocol.getAllDevices(pubKey); const allDevices = await MultiDeviceProtocol.getAllDevices(pubKey);
return allDevices.some(device => PubKey.isEqual(device, pubKey)); return allDevices.some(d => PubKey.isEqual(d, pubKey));
}; };
const ownDevice = await isOwnDevice(source); const ownDevice = await isOwnDevice(source);

@ -1,5 +1,3 @@
import { getPairedDevicesFor } from '../../../js/modules/data';
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import { import {
MessageQueueInterface, MessageQueueInterface,
@ -20,7 +18,7 @@ import {
} from '../utils'; } from '../utils';
import { PubKey } from '../types'; import { PubKey } from '../types';
import { MessageSender } from '.'; import { MessageSender } from '.';
import { SessionProtocol } from '../protocols'; import { MultiDeviceProtocol, SessionProtocol } from '../protocols';
import { UserUtil } from '../../util'; import { UserUtil } from '../../util';
export class MessageQueue implements MessageQueueInterface { export class MessageQueue implements MessageQueueInterface {
@ -35,8 +33,7 @@ export class MessageQueue implements MessageQueueInterface {
} }
public async sendUsingMultiDevice(user: PubKey, message: ContentMessage) { public async sendUsingMultiDevice(user: PubKey, message: ContentMessage) {
const userLinked = await getPairedDevicesFor(user.key); const userDevices = await MultiDeviceProtocol.getAllDevices(user.key);
const userDevices = userLinked.map(d => new PubKey(d));
await this.sendMessageToDevices(userDevices, message); await this.sendMessageToDevices(userDevices, message);
} }
@ -56,11 +53,10 @@ export class MessageQueue implements MessageQueueInterface {
const currentDevice = await UserUtil.getCurrentDevicePubKey(); const currentDevice = await UserUtil.getCurrentDevicePubKey();
if (currentDevice) { if (currentDevice) {
const otherDevices = await getPairedDevicesFor(currentDevice); const ourDevices = await MultiDeviceProtocol.getAllDevices(
currentDevice
const ourDevices = [currentDevice, ...otherDevices].map(
device => new PubKey(device)
); );
await this.sendSyncMessage(message, ourDevices); await this.sendSyncMessage(message, ourDevices);
// Remove our devices from currentDevices // Remove our devices from currentDevices

@ -1,12 +1,10 @@
import * as _ from 'lodash'; import * as _ from 'lodash';
import * as UserUtils from '../../util/user'; import * as UserUtils from '../../util/user';
import { import { getAllConversations } from '../../../js/modules/data';
getAllConversations,
getPrimaryDeviceFor,
} from '../../../js/modules/data';
import { ConversationController, Whisper } from '../../window'; import { ConversationController, Whisper } from '../../window';
import { ContentMessage, SyncMessage } from '../messages/outgoing'; import { ContentMessage, SyncMessage } from '../messages/outgoing';
import { MultiDeviceProtocol } from '../protocols';
export function from(message: ContentMessage): SyncMessage | undefined { export function from(message: ContentMessage): SyncMessage | undefined {
// const { timestamp, identifier } = message; // const { timestamp, identifier } = message;
@ -30,7 +28,7 @@ export async function getSyncContacts(): Promise<Array<any> | undefined> {
return []; return [];
} }
const primaryDevice = await getPrimaryDeviceFor(thisDevice); const primaryDevice = await MultiDeviceProtocol.getPrimaryDevice(thisDevice);
const conversations = await getAllConversations({ const conversations = await getAllConversations({
ConversationCollection: Whisper.ConversationCollection, ConversationCollection: Whisper.ConversationCollection,
}); });
@ -62,7 +60,7 @@ export async function getSyncContacts(): Promise<Array<any> | undefined> {
const secondaryContacts = (await Promise.all(seondaryContactsPromise)) const secondaryContacts = (await Promise.all(seondaryContactsPromise))
// Filter out our primary key if it was added here // Filter out our primary key if it was added here
.filter(c => c.id !== primaryDevice); .filter(c => c.id !== primaryDevice.key);
// Return unique contacts // Return unique contacts
return _.uniqBy( return _.uniqBy(

@ -5,11 +5,7 @@ import { AdvancedSearchOptions, SearchOptions } from '../../types/Search';
import { trigger } from '../../shims/events'; import { trigger } from '../../shims/events';
import { getMessageModel } from '../../shims/Whisper'; import { getMessageModel } from '../../shims/Whisper';
import { cleanSearchTerm } from '../../util/cleanSearchTerm'; import { cleanSearchTerm } from '../../util/cleanSearchTerm';
import { import { searchConversations, searchMessages } from '../../../js/modules/data';
getPrimaryDeviceFor,
searchConversations,
searchMessages,
} from '../../../js/modules/data';
import { makeLookup } from '../../util/makeLookup'; import { makeLookup } from '../../util/makeLookup';
import { import {
@ -19,6 +15,8 @@ import {
RemoveAllConversationsActionType, RemoveAllConversationsActionType,
SelectedConversationChangedActionType, SelectedConversationChangedActionType,
} from './conversations'; } from './conversations';
import { MultiDeviceProtocol } from '../../session/protocols';
import { PubKey } from '../../session/types';
// State // State
@ -283,15 +281,13 @@ async function queryConversationsAndContacts(
query query
); );
const ourPrimaryDevice = isSecondaryDevice const ourPrimaryDevice = await MultiDeviceProtocol.getPrimaryDevice(
? await getPrimaryDeviceFor(ourNumber) ourNumber
: ourNumber; );
const resultPrimaryDevices: Array<string | null> = await Promise.all( const resultPrimaryDevices = await Promise.all(
searchResults.map(async conversation => searchResults.map(async conversation =>
conversation.id === ourPrimaryDevice MultiDeviceProtocol.getPrimaryDevice(conversation.id)
? Promise.resolve(ourPrimaryDevice)
: getPrimaryDeviceFor(conversation.id)
) )
); );
@ -303,18 +299,10 @@ async function queryConversationsAndContacts(
const conversation = searchResults[i]; const conversation = searchResults[i];
const primaryDevice = resultPrimaryDevices[i]; const primaryDevice = resultPrimaryDevices[i];
if (primaryDevice) { if (isSecondaryDevice && PubKey.isEqual(primaryDevice, ourPrimaryDevice)) {
if (isSecondaryDevice && primaryDevice === ourPrimaryDevice) { conversations.push(ourNumber);
conversations.push(ourNumber);
} else {
conversations.push(primaryDevice);
}
} else if (conversation.type === 'direct') {
contacts.push(conversation.id);
} else if (conversation.type !== 'group') {
contacts.push(conversation.id);
} else { } else {
conversations.push(conversation.id); conversations.push(primaryDevice.key);
} }
} }
// Inject synthetic Note to Self entry if query matches localized 'Note to Self' // Inject synthetic Note to Self entry if query matches localized 'Note to Self'

Loading…
Cancel
Save