From 8807bbfe806b8f84760892155a5185bf8c6e476a Mon Sep 17 00:00:00 2001 From: Andrei Voronin Date: Wed, 24 Apr 2024 13:31:39 +0300 Subject: [PATCH] Reverting online/offline addings This commit reverts online/offline addings, but keeps possibly useful functions for better future. Right now functions with online functionality saved but unused, they are replaced with almost the same functions. Names was kept as much as possible. --- main/data/occupant_list_item.ui | 9 ---- main/src/ui/occupant_menu/list.vala | 69 ++++++++++++++++++++++--- main/src/ui/occupant_menu/list_row.vala | 4 -- 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/main/data/occupant_list_item.ui b/main/data/occupant_list_item.ui index 631dd574..4402ed95 100644 --- a/main/data/occupant_list_item.ui +++ b/main/data/occupant_list_item.ui @@ -26,14 +26,5 @@ - - - 12 - - 2 - 0 - - - \ No newline at end of file diff --git a/main/src/ui/occupant_menu/list.vala b/main/src/ui/occupant_menu/list.vala index e2ef9227..00bb0eee 100644 --- a/main/src/ui/occupant_menu/list.vala +++ b/main/src/ui/occupant_menu/list.vala @@ -29,8 +29,8 @@ public class List : Box { list_box.set_filter_func(filter); search_entry.search_changed.connect(refilter); - stream_interactor.get_module(PresenceManager.IDENTITY).show_received.connect(on_received_online_presence); - stream_interactor.get_module(PresenceManager.IDENTITY).received_offline_presence.connect(on_received_offline_presence); + stream_interactor.get_module(PresenceManager.IDENTITY).show_received.connect(on_show_received); + stream_interactor.get_module(PresenceManager.IDENTITY).received_offline_presence.connect(on_quit_received); initialize_for_conversation(conversation); } @@ -63,12 +63,11 @@ public class List : Box { this.conversation = conversation; var identity = stream_interactor.get_module(MucManager.IDENTITY); - Gee.List? members = identity.get_all_members(conversation.counterpart, conversation.account); + Gee.List? members = identity.get_members(conversation.counterpart, conversation.account); if (members != null) { // Add all members and their status to the list foreach (Jid member in members) { - bool online = get_status(member, conversation.account); - add_member(member, online); + add_member(member); //use add_member_with_status if you want to get online/offline statuses } } list_box.invalidate_filter(); @@ -83,7 +82,7 @@ public class List : Box { list_box.invalidate_filter(); } - public void add_member(Jid jid, bool online) { + public void add_member_with_status(Jid jid, bool online) { // HACK: // Here we track members based on their names (not jids) // Sometimes the same member can be referenced with different jids, for example: @@ -124,6 +123,35 @@ public class List : Box { } } + public void add_member(Jid jid) { + var row_wrapper = new ListRow(stream_interactor, conversation, jid); + var widget = row_wrapper.get_widget(); + + string member_name = null; + if (jid.resourcepart != null) { + member_name = jid.resourcepart; + } else { + member_name = jid.localpart; + } + + if (member_name == null) { + return; + } + + row_wrappers[widget] = row_wrapper; + rows[member_name] = widget; + list_box.append(widget); + } + + public void remove_member(Jid jid) { + var member_name = jid.resourcepart; + if (member_name == null) { + return; + } + list_box.remove(rows[member_name]); + rows.unset(member_name); + } + private void on_received_offline_presence(Jid jid, Account account) { if (conversation != null && conversation.counterpart.equals_bare(jid) && jid.is_full()) { var member_name = jid.resourcepart; @@ -139,6 +167,19 @@ public class List : Box { } } + private void on_quit_received(Jid jid, Account account) { + if (conversation != null && conversation.counterpart.equals_bare(jid) && jid.is_full()) { + var member_name = jid.resourcepart; + if (member_name == null) { + return; + } + if (rows.has_key(member_name)) { + remove_member(jid); + } + list_box.invalidate_filter(); + } + } + private void on_received_online_presence(Jid jid, Account account) { if (conversation != null && conversation.counterpart.equals_bare(jid) && jid.is_full()) { var member_name = jid.resourcepart; @@ -147,7 +188,7 @@ public class List : Box { } if (!rows.has_key(member_name)) { - add_member(jid, true); + add_member_with_status(jid, true); } row_wrappers[rows[member_name]].set_online(); @@ -156,6 +197,20 @@ public class List : Box { } } + private void on_show_received(Jid jid, Account account) { + if (conversation != null && conversation.counterpart.equals_bare(jid) && jid.is_full()) { + var member_name = jid.resourcepart; + if (member_name == null) { + return; + } + if (!rows.has_key(member_name)) { + add_member(jid); + } + list_box.invalidate_filter(); + } + } + + private void header(ListBoxRow row, ListBoxRow? before_row) { ListRow row_wrapper1 = row_wrappers[row.get_child()]; Xmpp.Xep.Muc.Affiliation? a1 = stream_interactor.get_module(MucManager.IDENTITY).get_affiliation(conversation.counterpart, row_wrapper1.jid, row_wrapper1.conversation.account); diff --git a/main/src/ui/occupant_menu/list_row.vala b/main/src/ui/occupant_menu/list_row.vala index 3e5b37e9..bc81795a 100644 --- a/main/src/ui/occupant_menu/list_row.vala +++ b/main/src/ui/occupant_menu/list_row.vala @@ -10,7 +10,6 @@ public class ListRow : Object { private Grid main_grid; private AvatarPicture picture; public Label name_label; - public Image status_image; public Conversation? conversation; public Jid? jid; @@ -19,7 +18,6 @@ public class ListRow : Object { main_grid = (Grid) builder.get_object("main_grid"); picture = (AvatarPicture) builder.get_object("picture"); name_label = (Label) builder.get_object("name_label"); - status_image = (Image) builder.get_object("status_image"); main_grid.set_column_spacing(10); main_grid.set_column_homogeneous(false); main_grid.set_baseline_row(1); @@ -43,11 +41,9 @@ public class ListRow : Object { } public void set_online() { - status_image.icon_name = "dino-status-online-bright"; } public void set_offline() { - status_image.icon_name = "dino-status-offline"; } }