2021-05-07 01:15:25 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { MessageAttributesType } from '../model-types.d';
|
|
|
|
|
|
|
|
export function markRead(
|
|
|
|
messageAttrs: MessageAttributesType,
|
|
|
|
readAt?: number,
|
|
|
|
{ skipSave = false } = {}
|
|
|
|
): MessageAttributesType {
|
|
|
|
const nextMessageAttributes = {
|
|
|
|
...messageAttrs,
|
|
|
|
unread: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
const { id: messageId, expireTimer, expirationStartTimestamp } = messageAttrs;
|
|
|
|
|
|
|
|
if (expireTimer && !expirationStartTimestamp) {
|
|
|
|
nextMessageAttributes.expirationStartTimestamp = Math.min(
|
|
|
|
Date.now(),
|
|
|
|
readAt || Date.now()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
window.Whisper.Notifications.removeBy({ messageId });
|
|
|
|
|
|
|
|
if (!skipSave) {
|
|
|
|
window.Signal.Util.queueUpdateMessage(nextMessageAttributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nextMessageAttributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getExpiresAt(
|
|
|
|
messageAttrs: Pick<
|
|
|
|
MessageAttributesType,
|
|
|
|
'expireTimer' | 'expirationStartTimestamp'
|
|
|
|
>
|
|
|
|
): number | undefined {
|
2021-06-17 17:15:10 +00:00
|
|
|
const { expireTimer, expirationStartTimestamp } = messageAttrs;
|
|
|
|
return expirationStartTimestamp && expireTimer
|
|
|
|
? expirationStartTimestamp + expireTimer * 1000
|
2021-05-07 01:15:25 +00:00
|
|
|
: undefined;
|
|
|
|
}
|