Get the correct unread count for a conversation

This commit is contained in:
Josh Perez 2021-05-10 14:49:13 -04:00 committed by GitHub
parent c68d65ea0b
commit 887b2c1db1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 14 deletions

View file

@ -11,7 +11,7 @@ export async function markConversationRead(
options: { readAt?: number; sendReadReceipts: boolean } = {
sendReadReceipts: true,
}
): Promise<number> {
): Promise<boolean> {
const { id: conversationId } = conversationAttrs;
window.Whisper.Notifications.removeBy({ conversationId });
@ -27,6 +27,10 @@ export async function markConversationRead(
),
]);
if (!unreadMessages.length && !unreadReactions.length) {
return false;
}
const unreadReactionSyncData = new Map<
string,
{
@ -67,22 +71,13 @@ export async function markConversationRead(
});
// Some messages we're marking read are local notifications with no sender
const messagesWithSenderId = allReadMessagesSync.filter(syncMessage =>
Boolean(syncMessage.senderId)
);
const incomingUnreadMessages = unreadMessages.filter(
message => message.type === 'incoming'
);
const unreadCount =
incomingUnreadMessages.length - messagesWithSenderId.length;
// If a message has errors, we don't want to send anything out about it.
// read syncs - let's wait for a client that really understands the message
// to mark it read. we'll mark our local error read locally, though.
// read receipts - here we can run into infinite loops, where each time the
// conversation is viewed, another error message shows up for the contact
const unreadMessagesSyncData = messagesWithSenderId.filter(
item => !item.hasErrors
const unreadMessagesSyncData = allReadMessagesSync.filter(
item => Boolean(item.senderId) && !item.hasErrors
);
const readSyncs = [
@ -107,5 +102,5 @@ export async function markConversationRead(
await sendReadReceiptsFor(conversationAttrs, unreadMessagesSyncData);
}
return unreadCount;
return true;
}