From 86420fdef11b2833fbc42549c8c5817031876d66 Mon Sep 17 00:00:00 2001 From: codedust Date: Mon, 2 Mar 2020 21:10:36 +0100 Subject: Show bubble containing the number of unread messages in the conversation list (#764) Co-authored-by: codedust Co-authored-by: fiaxh --- libdino/src/service/chat_interaction.vala | 18 ++++++++++---- main/data/conversation_row.ui | 28 +++++++++++++++++++++- main/data/theme.css | 8 +++++++ .../conversation_selector_row.vala | 20 ++++++++++++---- 4 files changed, 63 insertions(+), 11 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) { diff --git a/main/data/conversation_row.ui b/main/data/conversation_row.ui index 7772c907..8d257201 100644 --- a/main/data/conversation_row.ui +++ b/main/data/conversation_row.ui @@ -46,7 +46,7 @@ slide-right - 100 + 50 True True @@ -71,6 +71,7 @@ 15 end + end 0 + + + + @@ -116,6 +141,7 @@ False True + 5