From e159fd2492c28c1ef4ab64828ca0e8c2de877b41 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Fri, 3 Jul 2020 21:14:39 +0200 Subject: Only query entity caps when we need them --- .../conversation_selector_row.vala | 90 +++++++++++----------- 1 file changed, 47 insertions(+), 43 deletions(-) (limited to 'main/src/ui/conversation_selector/conversation_selector_row.vala') diff --git a/main/src/ui/conversation_selector/conversation_selector_row.vala b/main/src/ui/conversation_selector/conversation_selector_row.vala index 3e0c1349..07e3f831 100644 --- a/main/src/ui/conversation_selector/conversation_selector_row.vala +++ b/main/src/ui/conversation_selector/conversation_selector_row.vala @@ -271,50 +271,54 @@ public class ConversationSelectorRow : ListBoxRow { Jid full_jid = full_jids[i]; string? show = stream_interactor.get_module(PresenceManager.IDENTITY).get_last_show(full_jid, conversation.account); if (show == null) continue; - Xep.ServiceDiscovery.Identity? identity = stream_interactor.get_module(EntityInfo.IDENTITY).get_identity(conversation.account, full_jid); - Image image = new Image() { hexpand=false, valign=Align.CENTER, visible=true }; - if (identity != null && (identity.type_ == Xep.ServiceDiscovery.Identity.TYPE_PHONE || identity.type_ == Xep.ServiceDiscovery.Identity.TYPE_TABLET)) { - image.set_from_icon_name("dino-device-phone-symbolic", IconSize.SMALL_TOOLBAR); - } else { - image.set_from_icon_name("dino-device-desktop-symbolic", IconSize.SMALL_TOOLBAR); - } - - if (show == Presence.Stanza.SHOW_AWAY) { - Util.force_color(image, "#FF9800"); - } else if (show == Presence.Stanza.SHOW_XA || show == Presence.Stanza.SHOW_DND) { - Util.force_color(image, "#FF5722"); - } else { - Util.force_color(image, "#4CAF50"); - } - - string? status = null; - if (show == Presence.Stanza.SHOW_AWAY) { - status = "away"; - } else if (show == Presence.Stanza.SHOW_XA) { - status = "not available"; - } else if (show == Presence.Stanza.SHOW_DND) { - status = "do not disturb"; - } - - var sb = new StringBuilder(); - if (identity != null && identity.name != null) { - sb.append(identity.name); - } else if (full_jid.resourcepart != null && dino_resource_regex.match(full_jid.resourcepart)) { - sb.append("Dino"); - } else if (full_jid.resourcepart != null) { - sb.append(full_jid.resourcepart); - } else { - continue; - } - if (status != null) { - sb.append(" (").append(status).append(")"); - } - - Label resource = new Label(sb.str) { use_markup=true, hexpand=true, xalign=0, visible=true }; - - grid.attach(image, 0, i + 1, 1, 1); - grid.attach(resource, 1, i + 1, 1, 1); + int i_cache = i; + stream_interactor.get_module(EntityInfo.IDENTITY).get_identity.begin(conversation.account, full_jid, (_, res) => { + Xep.ServiceDiscovery.Identity? identity = stream_interactor.get_module(EntityInfo.IDENTITY).get_identity.end(res); + + Image image = new Image() { hexpand=false, valign=Align.CENTER, visible=true }; + if (identity != null && (identity.type_ == Xep.ServiceDiscovery.Identity.TYPE_PHONE || identity.type_ == Xep.ServiceDiscovery.Identity.TYPE_TABLET)) { + image.set_from_icon_name("dino-device-phone-symbolic", IconSize.SMALL_TOOLBAR); + } else { + image.set_from_icon_name("dino-device-desktop-symbolic", IconSize.SMALL_TOOLBAR); + } + + if (show == Presence.Stanza.SHOW_AWAY) { + Util.force_color(image, "#FF9800"); + } else if (show == Presence.Stanza.SHOW_XA || show == Presence.Stanza.SHOW_DND) { + Util.force_color(image, "#FF5722"); + } else { + Util.force_color(image, "#4CAF50"); + } + + string? status = null; + if (show == Presence.Stanza.SHOW_AWAY) { + status = "away"; + } else if (show == Presence.Stanza.SHOW_XA) { + status = "not available"; + } else if (show == Presence.Stanza.SHOW_DND) { + status = "do not disturb"; + } + + var sb = new StringBuilder(); + if (identity != null && identity.name != null) { + sb.append(identity.name); + } else if (full_jid.resourcepart != null && dino_resource_regex.match(full_jid.resourcepart)) { + sb.append("Dino"); + } else if (full_jid.resourcepart != null) { + sb.append(full_jid.resourcepart); + } else { + return; + } + if (status != null) { + sb.append(" (").append(status).append(")"); + } + + Label resource = new Label(sb.str) { use_markup=true, hexpand=true, xalign=0, visible=true }; + + grid.attach(image, 0, i_cache + 1, 1, 1); + grid.attach(resource, 1, i_cache + 1, 1, 1); + }); } return grid; } -- cgit v1.2.3-54-g00ecf