Send/Receive support for reaction read syncs

This commit is contained in:
Josh Perez 2021-05-06 18:15:25 -07:00 committed by GitHub
parent 82a9705010
commit e0c324e4ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 1188 additions and 498 deletions

View file

@ -97,6 +97,7 @@
});
if (message.isExpiring() && !expirationStartTimestamp) {
// TODO DESKTOP-1509: use setToExpire once this is TS
await message.setToExpire(false, { skipSave: true });
}

View file

@ -67,7 +67,7 @@
function getById(id) {
const existing = messageLookup[id];
return existing && existing.message ? existing.message : null;
return existing && existing.message ? existing.message : undefined;
}
function findBySentAt(sentAt) {

View file

@ -60,8 +60,14 @@
// Remove the last notification if both conditions hold:
//
// 1. Either `conversationId` or `messageId` matches (if present)
// 2. `reactionFromId` matches (if present)
removeBy({ conversationId, messageId, reactionFromId }) {
// 2. `emoji`, `targetAuthorUuid`, `targetTimestamp` matches (if present)
removeBy({
conversationId,
messageId,
emoji,
targetAuthorUuid,
targetTimestamp,
}) {
if (!this.notificationData) {
return;
}
@ -81,10 +87,15 @@
return;
}
const { reaction } = this.notificationData;
if (
reactionFromId &&
this.notificationData.reaction &&
this.notificationData.reaction.fromId !== reactionFromId
reaction &&
emoji &&
targetAuthorUuid &&
targetTimestamp &&
(reaction.emoji !== emoji ||
reaction.targetAuthorUuid !== targetAuthorUuid ||
reaction.targetTimestamp !== targetTimestamp)
) {
return;
}

View file

@ -98,6 +98,7 @@
});
if (message.isExpiring() && !expirationStartTimestamp) {
// TODO DESKTOP-1509: use setToExpire once this is TS
await message.setToExpire(false, { skipSave: true });
}

View file

@ -11,6 +11,30 @@
// eslint-disable-next-line func-names
(function () {
async function maybeItIsAReactionReadSync(receipt) {
const readReaction = await window.Signal.Data.markReactionAsRead(
receipt.get('senderUuid'),
Number(receipt.get('timestamp'))
);
if (!readReaction) {
window.log.info(
'Nothing found for read sync',
receipt.get('senderId'),
receipt.get('sender'),
receipt.get('senderUuid'),
receipt.get('timestamp')
);
}
Whisper.Notifications.removeBy({
conversationId: readReaction.conversationId,
emoji: readReaction.emoji,
targetAuthorUuid: readReaction.targetAuthorUuid,
targetTimestamp: readReaction.targetTimestamp,
});
}
window.Whisper = window.Whisper || {};
Whisper.ReadSyncs = new (Backbone.Collection.extend({
forMessage(message) {
@ -47,19 +71,14 @@
return item.isIncoming() && senderId === receipt.get('senderId');
});
if (found) {
Whisper.Notifications.removeBy({ messageId: found.id });
} else {
window.log.info(
'No message for read sync',
receipt.get('senderId'),
receipt.get('sender'),
receipt.get('senderUuid'),
receipt.get('timestamp')
);
if (!found) {
await maybeItIsAReactionReadSync(receipt);
return;
}
Whisper.Notifications.removeBy({ messageId: found.id });
const message = MessageController.register(found.id, found);
const readAt = receipt.get('read_at');
@ -67,7 +86,8 @@
// timer to the time specified by the read sync if it's earlier than
// the previous read time.
if (message.isUnread()) {
await message.markRead(readAt, { skipSave: true });
// TODO DESKTOP-1509: use MessageUpdater.markRead once this is TS
message.markRead(readAt, { skipSave: true });
const updateConversation = () => {
// onReadMessage may result in messages older than this one being
@ -100,6 +120,7 @@
message.set({ expirationStartTimestamp });
const force = true;
// TODO DESKTOP-1509: use setToExpire once this is TS
await message.setToExpire(force, { skipSave: true });
const conversation = message.getConversation();