Reload conversation messages on merge

This commit is contained in:
Fedor Indutny 2023-01-10 10:57:39 -08:00 committed by GitHub
parent 801dea2969
commit f8978328a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 118 additions and 63 deletions

View file

@ -1120,13 +1120,19 @@ export class ConversationController {
this._conversations.resetLookups(); this._conversations.resetLookups();
current.captureChange('combineConversations'); current.captureChange('combineConversations');
void current.updateLastMessage(); drop(current.updateLastMessage());
const state = window.reduxStore.getState();
if (state.conversations.selectedConversationId === current.id) {
// TODO: DESKTOP-4807
drop(current.loadNewestMessages(undefined, undefined));
}
const titleIsUseful = Boolean( const titleIsUseful = Boolean(
obsoleteTitleInfo && getTitleNoDefault(obsoleteTitleInfo) obsoleteTitleInfo && getTitleNoDefault(obsoleteTitleInfo)
); );
if (!fromPniSignature && obsoleteTitleInfo && titleIsUseful) { if (!fromPniSignature && obsoleteTitleInfo && titleIsUseful) {
void current.addConversationMerge(obsoleteTitleInfo); drop(current.addConversationMerge(obsoleteTitleInfo));
} }
log.warn(`${logId}: Complete!`); log.warn(`${logId}: Complete!`);

View file

@ -99,81 +99,130 @@ describe('pnp/merge', function needsName() {
await bootstrap.teardown(); await bootstrap.teardown();
}); });
it('happens via storage service, with notification', async () => { for (const finalContact of [UUIDKind.ACI, UUIDKind.PNI]) {
const { phone } = bootstrap; // eslint-disable-next-line no-loop-func
it(`happens via storage service, with notification (${finalContact})`, async () => {
const { phone } = bootstrap;
const window = await app.getWindow(); const window = await app.getWindow();
debug('opening conversation with the pni contact');
{
const leftPane = window.locator('.left-pane-wrapper'); const leftPane = window.locator('.left-pane-wrapper');
debug('opening conversation with the aci contact');
await leftPane
.locator('_react=ConversationListItem[title = "ACI Contact"]')
.click();
await window.locator('.module-conversation-hero').waitFor();
debug('Send message to ACI');
{
const composeArea = window.locator(
'.composition-area-wrapper, .conversation .ConversationView'
);
const compositionInput = composeArea.locator('_react=CompositionInput');
await compositionInput.type('Hello ACI');
await compositionInput.press('Enter');
}
debug('opening conversation with the pni contact');
await leftPane await leftPane
.locator('_react=ConversationListItem[title = "PNI Contact"]') .locator('_react=ConversationListItem[title = "PNI Contact"]')
.click(); .click();
await window.locator('.module-conversation-hero').waitFor(); await window.locator('.module-conversation-hero').waitFor();
}
debug('Verify starting state'); debug('Verify starting state');
{ {
// No messages // No messages
const messages = window.locator('.module-message__text'); const messages = window.locator('.module-message__text');
assert.strictEqual(await messages.count(), 0, 'message count'); assert.strictEqual(await messages.count(), 0, 'message count');
// No notifications // No notifications
const notifications = window.locator('.SystemMessage'); const notifications = window.locator('.SystemMessage');
assert.strictEqual(await notifications.count(), 0, 'notification count'); assert.strictEqual(
} await notifications.count(),
0,
'notification count'
);
}
debug( debug('Send message to PNI');
'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('_react=CompositionInput');
state
.removeRecord( await compositionInput.type('Hello PNI');
item => await compositionInput.press('Enter');
item.record.contact?.serviceUuid === }
pniContact.device.getUUIDByKind(UUIDKind.ACI)
) if (finalContact === UUIDKind.ACI) {
.removeRecord( debug('switching back to ACI conversation');
item => await leftPane
item.record.contact?.serviceUuid === .locator('_react=ConversationListItem[title = "ACI Contact"]')
pniContact.device.getUUIDByKind(UUIDKind.PNI) .click();
)
.addContact(pniContact, { await window.locator('.module-conversation-hero').waitFor();
identityState: Proto.ContactRecord.IdentityState.DEFAULT, }
whitelisted: true,
pni: pniContact.device.getUUIDByKind(UUIDKind.PNI), debug(
identityKey: pniContact.publicKey.serialize(), 'removing both contacts from storage service, adding one combined contact'
profileKey: pniContact.profileKey.serialize(),
})
); );
await phone.sendFetchStorage({ {
timestamp: bootstrap.getTimestamp(), const state = await phone.expectStorageState('consistency check');
}); await phone.setStorageState(
} state
.removeRecord(
item =>
item.record.contact?.serviceUuid ===
pniContact.device.getUUIDByKind(UUIDKind.ACI)
)
.removeRecord(
item =>
item.record.contact?.serviceUuid ===
pniContact.device.getUUIDByKind(UUIDKind.PNI)
)
.addContact(pniContact, {
identityState: Proto.ContactRecord.IdentityState.DEFAULT,
whitelisted: true,
pni: pniContact.device.getUUIDByKind(UUIDKind.PNI),
identityKey: pniContact.publicKey.serialize(),
profileKey: pniContact.profileKey.serialize(),
})
);
await phone.sendFetchStorage({
timestamp: bootstrap.getTimestamp(),
});
}
// wait for desktop to process these changes // wait for desktop to process these changes
await window.locator('.SystemMessage').waitFor(); await window.locator('.SystemMessage').waitFor();
debug('Verify final state'); debug('Verify final state');
{ {
// No messages // Should have both PNI and ACI messages
const messages = window.locator('.module-message__text'); await window.locator('.module-message__text >> "Hello ACI"').waitFor();
assert.strictEqual(await messages.count(), 0, 'message count'); await window.locator('.module-message__text >> "Hello PNI"').waitFor();
// One notification - the merge const messages = window.locator('.module-message__text');
const notifications = window.locator('.SystemMessage'); assert.strictEqual(await messages.count(), 2, 'message count');
assert.strictEqual(await notifications.count(), 1, 'notification count');
const first = await notifications.first(); // One notification - the merge
assert.match( const notifications = window.locator('.SystemMessage');
await first.innerText(), assert.strictEqual(
/and ACI Contact are the same account. Your message history for both chats are here./ await notifications.count(),
); 1,
} 'notification count'
}); );
const first = await notifications.first();
assert.match(
await first.innerText(),
/and ACI Contact are the same account. Your message history for both chats are here./
);
}
});
}
}); });