2022-11-08 21:38:19 -05:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-03-08 20:40:26 -05:00
|
|
|
import * as log from '../logging/log';
|
2024-07-22 11:16:33 -07:00
|
|
|
import { DataWriter } from '../sql/Client';
|
2025-01-10 08:18:32 +10:00
|
|
|
import { getMessageById } from '../messages/getMessageById';
|
2022-11-08 21:38:19 -05:00
|
|
|
import { isNotNil } from './isNotNil';
|
2022-11-16 12:18:02 -08:00
|
|
|
import { DurationInSeconds } from './durations';
|
2022-11-08 21:38:19 -05:00
|
|
|
import { markViewed } from '../services/MessageUpdater';
|
|
|
|
import { storageServiceUploadJob } from '../services/storage';
|
2025-01-10 08:18:32 +10:00
|
|
|
import { postSaveUpdates } from './cleanup';
|
2022-11-08 21:38:19 -05:00
|
|
|
|
2023-04-18 08:35:29 -07:00
|
|
|
export async function markOnboardingStoryAsRead(): Promise<boolean> {
|
2022-11-08 21:38:19 -05:00
|
|
|
const existingOnboardingStoryMessageIds = window.storage.get(
|
|
|
|
'existingOnboardingStoryMessageIds'
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!existingOnboardingStoryMessageIds) {
|
2023-03-08 20:40:26 -05:00
|
|
|
log.warn('markOnboardingStoryAsRead: no existing messages');
|
2023-04-18 08:35:29 -07:00
|
|
|
return false;
|
2022-11-08 21:38:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const messages = await Promise.all(
|
2025-01-10 08:18:32 +10:00
|
|
|
existingOnboardingStoryMessageIds.map(id => getMessageById(id))
|
2022-11-08 21:38:19 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
const storyReadDate = Date.now();
|
|
|
|
|
|
|
|
const messageAttributes = messages
|
|
|
|
.map(message => {
|
|
|
|
if (!message) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
message.set({
|
2022-11-16 12:18:02 -08:00
|
|
|
expireTimer: DurationInSeconds.DAY,
|
2022-11-08 21:38:19 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
message.set(markViewed(message.attributes, storyReadDate));
|
|
|
|
|
|
|
|
return message.attributes;
|
|
|
|
})
|
|
|
|
.filter(isNotNil);
|
|
|
|
|
2023-04-18 08:35:29 -07:00
|
|
|
log.info(
|
|
|
|
`markOnboardingStoryAsRead: marked ${messageAttributes.length} viewed`
|
|
|
|
);
|
2023-03-08 20:40:26 -05:00
|
|
|
|
2024-07-22 11:16:33 -07:00
|
|
|
await DataWriter.saveMessages(messageAttributes, {
|
2023-08-10 18:43:33 +02:00
|
|
|
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
2025-01-10 08:18:32 +10:00
|
|
|
postSaveUpdates,
|
2022-11-08 21:38:19 -05:00
|
|
|
});
|
|
|
|
|
2022-12-21 10:41:48 -08:00
|
|
|
await window.storage.put('hasViewedOnboardingStory', true);
|
2022-11-08 21:38:19 -05:00
|
|
|
|
2024-10-01 08:23:32 +10:00
|
|
|
storageServiceUploadJob({ reason: 'markOnboardingStoryAsRead' });
|
2023-04-18 08:35:29 -07:00
|
|
|
|
|
|
|
return true;
|
2022-11-08 21:38:19 -05:00
|
|
|
}
|