|
|
|
@ -15,6 +15,8 @@ import { SignalService } from './../protobuf';
|
|
|
|
import { removeFromCache } from './cache';
|
|
|
|
import { removeFromCache } from './cache';
|
|
|
|
import { toNumber } from 'lodash';
|
|
|
|
import { toNumber } from 'lodash';
|
|
|
|
import { DataMessage } from '../session/messages/outgoing';
|
|
|
|
import { DataMessage } from '../session/messages/outgoing';
|
|
|
|
|
|
|
|
import { MultiDeviceProtocol } from '../session/protocols';
|
|
|
|
|
|
|
|
import { PubKey } from '../session/types';
|
|
|
|
|
|
|
|
|
|
|
|
export { handleEndSession, handleMediumGroupUpdate };
|
|
|
|
export { handleEndSession, handleMediumGroupUpdate };
|
|
|
|
|
|
|
|
|
|
|
|
@ -265,7 +267,7 @@ async function handleSecondaryDeviceFriendRequest(pubKey: string) {
|
|
|
|
if (!c || !(await c.isFriendWithAnyDevice())) {
|
|
|
|
if (!c || !(await c.isFriendWithAnyDevice())) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await window.libloki.storage.savePairingAuthorisation(authorisation);
|
|
|
|
await MultiDeviceProtocol.savePairingAuthorisation(authorisation);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -601,14 +603,11 @@ export async function handleDataMessage(
|
|
|
|
|
|
|
|
|
|
|
|
const source = envelope.senderIdentity || senderPubKey;
|
|
|
|
const source = envelope.senderIdentity || senderPubKey;
|
|
|
|
|
|
|
|
|
|
|
|
const isOwnDevice = async (pubkey: string) => {
|
|
|
|
const isOwnDevice = async (device: string) => {
|
|
|
|
const primaryDevice = window.storage.get('primaryDevicePubKey');
|
|
|
|
const pubKey = new PubKey(device);
|
|
|
|
const secondaryDevices = await window.libloki.storage.getPairedDevicesFor(
|
|
|
|
const allDevices = await MultiDeviceProtocol.getAllDevices(pubKey);
|
|
|
|
primaryDevice
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const allDevices = [primaryDevice, ...secondaryDevices];
|
|
|
|
return allDevices.some(device => PubKey.isEqual(device, pubKey));
|
|
|
|
return allDevices.includes(pubkey);
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const ownDevice = await isOwnDevice(source);
|
|
|
|
const ownDevice = await isOwnDevice(source);
|
|
|
|
@ -773,13 +772,7 @@ export async function handleMessageEvent(event: any): Promise<void> {
|
|
|
|
// - group.id if it is a group message
|
|
|
|
// - group.id if it is a group message
|
|
|
|
let conversationId = id;
|
|
|
|
let conversationId = id;
|
|
|
|
|
|
|
|
|
|
|
|
const authorisation = await window.libloki.storage.getGrantAuthorisationForSecondaryPubKey(
|
|
|
|
const primarySource = await MultiDeviceProtocol.getPrimaryDevice(source);
|
|
|
|
source
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const primarySource =
|
|
|
|
|
|
|
|
(authorisation && authorisation.primaryDevicePubKey) || source;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isGroupMessage) {
|
|
|
|
if (isGroupMessage) {
|
|
|
|
/* handle one part of the group logic here:
|
|
|
|
/* handle one part of the group logic here:
|
|
|
|
handle requesting info of a new group,
|
|
|
|
handle requesting info of a new group,
|
|
|
|
@ -789,7 +782,7 @@ export async function handleMessageEvent(event: any): Promise<void> {
|
|
|
|
const shouldReturn = await preprocessGroupMessage(
|
|
|
|
const shouldReturn = await preprocessGroupMessage(
|
|
|
|
source,
|
|
|
|
source,
|
|
|
|
message.group,
|
|
|
|
message.group,
|
|
|
|
primarySource
|
|
|
|
primarySource.key
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// handleGroupMessage() can process fully a message in some cases
|
|
|
|
// handleGroupMessage() can process fully a message in some cases
|
|
|
|
@ -800,9 +793,9 @@ export async function handleMessageEvent(event: any): Promise<void> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (source !== ourNumber && authorisation) {
|
|
|
|
if (source !== ourNumber) {
|
|
|
|
// Ignore auth from our devices
|
|
|
|
// Ignore auth from our devices
|
|
|
|
conversationId = authorisation.primaryDevicePubKey;
|
|
|
|
conversationId = primarySource.key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// the conversation with the primary device of that source (can be the same as conversationOrigin)
|
|
|
|
// the conversation with the primary device of that source (can be the same as conversationOrigin)
|
|
|
|
|