[geary/wip/135-contact-popovers: 54/56] Start loading remote images if pref enabled via sender's contact popover



commit a1244ecae9bbcce6ba7770fdcb58f7837c82c5eb
Author: Michael Gratton <mike vee net>
Date:   Tue Mar 26 22:45:33 2019 +1100

    Start loading remote images if pref enabled via sender's contact popover

 src/client/application/application-contact.vala    | 30 ++++++++++++++++++++++
 .../conversation-contact-popover.vala              |  5 ++++
 .../conversation-viewer/conversation-message.vala  | 11 +++++---
 3 files changed, 43 insertions(+), 3 deletions(-)
---
diff --git a/src/client/application/application-contact.vala b/src/client/application/application-contact.vala
index a0595db9..40249834 100644
--- a/src/client/application/application-contact.vala
+++ b/src/client/application/application-contact.vala
@@ -95,6 +95,36 @@ public class Application.Contact : Geary.BaseObject {
         update_individual(null);
     }
 
+    /**
+     * Determines if this contact is equal to another.
+     *
+     * Returns true if the other contact has the same Folks
+     * individual, engine contact, or if none of the above display
+     * name.
+     */
+    public bool equal_to(Contact? other) {
+        if (other == null) {
+            return false;
+        }
+        if (this == other) {
+            return true;
+        }
+
+        if (this.individual != null) {
+            return (
+                other.individual != null &&
+                this.individual.id == other.individual.id
+            );
+        } else if (this.contact != null) {
+            return (
+                other.contact != null &&
+                this.contact.email == other.contact.email
+            );
+        }
+
+        return (this.display_name == other.display_name);
+    }
+
     /** Invokes the desktop contacts application to save this contact. */
     public async void save_to_desktop(GLib.Cancellable? cancellable)
         throws GLib.Error {
diff --git a/src/client/conversation-viewer/conversation-contact-popover.vala 
b/src/client/conversation-viewer/conversation-contact-popover.vala
index b22dc697..f7a95523 100644
--- a/src/client/conversation-viewer/conversation-contact-popover.vala
+++ b/src/client/conversation-viewer/conversation-contact-popover.vala
@@ -68,6 +68,10 @@ public class Conversation.ContactPopover : Gtk.Popover {
     private GLib.SimpleActionGroup actions = new GLib.SimpleActionGroup();
 
 
+    /** Fired when the remote resources load pref changes */
+    public signal void load_remote_resources_changed(bool enabled);
+
+
     public ContactPopover(Gtk.Widget relative_to,
                           Application.Contact contact,
                           Geary.RFC822.MailboxAddress mailbox) {
@@ -178,6 +182,7 @@ public class Conversation.ContactPopover : Gtk.Popover {
     private async void set_load_remote_resources(bool enabled) {
         try {
             yield this.contact.set_remote_resource_loading(enabled, null);
+            load_remote_resources_changed(enabled);
         } catch (GLib.Error err) {
             debug("Failed to set load remote resources for contact %s:, %s",
                   this.contact.to_string(), err.message);
diff --git a/src/client/conversation-viewer/conversation-message.vala 
b/src/client/conversation-viewer/conversation-message.vala
index a61db46d..ce8588d0 100644
--- a/src/client/conversation-viewer/conversation-message.vala
+++ b/src/client/conversation-viewer/conversation-message.vala
@@ -964,6 +964,7 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
 
     private void show_images(bool remember) {
         start_progress_loading();
+        this.remote_images_infobar.hide();
         this.load_remote_resources = true;
         this.remote_resources_requested = 0;
         this.remote_resources_loaded = 0;
@@ -1065,6 +1066,12 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
             );
             popover.load_avatar.begin();
             popover.set_position(Gtk.PositionType.BOTTOM);
+            popover.load_remote_resources_changed.connect((enabled) => {
+                    if (this.primary_contact.equal_to(address_child.contact) &&
+                        enabled) {
+                        show_images(false);
+                    }
+                });
             popover.closed.connect(() => {
                     address_child.unset_state_flags(Gtk.StateFlags.ACTIVE);
                 });
@@ -1196,11 +1203,9 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
             }
             break;
         default:
-            // Pass
+            this.remote_images_infobar.hide();
             break;
         }
-
-        remote_images_infobar.hide();
     }
 
     private void on_copy_link(Variant? param) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]