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