2022-11-09 02:38:19 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import * as log from '../logging/log';
|
|
|
|
import { calculateExpirationTimestamp } from './expirationTimer';
|
2023-01-10 01:44:20 +00:00
|
|
|
import { DAY } from './durations';
|
2024-06-17 19:24:39 +00:00
|
|
|
import { singleProtoJobQueue } from '../jobs/singleProtoJobQueue';
|
2022-11-09 02:38:19 +00:00
|
|
|
|
|
|
|
export async function findAndDeleteOnboardingStoryIfExists(): Promise<void> {
|
|
|
|
const existingOnboardingStoryMessageIds = window.storage.get(
|
|
|
|
'existingOnboardingStoryMessageIds'
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!existingOnboardingStoryMessageIds) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const hasExpired = await (async () => {
|
2023-10-04 00:12:57 +00:00
|
|
|
const [storyId] = existingOnboardingStoryMessageIds;
|
|
|
|
try {
|
|
|
|
const messageAttributes = await window.MessageCache.resolveAttributes(
|
|
|
|
'findAndDeleteOnboardingStoryIfExists',
|
|
|
|
storyId
|
|
|
|
);
|
2022-11-09 02:38:19 +00:00
|
|
|
|
2023-10-04 00:12:57 +00:00
|
|
|
const expires = calculateExpirationTimestamp(messageAttributes) ?? 0;
|
2022-11-09 02:38:19 +00:00
|
|
|
|
2023-01-10 01:44:20 +00:00
|
|
|
const now = Date.now();
|
|
|
|
const isExpired = expires < now;
|
|
|
|
const needsRepair = expires > now + 2 * DAY;
|
|
|
|
|
|
|
|
return isExpired || needsRepair;
|
2023-10-04 00:12:57 +00:00
|
|
|
} catch {
|
|
|
|
return true;
|
2022-11-09 02:38:19 +00:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
if (!hasExpired) {
|
|
|
|
log.info(
|
|
|
|
'findAndDeleteOnboardingStoryIfExists: current msg has not expired'
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
log.info('findAndDeleteOnboardingStoryIfExists: removing onboarding stories');
|
|
|
|
|
2024-06-17 19:24:39 +00:00
|
|
|
await window.Signal.Data.removeMessages(existingOnboardingStoryMessageIds, {
|
|
|
|
singleProtoJobQueue,
|
|
|
|
});
|
2022-11-09 02:38:19 +00:00
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
await window.storage.put('existingOnboardingStoryMessageIds', undefined);
|
2022-12-05 17:34:26 +00:00
|
|
|
|
|
|
|
const signalConversation =
|
|
|
|
await window.ConversationController.getOrCreateSignalConversation();
|
|
|
|
|
|
|
|
existingOnboardingStoryMessageIds.forEach(messageId =>
|
|
|
|
window.reduxActions.conversations.messageDeleted(
|
|
|
|
messageId,
|
|
|
|
signalConversation.id
|
|
|
|
)
|
|
|
|
);
|
2022-11-09 02:38:19 +00:00
|
|
|
}
|