Send/Receive support for reaction read syncs
This commit is contained in:
parent
82a9705010
commit
e0c324e4ba
23 changed files with 1188 additions and 498 deletions
87
ts/services/MessageUpdater.ts
Normal file
87
ts/services/MessageUpdater.ts
Normal file
|
@ -0,0 +1,87 @@
|
|||
// 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 {
|
||||
const expireTimerMs = messageAttrs.expireTimer * 1000;
|
||||
return messageAttrs.expirationStartTimestamp
|
||||
? messageAttrs.expirationStartTimestamp + expireTimerMs
|
||||
: undefined;
|
||||
}
|
||||
|
||||
export function setToExpire(
|
||||
messageAttrs: MessageAttributesType,
|
||||
{ force = false, skipSave = false } = {}
|
||||
): MessageAttributesType {
|
||||
if (!isExpiring(messageAttrs) || (!force && messageAttrs.expires_at)) {
|
||||
return messageAttrs;
|
||||
}
|
||||
|
||||
const expiresAt = getExpiresAt(messageAttrs);
|
||||
|
||||
if (!expiresAt) {
|
||||
return messageAttrs;
|
||||
}
|
||||
|
||||
const nextMessageAttributes = {
|
||||
...messageAttrs,
|
||||
expires_at: expiresAt,
|
||||
};
|
||||
|
||||
window.log.info('Set message expiration', {
|
||||
start: messageAttrs.expirationStartTimestamp,
|
||||
expiresAt,
|
||||
sentAt: messageAttrs.sent_at,
|
||||
});
|
||||
|
||||
if (messageAttrs.id && !skipSave) {
|
||||
window.Signal.Util.queueUpdateMessage(nextMessageAttributes);
|
||||
}
|
||||
|
||||
return nextMessageAttributes;
|
||||
}
|
||||
|
||||
function isExpiring(
|
||||
messageAttrs: Pick<
|
||||
MessageAttributesType,
|
||||
'expireTimer' | 'expirationStartTimestamp'
|
||||
>
|
||||
): boolean {
|
||||
return Boolean(
|
||||
messageAttrs.expireTimer && messageAttrs.expirationStartTimestamp
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue