From c6bdb1a4bc109256b2a109940c640a8b2ad8f57f Mon Sep 17 00:00:00 2001 From: fiaxh Date: Wed, 13 Nov 2019 17:42:47 +0100 Subject: Fix messages being displayed for the wrong sender: Show avatar on lower message when inserting message between two others fixes #641 fixes #639 --- .../conversation_item_skeleton.vala | 1 + .../ui/conversation_summary/conversation_view.vala | 25 ++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/main/src/ui/conversation_summary/conversation_item_skeleton.vala b/main/src/ui/conversation_summary/conversation_item_skeleton.vala index 182ec298..28551b01 100644 --- a/main/src/ui/conversation_summary/conversation_item_skeleton.vala +++ b/main/src/ui/conversation_summary/conversation_item_skeleton.vala @@ -71,6 +71,7 @@ public class ConversationItemSkeleton : EventBox { this.show_skeleton = true; this.last_group_item = true; update_margin(); + this.notify["show-skeleton"].connect(update_margin); } public void update_time() { diff --git a/main/src/ui/conversation_summary/conversation_view.vala b/main/src/ui/conversation_summary/conversation_view.vala index d73d012b..4c5d1ace 100644 --- a/main/src/ui/conversation_summary/conversation_view.vala +++ b/main/src/ui/conversation_summary/conversation_view.vala @@ -254,18 +254,21 @@ public class ConversationView : Box, Plugins.ConversationItemCollection, Plugins main.reorder_child(insert, index); if (lower_item != null) { - ConversationItemSkeleton lower_skeleton = item_item_skeletons[lower_item]; - Plugins.MetaConversationItem lower_start_item = lower_skeleton.item; - if (item.display_time != null && lower_start_item.display_time != null && - item.display_time.difference(lower_start_item.display_time) < TimeSpan.MINUTE && - lower_start_item.jid.equals(item.jid) && - lower_start_item.encryption == item.encryption && - (item.mark == Message.Marked.WONTSEND) == (lower_start_item.mark == Message.Marked.WONTSEND)) { + if (can_merge(item, lower_item)) { + ConversationItemSkeleton lower_skeleton = item_item_skeletons[lower_item]; item_skeleton.show_skeleton = false; lower_skeleton.last_group_item = false; } } + Plugins.MetaConversationItem? upper_item = meta_items.higher(item); + if (upper_item != null) { + if (!can_merge(upper_item, item)) { + ConversationItemSkeleton upper_skeleton = item_item_skeletons[upper_item]; + upper_skeleton.show_skeleton = true; + } + } + // If an item from the past was added, add everything between that item and the (post-)first present item if (index == 0) { Dino.Application app = Dino.Application.get_default(); @@ -282,6 +285,14 @@ public class ConversationView : Box, Plugins.ConversationItemCollection, Plugins return insert; } + private bool can_merge(Plugins.MetaConversationItem upper_item /*more recent, displayed below*/, Plugins.MetaConversationItem lower_item /*less recent, displayed above*/) { + return upper_item.display_time != null && lower_item.display_time != null && + upper_item.display_time.difference(lower_item.display_time) < TimeSpan.MINUTE && + upper_item.jid.equals(lower_item.jid) && + upper_item.encryption == lower_item.encryption && + (upper_item.mark == Message.Marked.WONTSEND) == (lower_item.mark == Message.Marked.WONTSEND); + } + private void on_upper_notify() { if (was_upper == null || scrolled.vadjustment.value > was_upper - was_page_size - 1) { // scrolled down or content smaller than page size if (at_current_content) { -- cgit v1.2.3-54-g00ecf