Introduce versioning clock to timer system

This commit is contained in:
Fedor Indutny 2024-08-21 09:03:28 -07:00 committed by GitHub
parent bb1d957e49
commit 2fb50df0af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 703 additions and 28 deletions

View file

@ -68,7 +68,7 @@ describe('pnp/merge', function (this: Mocha.Suite) {
serviceE164: undefined,
identityKey: aciIdentityKey,
givenName: pniContact.profileName,
givenName: 'ACI Contact',
});
// Put both contacts in left pane
@ -454,4 +454,88 @@ describe('pnp/merge', function (this: Mocha.Suite) {
assert.strictEqual(await messages.count(), 0, 'message count');
}
});
it('preserves expireTimerVersion after merge', async () => {
const { phone, desktop } = bootstrap;
for (const key of ['aci' as const, 'pni' as const]) {
debug(`Send a ${key} sync message`);
const timestamp = bootstrap.getTimestamp();
const destinationServiceId = pniContact.device[key];
const destination = key === 'pni' ? pniContact.device.number : undefined;
const content = {
syncMessage: {
sent: {
destinationServiceId,
destination,
timestamp: Long.fromNumber(timestamp),
message: {
timestamp: Long.fromNumber(timestamp),
flags: Proto.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
expireTimer: key === 'pni' ? 90 * 24 * 3600 : 60 * 24 * 3600,
expireTimerVersion: key === 'pni' ? 3 : 4,
},
unidentifiedStatus: [
{
destinationServiceId,
destination,
},
],
},
},
};
const sendOptions = {
timestamp,
};
// eslint-disable-next-line no-await-in-loop
await phone.sendRaw(desktop, content, sendOptions);
}
debug(
'removing both contacts from storage service, adding one combined contact'
);
{
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(),
pniSignatureVerified: true,
})
);
await phone.sendFetchStorage({
timestamp: bootstrap.getTimestamp(),
});
await app.waitForManifestVersion(state.version);
}
const window = await app.getWindow();
const leftPane = window.locator('#LeftPane');
debug('opening conversation with the merged contact');
await leftPane
.locator(
`[data-testid="${pniContact.device.aci}"] >> ` +
`"${pniContact.profileName}"`
)
.click();
await window.locator('.module-conversation-hero').waitFor();
debug('Send message to merged contact');
{
const compositionInput = await app.waitForEnabledComposer();
await typeIntoInput(compositionInput, 'Hello merged');
await compositionInput.press('Enter');
}
debug('Getting message to merged contact');
const { body, dataMessage } = await pniContact.waitForMessage();
assert.strictEqual(body, 'Hello merged');
assert.strictEqual(dataMessage.expireTimer, 60 * 24 * 3600);
assert.strictEqual(dataMessage.expireTimerVersion, 4);
});
});