diff options
Diffstat (limited to 'main/src/ui/util')
-rw-r--r-- | main/src/ui/util/helper.vala | 94 |
1 files changed, 18 insertions, 76 deletions
diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala index 5d6d7bf5..b147e5d7 100644 --- a/main/src/ui/util/helper.vala +++ b/main/src/ui/util/helper.vala @@ -115,94 +115,23 @@ public static async AvatarDrawer get_conversation_participants_avatar_drawer(Str } public static string get_conversation_display_name(StreamInteractor stream_interactor, Conversation conversation) { - if (conversation.type_ == Conversation.Type.CHAT) { - string? display_name = get_real_display_name(stream_interactor, conversation.account, conversation.counterpart); - if (display_name != null) return display_name; - return conversation.counterpart.to_string(); - } - if (conversation.type_ == Conversation.Type.GROUPCHAT) { - return get_groupchat_display_name(stream_interactor, conversation.account, conversation.counterpart); - } - if (conversation.type_ == Conversation.Type.GROUPCHAT_PM) { - return _("%s from %s").printf(get_occupant_display_name(stream_interactor, conversation, conversation.counterpart), get_groupchat_display_name(stream_interactor, conversation.account, conversation.counterpart.bare_jid)); - } - return conversation.counterpart.to_string(); + return Dino.get_conversation_display_name(stream_interactor, conversation, _("%s from %s")); } public static string get_participant_display_name(StreamInteractor stream_interactor, Conversation conversation, Jid participant, bool me_is_me = false) { - if (me_is_me) { - if (conversation.account.bare_jid.equals_bare(participant) || - (conversation.type_ == Conversation.Type.GROUPCHAT || conversation.type_ == Conversation.Type.GROUPCHAT_PM) && - conversation.nickname != null && participant.equals_bare(conversation.counterpart) && conversation.nickname == participant.resourcepart) { - return _("Me"); - } - } - if (conversation.type_ == Conversation.Type.CHAT) { - return get_real_display_name(stream_interactor, conversation.account, participant, me_is_me) ?? participant.bare_jid.to_string(); - } - if ((conversation.type_ == Conversation.Type.GROUPCHAT || conversation.type_ == Conversation.Type.GROUPCHAT_PM) && conversation.counterpart.equals_bare(participant)) { - return get_occupant_display_name(stream_interactor, conversation, participant); - } - return participant.bare_jid.to_string(); + return Dino.get_participant_display_name(stream_interactor, conversation, participant, me_is_me ? _("Me") : null); } private static string? get_real_display_name(StreamInteractor stream_interactor, Account account, Jid jid, bool me_is_me = false) { - if (jid.equals_bare(account.bare_jid)) { - if (me_is_me || account.alias == null || account.alias.length == 0) { - return _("Me"); - } - return account.alias; - } - Roster.Item roster_item = stream_interactor.get_module(RosterManager.IDENTITY).get_roster_item(account, jid); - if (roster_item != null && roster_item.name != null && roster_item.name != "") { - return roster_item.name; - } - return null; + return Dino.get_real_display_name(stream_interactor, account, jid, me_is_me ? _("Me") : null); } private static string get_groupchat_display_name(StreamInteractor stream_interactor, Account account, Jid 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<Jid>? 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_real_display_name(stream_interactor, account, occupant) ?? occupant.localpart ?? occupant.domainpart).split(" ")[0]); - } - return builder.str; - } - } - return jid.to_string(); + return Dino.get_groupchat_display_name(stream_interactor, account, jid); } private static string get_occupant_display_name(StreamInteractor stream_interactor, Conversation conversation, Jid jid, bool me_is_me = false, bool muc_real_name = false) { - if (muc_real_name) { - MucManager muc_manager = stream_interactor.get_module(MucManager.IDENTITY); - if (muc_manager.is_private_room(conversation.account, jid.bare_jid)) { - Jid? real_jid = muc_manager.get_real_jid(jid, conversation.account); - if (real_jid != null) { - string? display_name = get_real_display_name(stream_interactor, conversation.account, real_jid, me_is_me); - if (display_name != null) return display_name; - } - } - } - - // If it's us (jid=our real full JID), display our nick - if (conversation.type_ == Conversation.Type.GROUPCHAT_PM && conversation.account.bare_jid.equals_bare(jid)) { - var muc_conv = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(conversation.counterpart.bare_jid, conversation.account, Conversation.Type.GROUPCHAT); - if (muc_conv != null && muc_conv.nickname != null) { - return muc_conv.nickname; - } - } - - return jid.resourcepart ?? jid.to_string(); + return Dino.get_occupant_display_name(stream_interactor, conversation, jid, me_is_me ? _("Me") : null); } public static void image_set_from_scaled_pixbuf(Image image, Gdk.Pixbuf pixbuf, int scale = 0, int width = 0, int height = 0) { @@ -440,6 +369,19 @@ public string summarize_whitespaces_to_space(string s) { } } +public void present_window(Window window) { +#if GDK3_WITH_X11 + Gdk.X11.Window x11window = window.get_window() as Gdk.X11.Window; + if (x11window != null) { + window.present_with_time(Gdk.X11.get_server_time(x11window)); + } else { + window.present(); + } +#else + window.present(); +#endif +} + public bool use_csd() { return ((Application) GLib.Application.get_default()).use_csd(); } |