From d8e0ab406cdad73edf79123e84d0013b96a3963a Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 4 Dec 2018 10:21:24 +0100 Subject: display groups w/o name by list of members For members-only, non-anonymous groups that do not have a name set we now show an automatically generated name that is generated from the list of members (offline, and online). Only the first name (before the first space) is used to keep the generated name short. The term *private room* is coined as a short hand for members only&non-anon group chats. This commit also uses the offline members list instead of the online member list to generate avatar tiles (also only in members-only, non-anon groups.) --- main/src/ui/avatar_image.vala | 15 ++++++++++++++- main/src/ui/conversation_selector/conversation_row.vala | 5 +++++ main/src/ui/conversation_titlebar/view.vala | 6 ++++++ main/src/ui/util/helper.vala | 17 ++++++++++++++++- 4 files changed, 41 insertions(+), 2 deletions(-) (limited to 'main') diff --git a/main/src/ui/avatar_image.vala b/main/src/ui/avatar_image.vala index bf6cb9f4..f6140c26 100644 --- a/main/src/ui/avatar_image.vala +++ b/main/src/ui/avatar_image.vala @@ -194,6 +194,7 @@ public class AvatarImage : Misc { stream_interactor.get_module(AvatarManager.IDENTITY).received_avatar.disconnect(on_received_avatar); stream_interactor.connection_manager.connection_state_changed.disconnect(on_connection_changed); stream_interactor.get_module(RosterManager.IDENTITY).updated_roster_item.disconnect(on_roster_updated); + stream_interactor.get_module(MucManager.IDENTITY).private_room_occupant_updated.disconnect(on_occupant_updated); } } @@ -205,10 +206,16 @@ public class AvatarImage : Misc { stream_interactor.get_module(AvatarManager.IDENTITY).received_avatar.connect(on_received_avatar); stream_interactor.connection_manager.connection_state_changed.connect(on_connection_changed); stream_interactor.get_module(RosterManager.IDENTITY).updated_roster_item.connect(on_roster_updated); + stream_interactor.get_module(MucManager.IDENTITY).private_room_occupant_updated.connect(on_occupant_updated); } if (muc_manager.is_groupchat(jid_, account) && avatar_manager.get_avatar(account, jid_) == null) { // Groupchat without avatar - Gee.List? occupants = muc_manager.get_other_occupants(jid_, account); + Gee.List? occupants; + if (muc_manager.is_private_room(account, jid_)) { + occupants = muc_manager.get_other_offline_members(jid_, account); + } else { + occupants = muc_manager.get_other_occupants(jid_, account); + } jid = jid_; if (occupants == null || occupants.size == 0) { if (force_update || current_jids.length != 1 || !current_jids[0].equals(jid_) || gray != (allow_gray && (occupants == null || !is_self_online()))) { @@ -292,6 +299,12 @@ public class AvatarImage : Misc { set_jid(stream_interactor, this.jid, account, true); } + private void on_occupant_updated(Account account, Jid room, Jid occupant) { + if (!account.equals(this.account)) return; + if (!room.equals_bare(this.jid)) return; + set_jid(stream_interactor, this.jid, account, true); + } + private bool is_self_online() { return stream_interactor.connection_manager.get_state(account) == ConnectionManager.ConnectionState.CONNECTED; } diff --git a/main/src/ui/conversation_selector/conversation_row.vala b/main/src/ui/conversation_selector/conversation_row.vala index 6327e07d..992cf107 100644 --- a/main/src/ui/conversation_selector/conversation_row.vala +++ b/main/src/ui/conversation_selector/conversation_row.vala @@ -59,6 +59,11 @@ public class ConversationRow : ListBoxRow { update_name_label(); } }); + stream_interactor.get_module(MucManager.IDENTITY).private_room_occupant_updated.connect((account, room, occupant) => { + if (conversation != null && conversation.counterpart.equals_bare(room.bare_jid) && conversation.account.equals(account)) { + update_name_label(); + } + }); break; case Conversation.Type.GROUPCHAT_PM: break; diff --git a/main/src/ui/conversation_titlebar/view.vala b/main/src/ui/conversation_titlebar/view.vala index 7ee47311..7ced9830 100644 --- a/main/src/ui/conversation_titlebar/view.vala +++ b/main/src/ui/conversation_titlebar/view.vala @@ -42,6 +42,12 @@ public class ConversationTitlebar : Gtk.HeaderBar { } }); + stream_interactor.get_module(MucManager.IDENTITY).private_room_occupant_updated.connect((account, room, occupant) => { + if (conversation != null && conversation.counterpart.equals_bare(room.bare_jid) && conversation.account.equals(account)) { + update_title(); + } + }); + stream_interactor.get_module(MucManager.IDENTITY).subject_set.connect((account, jid, subject) => { if (conversation != null && conversation.counterpart.equals_bare(jid) && conversation.account.equals(account)) { update_subtitle(subject); diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala index 2f2bb84d..da854513 100644 --- a/main/src/ui/util/helper.vala +++ b/main/src/ui/util/helper.vala @@ -60,10 +60,25 @@ public static string get_conversation_display_name(StreamInteractor stream_inter public static string get_display_name(StreamInteractor stream_interactor, Jid jid, Account account) { if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat(jid, account)) { - string room_name = stream_interactor.get_module(MucManager.IDENTITY).get_room_name(account, jid); + MucManager muc_manager = stream_interactor.get_module(MucManager.IDENTITY); + string room_name = muc_manager.get_room_name(account, jid); if (room_name != null && room_name != jid.localpart) { return room_name; } + if (muc_manager.is_private_room(account, jid)) { + Gee.List? other_occupants = muc_manager.get_other_offline_members(jid, account); + if (other_occupants != null && other_occupants.size > 0) { + var builder = new StringBuilder (); + foreach(Jid occupant in other_occupants) { + + if (builder.len != 0) { + builder.append(", "); + } + builder.append(get_display_name(stream_interactor, occupant, account).split(" ")[0]); + } + return builder.str; + } + } return jid.bare_jid.to_string(); } else if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) { return jid.resourcepart; -- cgit v1.2.3-70-g09d2