From 74374e4313c795a5dd811fd6eab387844e38aa91 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Wed, 17 Aug 2022 16:12:38 -0700 Subject: [PATCH] maybeMergeContacts/create: Put PNI into UUID field if no ACI --- ts/ConversationController.ts | 9 ++++-- .../ConversationController_test.ts | 29 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ts/ConversationController.ts b/ts/ConversationController.ts index e7a15b883fd6..f64ef6820c81 100644 --- a/ts/ConversationController.ts +++ b/ts/ConversationController.ts @@ -451,9 +451,6 @@ export class ConversationController { ); } - const identifier = aci || e164 || pni; - strictAssert(identifier, `${logId}: identifier must be truthy!`); - const matches: Array = [ { key: 'uuid', @@ -591,6 +588,12 @@ export class ConversationController { ); log.info(`${logId}: Creating a new conversation with all inputs`); + + // This is not our precedence for lookup, but it ensures that the PNI gets into the + // uuid slot if we have no ACI. + const identifier = aci || pni || e164; + strictAssert(identifier, `${logId}: identifier must be truthy!`); + return this.getOrCreate(identifier, 'private', { e164, pni }); } diff --git a/ts/test-electron/ConversationController_test.ts b/ts/test-electron/ConversationController_test.ts index 56818b2ae859..993d4af948e9 100644 --- a/ts/test-electron/ConversationController_test.ts +++ b/ts/test-electron/ConversationController_test.ts @@ -190,6 +190,35 @@ describe('ConversationController', () => { assert.strictEqual(result?.id, second?.id, 'result and second match'); }); + it('creates a new conversation with e164+PNI if no matches', () => { + const result = window.ConversationController.maybeMergeContacts({ + mergeOldAndNew, + e164: E164_1, + pni: PNI_1, + reason, + }); + + expectPropsAndLookups(result, 'result', { + aci: PNI_1, + e164: E164_1, + pni: PNI_1, + }); + + const second = window.ConversationController.maybeMergeContacts({ + mergeOldAndNew, + e164: E164_1, + pni: PNI_1, + reason, + }); + + expectPropsAndLookups(second, 'second', { + aci: PNI_1, + e164: E164_1, + pni: PNI_1, + }); + + assert.strictEqual(result?.id, second?.id, 'result and second match'); + }); it('creates a new conversation with all data if no matches', () => { const result = window.ConversationController.maybeMergeContacts({ mergeOldAndNew,