Fix messages being displayed for the wrong sender: Show avatar on lower message when inserting message between two others

fixes #641
fixes #639
This commit is contained in:
fiaxh 2019-11-13 17:42:47 +01:00
parent 8f0fe37402
commit c6bdb1a4bc
2 changed files with 19 additions and 7 deletions

View file

@ -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() {

View file

@ -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) {