Merge contacts when we discover split or duplicated contacts

This commit is contained in:
Scott Nonnenberg 2020-07-10 11:28:49 -07:00
parent 68e432188b
commit 901179440f
32 changed files with 1199 additions and 824 deletions

View file

@ -696,6 +696,7 @@ export default class AccountManager extends EventTarget {
const conversationId = window.ConversationController.ensureContactIds({
e164: number,
uuid,
highTrust: true,
});
if (!conversationId) {
throw new Error('registrationDone: no conversationId!');

View file

@ -1058,6 +1058,7 @@ class MessageReceiverInner extends EventTarget {
) {
const {
destination,
destinationUuid,
timestamp,
message: msg,
expirationStartTimestamp,
@ -1083,12 +1084,13 @@ class MessageReceiverInner extends EventTarget {
msg.flags &&
msg.flags & window.textsecure.protobuf.DataMessage.Flags.END_SESSION
) {
if (!destination) {
const identifier = destination || destinationUuid;
if (!identifier) {
throw new Error(
'MessageReceiver.handleSentMessage: Cannot end session with falsey destination'
);
}
p = this.handleEndSession(destination);
p = this.handleEndSession(identifier);
}
return p.then(async () =>
this.processDecrypted(envelope, msg).then(message => {
@ -1120,6 +1122,7 @@ class MessageReceiverInner extends EventTarget {
ev.confirm = this.removeFromCache.bind(this, envelope);
ev.data = {
destination,
destinationUuid,
timestamp: timestamp.toNumber(),
serverTimestamp: envelope.serverTimestamp,
device: envelope.sourceDevice,
@ -1303,7 +1306,8 @@ class MessageReceiverInner extends EventTarget {
ev.timestamp = envelope.timestamp.toNumber();
ev.read = {
timestamp: receiptMessage.timestamp[i].toNumber(),
reader: envelope.source || envelope.sourceUuid,
source: envelope.source,
sourceUuid: envelope.sourceUuid,
};
results.push(this.dispatchAndWait(ev));
}

View file

@ -925,7 +925,7 @@ export default class MessageSender {
async sendCallingMessage(
recipientId: string,
callingMessage: CallingMessageClass,
sendOptions: SendOptionsType
sendOptions?: SendOptionsType
) {
const recipients = [recipientId];
const finalTimestamp = Date.now();
@ -1001,7 +1001,11 @@ export default class MessageSender {
);
}
async syncReadMessages(
reads: Array<{ sender: string; timestamp: number }>,
reads: Array<{
senderUuid?: string;
senderE164?: string;
timestamp: number;
}>,
options?: SendOptionsType
) {
const myNumber = window.textsecure.storage.user.getNumber();
@ -1013,7 +1017,8 @@ export default class MessageSender {
for (let i = 0; i < reads.length; i += 1) {
const read = new window.textsecure.protobuf.SyncMessage.Read();
read.timestamp = reads[i].timestamp;
read.sender = reads[i].sender;
read.sender = reads[i].senderE164;
read.senderUuid = reads[i].senderUuid;
syncMessage.read.push(read);
}
@ -1352,20 +1357,20 @@ export default class MessageSender {
proto.flags = window.textsecure.protobuf.DataMessage.Flags.END_SESSION;
proto.timestamp = timestamp;
const identifier = e164 || uuid;
const identifier = uuid || e164;
const logError = (prefix: string) => (error: Error) => {
window.log.error(prefix, error && error.stack ? error.stack : error);
throw error;
};
const deleteAllSessions = async (targetNumber: string) =>
const deleteAllSessions = async (targetIdentifier: string) =>
window.textsecure.storage.protocol
.getDeviceIds(targetNumber)
.getDeviceIds(targetIdentifier)
.then(async deviceIds =>
Promise.all(
deviceIds.map(async deviceId => {
const address = new window.libsignal.SignalProtocolAddress(
targetNumber,
targetIdentifier,
deviceId
);
window.log.info('deleting sessions for', address.toString());
@ -1401,7 +1406,7 @@ export default class MessageSender {
const myNumber = window.textsecure.storage.user.getNumber();
const myUuid = window.textsecure.storage.user.getUuid();
// We already sent the reset session to our other devices in the code above!
if (e164 === myNumber || uuid === myUuid) {
if ((e164 && e164 === myNumber) || (uuid && uuid === myUuid)) {
return sendToContactPromise;
}

View file

@ -6,6 +6,7 @@ import { Agent } from 'https';
import is from '@sindresorhus/is';
import { redactPackId } from '../../js/modules/stickers';
import { getRandomValue } from '../Crypto';
import MessageSender from './SendMessage';
import PQueue from 'p-queue';
import { v4 as getGuid } from 'uuid';
@ -13,7 +14,6 @@ import { v4 as getGuid } from 'uuid';
import {
StorageServiceCallOptionsType,
StorageServiceCredentials,
TextSecureType,
} from '../textsecure.d';
// tslint:disable no-bitwise
@ -589,9 +589,9 @@ export type WebAPIType = {
getSenderCertificate: (withUuid?: boolean) => Promise<any>;
getSticker: (packId: string, stickerId: string) => Promise<any>;
getStickerPackManifest: (packId: string) => Promise<StickerPackManifestType>;
getStorageCredentials: TextSecureType['messaging']['getStorageCredentials'];
getStorageManifest: TextSecureType['messaging']['getStorageManifest'];
getStorageRecords: TextSecureType['messaging']['getStorageRecords'];
getStorageCredentials: MessageSender['getStorageCredentials'];
getStorageManifest: MessageSender['getStorageManifest'];
getStorageRecords: MessageSender['getStorageRecords'];
makeProxiedRequest: (
targetUrl: string,
options?: ProxiedRequestOptionsType