Always update unreadCount for conversations

This commit is contained in:
Josh Perez 2021-05-17 12:52:09 -04:00 committed by Scott Nonnenberg
parent 794d910d4e
commit 215d90fbe8
3 changed files with 29 additions and 19 deletions

View file

@ -4053,21 +4053,17 @@ export class ConversationModel extends window.Backbone
sendReadReceipts: true, sendReadReceipts: true,
} }
): Promise<void> { ): Promise<void> {
const markedUnread = await markConversationRead( await markConversationRead(this.attributes, newestUnreadId, options);
this.attributes,
newestUnreadId,
options
);
if (!markedUnread) {
return;
}
const unreadCount = await window.Signal.Data.getUnreadCountForConversation( const unreadCount = await window.Signal.Data.getUnreadCountForConversation(
this.id this.id
); );
this.set({ unreadCount });
window.Signal.Data.updateConversation(this.attributes); const prevUnreadCount = this.get('unreadCount');
if (prevUnreadCount !== unreadCount) {
this.set({ unreadCount });
window.Signal.Data.updateConversation(this.attributes);
}
} }
// This is an expensive operation we use to populate the message request hero row. It // This is an expensive operation we use to populate the message request hero row. It

View file

@ -3215,7 +3215,8 @@ async function getUnreadCountForConversation(
` `
SELECT COUNT(*) AS unreadCount FROM messages SELECT COUNT(*) AS unreadCount FROM messages
WHERE unread = 1 AND WHERE unread = 1 AND
conversationId = $conversationId conversationId = $conversationId AND
type = 'incoming';
` `
) )
.get({ .get({
@ -3346,12 +3347,17 @@ async function getUnreadReactionsAndMarkRead(
newestUnreadId, newestUnreadId,
}); });
db.exec(` db.prepare(
`
UPDATE reactions SET UPDATE reactions SET
unread = 0 WHERE unread = 0 WHERE
$conversationId = conversationId AND conversationId = $conversationId AND
$messageReceivedAt <= messageReceivedAt; messageReceivedAt <= $newestUnreadId;
`); `
).run({
conversationId,
newestUnreadId,
});
return unreadMessages; return unreadMessages;
})(); })();
@ -3385,8 +3391,8 @@ async function markReactionAsRead(
` `
UPDATE reactions SET UPDATE reactions SET
unread = 0 WHERE unread = 0 WHERE
$targetAuthorUuid = targetAuthorUuid AND targetAuthorUuid = $targetAuthorUuid AND
$targetTimestamp = targetTimestamp; targetTimestamp = $targetTimestamp;
` `
).run({ ).run({
targetAuthorUuid, targetAuthorUuid,

View file

@ -13,7 +13,6 @@ export async function markConversationRead(
} }
): Promise<boolean> { ): Promise<boolean> {
const { id: conversationId } = conversationAttrs; const { id: conversationId } = conversationAttrs;
window.Whisper.Notifications.removeBy({ conversationId });
const [unreadMessages, unreadReactions] = await Promise.all([ const [unreadMessages, unreadReactions] = await Promise.all([
window.Signal.Data.getUnreadByConversationAndMarkRead( window.Signal.Data.getUnreadByConversationAndMarkRead(
@ -27,10 +26,19 @@ export async function markConversationRead(
), ),
]); ]);
window.log.info('markConversationRead', {
conversationId,
newestUnreadId,
unreadMessages: unreadMessages.length,
unreadReactions: unreadReactions.length,
});
if (!unreadMessages.length && !unreadReactions.length) { if (!unreadMessages.length && !unreadReactions.length) {
return false; return false;
} }
window.Whisper.Notifications.removeBy({ conversationId });
const unreadReactionSyncData = new Map< const unreadReactionSyncData = new Map<
string, string,
{ {