aboutsummaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2020-07-03 21:14:39 +0200
committerfiaxh <git@lightrise.org>2020-07-16 23:31:19 +0200
commite159fd2492c28c1ef4ab64828ca0e8c2de877b41 (patch)
treeaca3c42854b08b5683a1c85e7c7a74fd0a4bdf0d /main
parent74f7fa897f9aec298eeadcfc7a7b971f06498858 (diff)
downloaddino-e159fd2492c28c1ef4ab64828ca0e8c2de877b41.tar.gz
dino-e159fd2492c28c1ef4ab64828ca0e8c2de877b41.zip
Only query entity caps when we need them
Diffstat (limited to 'main')
-rw-r--r--main/src/ui/conversation_selector/conversation_selector_row.vala90
-rw-r--r--main/src/ui/conversation_view_controller.vala47
2 files changed, 74 insertions, 63 deletions
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(" <i>(").append(status).append(")</i>");
- }
-
- 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(" <i>(").append(status).append(")</i>");
+ }
+
+ 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;
}
diff --git a/main/src/ui/conversation_view_controller.vala b/main/src/ui/conversation_view_controller.vala
index 831aae73..b2be8ed8 100644
--- a/main/src/ui/conversation_view_controller.vala
+++ b/main/src/ui/conversation_view_controller.vala
@@ -93,9 +93,12 @@ public class ConversationViewController : Object {
AccelGroup accel_group = new AccelGroup();
accel_group.connect(Gdk.Key.U, ModifierType.CONTROL_MASK, AccelFlags.VISIBLE, () => {
- if (conversation != null && stream_interactor.get_module(FileManager.IDENTITY).is_upload_available(conversation)) {
- open_file_picker();
- }
+ if (conversation == null) return false;
+ stream_interactor.get_module(FileManager.IDENTITY).is_upload_available.begin(conversation, (_, res) => {
+ if (stream_interactor.get_module(FileManager.IDENTITY).is_upload_available.end(res)) {
+ open_file_picker();
+ }
+ });
return false;
});
((Gtk.Window)view.get_toplevel()).add_accel_group(accel_group);
@@ -138,13 +141,15 @@ public class ConversationViewController : Object {
}
private void update_file_upload_status() {
- bool upload_available = stream_interactor.get_module(FileManager.IDENTITY).is_upload_available(conversation);
- chat_input_controller.set_file_upload_active(upload_available);
- if (upload_available && overlay_dialog == null) {
- Gtk.drag_dest_set(view, DestDefaults.ALL, target_list, Gdk.DragAction.COPY);
- } else {
- Gtk.drag_dest_unset(view);
- }
+ stream_interactor.get_module(FileManager.IDENTITY).is_upload_available.begin(conversation, (_, res) => {
+ bool upload_available = stream_interactor.get_module(FileManager.IDENTITY).is_upload_available.end(res);
+ chat_input_controller.set_file_upload_active(upload_available);
+ if (upload_available && overlay_dialog == null) {
+ Gtk.drag_dest_set(view, DestDefaults.ALL, target_list, Gdk.DragAction.COPY);
+ } else {
+ Gtk.drag_dest_unset(view);
+ }
+ });
}
private void update_conversation_display_name() {
@@ -212,18 +217,20 @@ public class ConversationViewController : Object {
FileSendOverlay overlay = new FileSendOverlay(file, file_info);
overlay.send_file.connect(() => send_file(file));
- HashMap<int, long> limits = stream_interactor.get_module(FileManager.IDENTITY).get_file_size_limits(conversation);
- bool something_works = false;
- foreach (var limit in limits.values) {
- if (limit >= file_info.get_size()) {
- something_works = true;
+ stream_interactor.get_module(FileManager.IDENTITY).get_file_size_limits.begin(conversation, (_, res) => {
+ HashMap<int, long> limits = stream_interactor.get_module(FileManager.IDENTITY).get_file_size_limits.end(res);
+ bool something_works = false;
+ foreach (var limit in limits.values) {
+ if (limit >= file_info.get_size()) {
+ something_works = true;
+ }
}
- }
- if (!something_works && limits.has_key(0)) {
- if (!something_works && file_info.get_size() > limits[0]) {
- overlay.set_file_too_large();
+ if (!something_works && limits.has_key(0)) {
+ if (!something_works && file_info.get_size() > limits[0]) {
+ overlay.set_file_too_large();
+ }
}
- }
+ });
overlay.close.connect(() => {
// We don't want drag'n'drop to be active while the overlay is active