Show Session Switchover Events

Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
Fedor Indutny 2023-10-23 19:40:42 +02:00 committed by GitHub
parent 70cd073a72
commit dd2493a353
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 455 additions and 17 deletions

View file

@ -471,7 +471,7 @@ export class ConversationController {
e164,
pni: providedPni,
reason,
fromPniSignature,
fromPniSignature = false,
mergeOldAndNew = safeCombineConversations,
}: {
aci?: AciString;
@ -526,6 +526,12 @@ export class ConversationController {
let unusedMatches: Array<ConvoMatchType> = [];
let targetConversation: ConversationModel | undefined;
let targetOldServiceIds:
| {
aci?: AciString;
pni?: PniString;
}
| undefined;
let matchCount = 0;
matches.forEach(item => {
const { key, value, match } = item;
@ -597,6 +603,11 @@ export class ConversationController {
);
}
targetOldServiceIds = {
aci: targetConversation.getAci(),
pni: targetConversation.getPni(),
};
log.info(
`${logId}: Applying new value for ${unused.key} to target conversation`
);
@ -686,9 +697,32 @@ export class ConversationController {
// `${logId}: Match on ${key} is target conversation - ${match.idForLogging()}`
// );
targetConversation = match;
targetOldServiceIds = {
aci: targetConversation.getAci(),
pni: targetConversation.getPni(),
};
}
});
// If the change is not coming from PNI Signature, and target conversation
// had PNI and has acquired new ACI and/or PNI we should check if it had
// a PNI session on the original PNI. If yes - add a PhoneNumberDiscovery notification
if (
e164 &&
pni &&
targetConversation &&
targetOldServiceIds?.pni &&
!fromPniSignature &&
(targetOldServiceIds.pni !== pni ||
(aci && targetOldServiceIds.aci !== aci))
) {
mergePromises.push(
targetConversation.addPhoneNumberDiscoveryIfNeeded(
targetOldServiceIds.pni
)
);
}
if (targetConversation) {
return { conversation: targetConversation, mergePromises };
}