Replace MessageController with MessageCache

This commit is contained in:
Josh Perez 2023-10-03 20:12:57 -04:00 committed by GitHub
parent ba1a8aad09
commit 7d35216fda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
73 changed files with 2237 additions and 1229 deletions

View file

@ -2,7 +2,6 @@
// SPDX-License-Identifier: AGPL-3.0-only
import * as log from '../logging/log';
import { getMessageById } from '../messages/getMessageById';
import { calculateExpirationTimestamp } from './expirationTimer';
import { DAY } from './durations';
@ -16,23 +15,23 @@ export async function findAndDeleteOnboardingStoryIfExists(): Promise<void> {
}
const hasExpired = await (async () => {
for (const id of existingOnboardingStoryMessageIds) {
// eslint-disable-next-line no-await-in-loop
const message = await getMessageById(id);
if (!message) {
continue;
}
const [storyId] = existingOnboardingStoryMessageIds;
try {
const messageAttributes = await window.MessageCache.resolveAttributes(
'findAndDeleteOnboardingStoryIfExists',
storyId
);
const expires = calculateExpirationTimestamp(message.attributes) ?? 0;
const expires = calculateExpirationTimestamp(messageAttributes) ?? 0;
const now = Date.now();
const isExpired = expires < now;
const needsRepair = expires > now + 2 * DAY;
return isExpired || needsRepair;
} catch {
return true;
}
return true;
})();
if (!hasExpired) {