32 lines
794 B
TypeScript
32 lines
794 B
TypeScript
// 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;
|
|
}
|