Always update unreadCount for conversations
This commit is contained in:
parent
794d910d4e
commit
215d90fbe8
3 changed files with 29 additions and 19 deletions
|
@ -4053,21 +4053,17 @@ export class ConversationModel extends window.Backbone
|
|||
sendReadReceipts: true,
|
||||
}
|
||||
): Promise<void> {
|
||||
const markedUnread = await markConversationRead(
|
||||
this.attributes,
|
||||
newestUnreadId,
|
||||
options
|
||||
);
|
||||
|
||||
if (!markedUnread) {
|
||||
return;
|
||||
}
|
||||
await markConversationRead(this.attributes, newestUnreadId, options);
|
||||
|
||||
const unreadCount = await window.Signal.Data.getUnreadCountForConversation(
|
||||
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
|
||||
|
|
|
@ -3215,7 +3215,8 @@ async function getUnreadCountForConversation(
|
|||
`
|
||||
SELECT COUNT(*) AS unreadCount FROM messages
|
||||
WHERE unread = 1 AND
|
||||
conversationId = $conversationId
|
||||
conversationId = $conversationId AND
|
||||
type = 'incoming';
|
||||
`
|
||||
)
|
||||
.get({
|
||||
|
@ -3346,12 +3347,17 @@ async function getUnreadReactionsAndMarkRead(
|
|||
newestUnreadId,
|
||||
});
|
||||
|
||||
db.exec(`
|
||||
db.prepare(
|
||||
`
|
||||
UPDATE reactions SET
|
||||
unread = 0 WHERE
|
||||
$conversationId = conversationId AND
|
||||
$messageReceivedAt <= messageReceivedAt;
|
||||
`);
|
||||
conversationId = $conversationId AND
|
||||
messageReceivedAt <= $newestUnreadId;
|
||||
`
|
||||
).run({
|
||||
conversationId,
|
||||
newestUnreadId,
|
||||
});
|
||||
|
||||
return unreadMessages;
|
||||
})();
|
||||
|
@ -3385,8 +3391,8 @@ async function markReactionAsRead(
|
|||
`
|
||||
UPDATE reactions SET
|
||||
unread = 0 WHERE
|
||||
$targetAuthorUuid = targetAuthorUuid AND
|
||||
$targetTimestamp = targetTimestamp;
|
||||
targetAuthorUuid = $targetAuthorUuid AND
|
||||
targetTimestamp = $targetTimestamp;
|
||||
`
|
||||
).run({
|
||||
targetAuthorUuid,
|
||||
|
|
|
@ -13,7 +13,6 @@ export async function markConversationRead(
|
|||
}
|
||||
): Promise<boolean> {
|
||||
const { id: conversationId } = conversationAttrs;
|
||||
window.Whisper.Notifications.removeBy({ conversationId });
|
||||
|
||||
const [unreadMessages, unreadReactions] = await Promise.all([
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
window.Whisper.Notifications.removeBy({ conversationId });
|
||||
|
||||
const unreadReactionSyncData = new Map<
|
||||
string,
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue