aboutsummaryrefslogtreecommitdiff
path: root/libdino
diff options
context:
space:
mode:
authorcodedust <codedust@users.noreply.github.com>2020-03-02 21:10:36 +0100
committerfiaxh <git@lightrise.org>2020-07-06 21:52:33 +0200
commit86420fdef11b2833fbc42549c8c5817031876d66 (patch)
treefb51349e7468d64f394901a4d177398865aae580 /libdino
parent23c021685364de19e64248d0411a7ed2f216700e (diff)
downloaddino-86420fdef11b2833fbc42549c8c5817031876d66.tar.gz
dino-86420fdef11b2833fbc42549c8c5817031876d66.zip
Show bubble containing the number of unread messages in the conversation list (#764)
Co-authored-by: codedust <codedust@users.noreply.github.com> Co-authored-by: fiaxh <git@lightrise.org>
Diffstat (limited to 'libdino')
-rw-r--r--libdino/src/service/chat_interaction.vala18
1 files changed, 13 insertions, 5 deletions
diff --git a/libdino/src/service/chat_interaction.vala b/libdino/src/service/chat_interaction.vala
index c832aeca..d777db90 100644
--- a/libdino/src/service/chat_interaction.vala
+++ b/libdino/src/service/chat_interaction.vala
@@ -32,11 +32,19 @@ public class ChatInteraction : StreamInteractionModule, Object {
stream_interactor.get_module(ContentItemStore.IDENTITY).new_item.connect(new_item);
}
- public bool has_unread(Conversation conversation) {
- ContentItem? last_content_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_latest(conversation);
- if (last_content_item == null) return false;
-
- return last_content_item.id != conversation.read_up_to_item;
+ 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 local_time = read_up_to_item.sort_time.to_unix().to_string();
+ string time = read_up_to_item.display_time.to_unix().to_string();
+ string id = read_up_to_item.id.to_string();
+ return (int)db.content_item.select()
+ .where(@"local_time > ? OR (local_time = ? AND time > ?) OR (local_time = ? AND time = ? AND id > ?)", { local_time, local_time, time, local_time, time, id })
+ .with(db.content_item.conversation_id, "=", conversation.id)
+ .with(db.content_item.hide, "=", false)
+ .count();
}
public bool is_active_focus(Conversation? conversation = null) {