Early preparations for PNP Contact Merging

This commit is contained in:
Scott Nonnenberg 2022-08-09 14:39:00 -07:00 committed by GitHub
parent 2f5dd73e58
commit faf6c41332
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 1572 additions and 447 deletions

View file

@ -68,14 +68,14 @@ function isStoryAMatch(
return false;
}
const authorConversationId = window.ConversationController.ensureContactIds({
const authorConversation = window.ConversationController.lookupOrCreate({
e164: undefined,
uuid: authorUuid,
});
return (
message.sent_at === sentTimestamp &&
getContactId(message) === authorConversationId &&
getContactId(message) === authorConversation?.id &&
(message.conversationId === conversationId ||
message.conversationId === ourConversationId)
);

View file

@ -4,15 +4,11 @@
import * as log from '../logging/log';
import { profileService } from '../services/profiles';
export async function getProfile(
providedUuid?: string,
providedE164?: string
): Promise<void> {
const id = window.ConversationController.ensureContactIds({
uuid: providedUuid,
e164: providedE164,
export async function getProfile(uuid?: string, e164?: string): Promise<void> {
const c = window.ConversationController.lookupOrCreate({
uuid,
e164,
});
const c = window.ConversationController.get(id);
if (!c) {
log.error('getProfile: failed to find conversation; doing nothing');
return;

View file

@ -616,18 +616,9 @@ function startAutomaticSessionReset(decryptionError: DecryptionErrorEventData) {
scheduleSessionReset(senderUuid, senderDevice);
const conversationId = window.ConversationController.ensureContactIds({
const conversation = window.ConversationController.lookupOrCreate({
uuid: senderUuid,
});
if (!conversationId) {
log.warn(
'onLightSessionReset: No conversation id, cannot add message to timeline'
);
return;
}
const conversation = window.ConversationController.get(conversationId);
if (!conversation) {
log.warn(
'onLightSessionReset: No conversation, cannot add message to timeline'

View file

@ -73,25 +73,24 @@ export async function lookupConversationWithoutUuid(
const serverLookup = await messaging.getUuidsForE164s([options.e164]);
if (serverLookup[options.e164]) {
conversationId = window.ConversationController.ensureContactIds({
const convo = window.ConversationController.maybeMergeContacts({
aci: serverLookup[options.e164] || undefined,
e164: options.e164,
uuid: serverLookup[options.e164],
highTrust: true,
reason: 'startNewConversationWithoutUuid(e164)',
});
conversationId = convo?.id;
}
} else {
const foundUsername = await checkForUsername(options.username);
if (foundUsername) {
conversationId = window.ConversationController.ensureContactIds({
const convo = window.ConversationController.lookupOrCreate({
uuid: foundUsername.uuid,
highTrust: true,
reason: 'startNewConversationWithoutUuid(username)',
});
const convo = window.ConversationController.get(conversationId);
strictAssert(convo, 'We just ensured conversation existence');
conversationId = convo.id;
convo.set({ username: foundUsername.username });
}
}

View file

@ -89,10 +89,10 @@ export async function markConversationRead(
originalReadStatus: messageSyncData.originalReadStatus,
senderE164: messageSyncData.source,
senderUuid: messageSyncData.sourceUuid,
senderId: window.ConversationController.ensureContactIds({
senderId: window.ConversationController.lookupOrCreate({
e164: messageSyncData.source,
uuid: messageSyncData.sourceUuid,
}),
})?.id,
timestamp: messageSyncData.sent_at,
hasErrors: message ? hasErrors(message.attributes) : false,
};

View file

@ -63,21 +63,21 @@ export async function sendReceipts({
return result;
}
const senderId = window.ConversationController.ensureContactIds({
const sender = window.ConversationController.lookupOrCreate({
e164: senderE164,
uuid: senderUuid,
});
if (!senderId) {
if (!sender) {
throw new Error(
'no conversation found with that E164/UUID. Cannot send this receipt'
);
}
const existingGroup = result.get(senderId);
const existingGroup = result.get(sender.id);
if (existingGroup) {
existingGroup.push(receipt);
} else {
result.set(senderId, [receipt]);
result.set(sender.id, [receipt]);
}
return result;