Improve handling of expireTimerVersion glare

This commit is contained in:
trevor-signal 2024-11-18 16:28:29 -05:00 committed by GitHub
parent b8ae50efd6
commit 512dcaad45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4679,32 +4679,37 @@ export class ConversationModel extends window.Backbone
expireTimer = undefined;
}
const timerMatchesLocalValue =
this.get('expireTimer') === expireTimer ||
(!expireTimer && !this.get('expireTimer'));
const localVersion = this.getExpireTimerVersion();
const logId =
`updateExpirationTimer(${this.idForLogging()}, ` +
`${expireTimer || 'disabled'}, version=${version || 0}) ` +
`source=${source ?? '?'} reason=${reason}`;
`source=${source ?? '?'} localValue=${this.get('expireTimer')} ` +
`localVersion=${localVersion}, reason=${reason}`;
if (isSetByOther) {
const expireTimerVersion = this.getExpireTimerVersion();
if (version) {
if (expireTimerVersion && version < expireTimerVersion) {
log.warn(
`${logId}: not updating, local version is ${expireTimerVersion}`
);
if (localVersion && version < localVersion) {
log.warn(`${logId}: not updating, local version is ${localVersion}`);
return;
}
if (version === expireTimerVersion) {
log.warn(`${logId}: expire version glare`);
if (version === localVersion) {
if (!timerMatchesLocalValue) {
log.warn(`${logId}: expire version glare`);
}
} else {
this.set({ expireTimerVersion: version });
log.info(`${logId}: updating expire version`);
}
}
}
if (
this.get('expireTimer') === expireTimer ||
(!expireTimer && !this.get('expireTimer'))
) {
if (timerMatchesLocalValue) {
return;
}