diff options
author | fiaxh <git@lightrise.org> | 2021-12-21 18:51:57 +0100 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2021-12-21 18:51:57 +0100 |
commit | 1378224444b1862ac95783ac2bae7d25a0a8862d (patch) | |
tree | 17ac3a72431a1fcfc897ecbeef609f121d17cba6 /libdino | |
parent | 4e9957deaf4af2258dada078d251524ca96f7675 (diff) | |
download | dino-1378224444b1862ac95783ac2bae7d25a0a8862d.tar.gz dino-1378224444b1862ac95783ac2bae7d25a0a8862d.zip |
Fix unread counting in new conversations w/o read_up_to_item
fixes #1094
Diffstat (limited to 'libdino')
-rw-r--r-- | libdino/src/service/chat_interaction.vala | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/libdino/src/service/chat_interaction.vala b/libdino/src/service/chat_interaction.vala index 240d22af..00c611db 100644 --- a/libdino/src/service/chat_interaction.vala +++ b/libdino/src/service/chat_interaction.vala @@ -33,17 +33,21 @@ public class ChatInteraction : StreamInteractionModule, Object { } public int get_num_unread(Conversation conversation) { - ContentItem? read_up_to_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_item_by_id(conversation, conversation.read_up_to_item); - if (read_up_to_item == null) return 0; - Database db = Dino.Application.get_default().db; - string time = read_up_to_item.time.to_unix().to_string(); - string id = read_up_to_item.id.to_string(); - return (int)db.content_item.select() - .where(@"time > ? OR (time = ? AND id > ?)", { time, time, id }) + + Qlite.QueryBuilder query = db.content_item.select() .with(db.content_item.conversation_id, "=", conversation.id) - .with(db.content_item.hide, "=", false) - .count(); + .with(db.content_item.hide, "=", false); + + ContentItem? read_up_to_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_item_by_id(conversation, conversation.read_up_to_item); + if (read_up_to_item != null) { + string time = read_up_to_item.time.to_unix().to_string(); + string id = read_up_to_item.id.to_string(); + query.where(@"time > ? OR (time = ? AND id > ?)", { time, time, id }); + } + // If it's a new conversation with read_up_to_item == null, all items are new. + + return (int) query.count(); } public bool is_active_focus(Conversation? conversation = null) { |