Handle PNI+PNI+E164 triple
This commit is contained in:
parent
9fe7bb41ec
commit
dd16be13b0
3 changed files with 167 additions and 113 deletions
|
@ -470,17 +470,20 @@ export class ConversationController {
|
||||||
} {
|
} {
|
||||||
const dataProvided = [];
|
const dataProvided = [];
|
||||||
if (providedAci) {
|
if (providedAci) {
|
||||||
dataProvided.push('aci');
|
dataProvided.push(`aci=${providedAci}`);
|
||||||
}
|
}
|
||||||
if (e164) {
|
if (e164) {
|
||||||
dataProvided.push('e164');
|
dataProvided.push(`e164=${e164}`);
|
||||||
}
|
}
|
||||||
if (providedPni) {
|
if (providedPni) {
|
||||||
dataProvided.push('pni');
|
dataProvided.push(`pni=${providedPni}`);
|
||||||
}
|
}
|
||||||
const logId = `maybeMergeContacts/${reason}/${dataProvided.join('+')}`;
|
const logId = `maybeMergeContacts/${reason}/${dataProvided.join(',')}`;
|
||||||
|
|
||||||
const aci = providedAci ? UUID.cast(providedAci) : undefined;
|
const aci =
|
||||||
|
providedAci && providedAci !== providedPni
|
||||||
|
? UUID.cast(providedAci)
|
||||||
|
: undefined;
|
||||||
const pni = providedPni ? UUID.cast(providedPni) : undefined;
|
const pni = providedPni ? UUID.cast(providedPni) : undefined;
|
||||||
const mergePromises: Array<Promise<void>> = [];
|
const mergePromises: Array<Promise<void>> = [];
|
||||||
|
|
||||||
|
@ -517,7 +520,8 @@ export class ConversationController {
|
||||||
if (!match) {
|
if (!match) {
|
||||||
if (targetConversation) {
|
if (targetConversation) {
|
||||||
log.info(
|
log.info(
|
||||||
`${logId}: No match for ${key}, applying to target conversation`
|
`${logId}: No match for ${key}, applying to target ` +
|
||||||
|
`conversation - ${targetConversation.idForLogging()}`
|
||||||
);
|
);
|
||||||
// Note: This line might erase a known e164 or PNI
|
// Note: This line might erase a known e164 or PNI
|
||||||
applyChangeToConversation(targetConversation, {
|
applyChangeToConversation(targetConversation, {
|
||||||
|
@ -609,7 +613,8 @@ export class ConversationController {
|
||||||
// Clear the value on the current match, since it belongs on targetConversation!
|
// Clear the value on the current match, since it belongs on targetConversation!
|
||||||
// Note: we need to do the remove first, because it will clear the lookup!
|
// Note: we need to do the remove first, because it will clear the lookup!
|
||||||
log.info(
|
log.info(
|
||||||
`${logId}: Clearing ${key} on match, and adding it to target conversation`
|
`${logId}: Clearing ${key} on match, and adding it to target ` +
|
||||||
|
`conversation - ${targetConversation.idForLogging()}`
|
||||||
);
|
);
|
||||||
const change: Pick<
|
const change: Pick<
|
||||||
Partial<ConversationAttributesType>,
|
Partial<ConversationAttributesType>,
|
||||||
|
@ -635,7 +640,7 @@ export class ConversationController {
|
||||||
if (willMerge) {
|
if (willMerge) {
|
||||||
log.warn(
|
log.warn(
|
||||||
`${logId}: Removing old conversation which matched on ${key}. ` +
|
`${logId}: Removing old conversation which matched on ${key}. ` +
|
||||||
'Merging with target conversation.'
|
`Merging with target conversation - ${targetConversation.idForLogging()}`
|
||||||
);
|
);
|
||||||
mergePromises.push(
|
mergePromises.push(
|
||||||
mergeOldAndNew({
|
mergeOldAndNew({
|
||||||
|
@ -649,7 +654,10 @@ export class ConversationController {
|
||||||
}
|
}
|
||||||
} else if (targetConversation && !targetConversation?.get(key)) {
|
} else if (targetConversation && !targetConversation?.get(key)) {
|
||||||
// This is mostly for the situation where PNI was erased when updating e164
|
// This is mostly for the situation where PNI was erased when updating e164
|
||||||
log.debug(`${logId}: Re-adding ${key} on target conversation`);
|
log.debug(
|
||||||
|
`${logId}: Re-adding ${key} on target conversation - ` +
|
||||||
|
`${targetConversation.idForLogging()}`
|
||||||
|
);
|
||||||
applyChangeToConversation(targetConversation, {
|
applyChangeToConversation(targetConversation, {
|
||||||
[key]: value,
|
[key]: value,
|
||||||
});
|
});
|
||||||
|
@ -1075,6 +1083,8 @@ export class ConversationController {
|
||||||
|
|
||||||
// Note: we explicitly don't want to update V2 groups
|
// Note: we explicitly don't want to update V2 groups
|
||||||
|
|
||||||
|
const obsoleteHadMessages = (obsolete.get('messageCount') ?? 0) > 0;
|
||||||
|
|
||||||
log.warn(`${logId}: Delete the obsolete conversation from the database`);
|
log.warn(`${logId}: Delete the obsolete conversation from the database`);
|
||||||
await removeConversation(obsoleteId);
|
await removeConversation(obsoleteId);
|
||||||
|
|
||||||
|
@ -1112,7 +1122,12 @@ export class ConversationController {
|
||||||
const titleIsUseful = Boolean(
|
const titleIsUseful = Boolean(
|
||||||
obsoleteTitleInfo && getTitleNoDefault(obsoleteTitleInfo)
|
obsoleteTitleInfo && getTitleNoDefault(obsoleteTitleInfo)
|
||||||
);
|
);
|
||||||
if (obsoleteTitleInfo && titleIsUseful && !fromPniSignature) {
|
if (
|
||||||
|
obsoleteTitleInfo &&
|
||||||
|
titleIsUseful &&
|
||||||
|
!fromPniSignature &&
|
||||||
|
obsoleteHadMessages
|
||||||
|
) {
|
||||||
drop(current.addConversationMerge(obsoleteTitleInfo));
|
drop(current.addConversationMerge(obsoleteTitleInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -571,6 +571,28 @@ describe('ConversationController', () => {
|
||||||
|
|
||||||
assert.strictEqual(result?.id, initial?.id, 'result and initial match');
|
assert.strictEqual(result?.id, initial?.id, 'result and initial match');
|
||||||
});
|
});
|
||||||
|
it('adds PNI to conversation with e164+ACI', () => {
|
||||||
|
const initial = create('initial', {
|
||||||
|
aci: ACI_1,
|
||||||
|
e164: E164_1,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { conversation: result } =
|
||||||
|
window.ConversationController.maybeMergeContacts({
|
||||||
|
mergeOldAndNew,
|
||||||
|
aci: PNI_1,
|
||||||
|
pni: PNI_1,
|
||||||
|
e164: E164_1,
|
||||||
|
reason,
|
||||||
|
});
|
||||||
|
expectPropsAndLookups(result, 'result', {
|
||||||
|
uuid: ACI_1,
|
||||||
|
e164: E164_1,
|
||||||
|
pni: PNI_1,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(result?.id, initial?.id, 'result and initial match');
|
||||||
|
});
|
||||||
it('replaces PNI in conversation with all data', () => {
|
it('replaces PNI in conversation with all data', () => {
|
||||||
const initial = create('initial', {
|
const initial = create('initial', {
|
||||||
aci: ACI_1,
|
aci: ACI_1,
|
||||||
|
|
|
@ -101,123 +101,140 @@ describe('pnp/merge', function needsName() {
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const finalContact of [UUIDKind.ACI, UUIDKind.PNI]) {
|
for (const finalContact of [UUIDKind.ACI, UUIDKind.PNI]) {
|
||||||
// eslint-disable-next-line no-loop-func
|
for (const withNotification of [false, true]) {
|
||||||
it(`happens via storage service, with notification (${finalContact})`, async () => {
|
const testName =
|
||||||
const { phone } = bootstrap;
|
'happens via storage service, ' +
|
||||||
|
`${withNotification ? 'with' : 'without'} notification ` +
|
||||||
|
`(${finalContact})`;
|
||||||
|
|
||||||
const window = await app.getWindow();
|
// eslint-disable-next-line no-loop-func
|
||||||
const leftPane = window.locator('.left-pane-wrapper');
|
it(testName, async () => {
|
||||||
|
const { phone } = bootstrap;
|
||||||
|
|
||||||
debug('opening conversation with the aci contact');
|
const window = await app.getWindow();
|
||||||
await leftPane
|
const leftPane = window.locator('.left-pane-wrapper');
|
||||||
.locator(`[data-testid="${pniContact.device.uuid}"]`)
|
|
||||||
.click();
|
|
||||||
|
|
||||||
await window.locator('.module-conversation-hero').waitFor();
|
debug('opening conversation with the aci contact');
|
||||||
|
|
||||||
debug('Send message to ACI');
|
|
||||||
{
|
|
||||||
const composeArea = window.locator(
|
|
||||||
'.composition-area-wrapper, .conversation .ConversationView'
|
|
||||||
);
|
|
||||||
const compositionInput = composeArea.locator(
|
|
||||||
'[data-testid=CompositionInput]'
|
|
||||||
);
|
|
||||||
|
|
||||||
await compositionInput.type('Hello ACI');
|
|
||||||
await compositionInput.press('Enter');
|
|
||||||
}
|
|
||||||
|
|
||||||
debug('opening conversation with the pni contact');
|
|
||||||
await leftPane
|
|
||||||
.locator('.module-conversation-list__item--contact-or-conversation')
|
|
||||||
.first()
|
|
||||||
.click();
|
|
||||||
|
|
||||||
await window.locator('.module-conversation-hero').waitFor();
|
|
||||||
|
|
||||||
debug('Verify starting state');
|
|
||||||
{
|
|
||||||
// No messages
|
|
||||||
const messages = window.locator('.module-message__text');
|
|
||||||
assert.strictEqual(await messages.count(), 0, 'message count');
|
|
||||||
|
|
||||||
// No notifications
|
|
||||||
const notifications = window.locator('.SystemMessage');
|
|
||||||
assert.strictEqual(
|
|
||||||
await notifications.count(),
|
|
||||||
0,
|
|
||||||
'notification count'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
debug('Send message to PNI');
|
|
||||||
{
|
|
||||||
const composeArea = window.locator(
|
|
||||||
'.composition-area-wrapper, .conversation .ConversationView'
|
|
||||||
);
|
|
||||||
const compositionInput = composeArea.locator(
|
|
||||||
'[data-testid=CompositionInput]'
|
|
||||||
);
|
|
||||||
|
|
||||||
await compositionInput.type('Hello PNI');
|
|
||||||
await compositionInput.press('Enter');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (finalContact === UUIDKind.ACI) {
|
|
||||||
debug('switching back to ACI conversation');
|
|
||||||
await leftPane
|
await leftPane
|
||||||
.locator(`[data-testid="${pniContact.device.uuid}"]`)
|
.locator(`[data-testid="${pniContact.device.uuid}"]`)
|
||||||
.click();
|
.click();
|
||||||
|
|
||||||
await window.locator('.module-conversation-hero').waitFor();
|
await window.locator('.module-conversation-hero').waitFor();
|
||||||
}
|
|
||||||
|
|
||||||
debug(
|
debug('Send message to ACI');
|
||||||
'removing both contacts from storage service, adding one combined contact'
|
{
|
||||||
);
|
const composeArea = window.locator(
|
||||||
{
|
'.composition-area-wrapper, .conversation .ConversationView'
|
||||||
const state = await phone.expectStorageState('consistency check');
|
);
|
||||||
await phone.setStorageState(
|
const compositionInput = composeArea.locator(
|
||||||
state.mergeContact(pniContact, {
|
'[data-testid=CompositionInput]'
|
||||||
identityState: Proto.ContactRecord.IdentityState.DEFAULT,
|
);
|
||||||
whitelisted: true,
|
|
||||||
identityKey: pniContact.publicKey.serialize(),
|
await compositionInput.type('Hello ACI');
|
||||||
profileKey: pniContact.profileKey.serialize(),
|
await compositionInput.press('Enter');
|
||||||
})
|
}
|
||||||
|
|
||||||
|
debug('opening conversation with the pni contact');
|
||||||
|
await leftPane
|
||||||
|
.locator('.module-conversation-list__item--contact-or-conversation')
|
||||||
|
.first()
|
||||||
|
.click();
|
||||||
|
|
||||||
|
await window.locator('.module-conversation-hero').waitFor();
|
||||||
|
|
||||||
|
debug('Verify starting state');
|
||||||
|
{
|
||||||
|
// No messages
|
||||||
|
const messages = window.locator('.module-message__text');
|
||||||
|
assert.strictEqual(await messages.count(), 0, 'message count');
|
||||||
|
|
||||||
|
// No notifications
|
||||||
|
const notifications = window.locator('.SystemMessage');
|
||||||
|
assert.strictEqual(
|
||||||
|
await notifications.count(),
|
||||||
|
0,
|
||||||
|
'notification count'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (withNotification) {
|
||||||
|
debug('Send message to PNI');
|
||||||
|
const composeArea = window.locator(
|
||||||
|
'.composition-area-wrapper, .conversation .ConversationView'
|
||||||
|
);
|
||||||
|
const compositionInput = composeArea.locator(
|
||||||
|
'[data-testid=CompositionInput]'
|
||||||
|
);
|
||||||
|
|
||||||
|
await compositionInput.type('Hello PNI');
|
||||||
|
await compositionInput.press('Enter');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (finalContact === UUIDKind.ACI) {
|
||||||
|
debug('switching back to ACI conversation');
|
||||||
|
await leftPane
|
||||||
|
.locator(`[data-testid="${pniContact.device.uuid}"]`)
|
||||||
|
.click();
|
||||||
|
|
||||||
|
await window.locator('.module-conversation-hero').waitFor();
|
||||||
|
}
|
||||||
|
|
||||||
|
debug(
|
||||||
|
'removing both contacts from storage service, adding one combined contact'
|
||||||
);
|
);
|
||||||
await phone.sendFetchStorage({
|
{
|
||||||
timestamp: bootstrap.getTimestamp(),
|
const state = await phone.expectStorageState('consistency check');
|
||||||
});
|
await phone.setStorageState(
|
||||||
}
|
state.mergeContact(pniContact, {
|
||||||
|
identityState: Proto.ContactRecord.IdentityState.DEFAULT,
|
||||||
|
whitelisted: true,
|
||||||
|
identityKey: pniContact.publicKey.serialize(),
|
||||||
|
profileKey: pniContact.profileKey.serialize(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
await phone.sendFetchStorage({
|
||||||
|
timestamp: bootstrap.getTimestamp(),
|
||||||
|
});
|
||||||
|
await app.waitForManifestVersion(state.version);
|
||||||
|
}
|
||||||
|
|
||||||
// wait for desktop to process these changes
|
debug('Verify final state');
|
||||||
await window.locator('.SystemMessage').waitFor();
|
{
|
||||||
|
// Should have both PNI and ACI messages
|
||||||
|
await window
|
||||||
|
.locator('.module-message__text >> "Hello ACI"')
|
||||||
|
.waitFor();
|
||||||
|
if (withNotification) {
|
||||||
|
await window
|
||||||
|
.locator('.module-message__text >> "Hello PNI"')
|
||||||
|
.waitFor();
|
||||||
|
}
|
||||||
|
|
||||||
debug('Verify final state');
|
const messages = window.locator('.module-message__text');
|
||||||
{
|
assert.strictEqual(
|
||||||
// Should have both PNI and ACI messages
|
await messages.count(),
|
||||||
await window.locator('.module-message__text >> "Hello ACI"').waitFor();
|
withNotification ? 2 : 1,
|
||||||
await window.locator('.module-message__text >> "Hello PNI"').waitFor();
|
'message count'
|
||||||
|
);
|
||||||
|
|
||||||
const messages = window.locator('.module-message__text');
|
// One notification - the merge
|
||||||
assert.strictEqual(await messages.count(), 2, 'message count');
|
const notifications = window.locator('.SystemMessage');
|
||||||
|
assert.strictEqual(
|
||||||
|
await notifications.count(),
|
||||||
|
withNotification ? 1 : 0,
|
||||||
|
'notification count'
|
||||||
|
);
|
||||||
|
|
||||||
// One notification - the merge
|
if (withNotification) {
|
||||||
const notifications = window.locator('.SystemMessage');
|
const first = await notifications.first();
|
||||||
assert.strictEqual(
|
assert.match(
|
||||||
await notifications.count(),
|
await first.innerText(),
|
||||||
1,
|
/Your message history with ACI Contact and their number .* has been merged./
|
||||||
'notification count'
|
);
|
||||||
);
|
}
|
||||||
|
}
|
||||||
const first = await notifications.first();
|
});
|
||||||
assert.match(
|
}
|
||||||
await first.innerText(),
|
|
||||||
/Your message history with ACI Contact and their number .* has been merged./
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
it('accepts storage service contact splitting', async () => {
|
it('accepts storage service contact splitting', async () => {
|
||||||
|
|
Loading…
Reference in a new issue