[geary/wip/713150-conversations] Small bug fixes w/ removing conversations and dropping refs



commit 451ddc6382cd31ff8a1632fb31c5925bfee49a24
Author: Jim Nelson <jim yorba org>
Date:   Tue Mar 3 17:51:19 2015 -0800

    Small bug fixes w/ removing conversations and dropping refs

 src/client/application/geary-controller.vala |    8 ++++++++
 src/engine/app/app-conversation-monitor.vala |   15 ++++++++-------
 2 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 21fcde2..e1640cc 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -287,6 +287,7 @@ public class GearyController : Geary.BaseObject {
         } catch (Error err) {
             message("Error closing conversation at shutdown: %s", err.message);
         } finally {
+            last_deleted_conversation = null;
             current_conversations = null;
         }
         
@@ -1342,6 +1343,7 @@ public class GearyController : Geary.BaseObject {
         // stop monitoring for conversations and close the folder
         if (current_conversations != null) {
             yield current_conversations.stop_monitoring_async(null);
+            last_deleted_conversation = null;
             current_conversations = null;
         }
         
@@ -1400,6 +1402,7 @@ public class GearyController : Geary.BaseObject {
         current_conversations.scan_completed.connect(on_conversation_count_changed);
         current_conversations.conversations_added.connect(on_conversation_count_changed);
         current_conversations.conversation_removed.connect(on_conversation_count_changed);
+        current_conversations.conversation_removed.connect(on_conversation_removed);
         
         if (!current_conversations.is_monitoring)
             yield current_conversations.start_monitoring_async(conversation_cancellable);
@@ -1427,6 +1430,11 @@ public class GearyController : Geary.BaseObject {
             conversation_count_changed(current_conversations.get_conversation_count());
     }
     
+    private void on_conversation_removed(Geary.App.Conversation conversation) {
+        if (conversation == last_deleted_conversation)
+            last_deleted_conversation = null;
+    }
+    
     private void on_libnotify_invoked(Geary.Folder? folder, Geary.Email? email) {
         new_messages_monitor.clear_all_new_messages();
         
diff --git a/src/engine/app/app-conversation-monitor.vala b/src/engine/app/app-conversation-monitor.vala
index dea19f4..d282a52 100644
--- a/src/engine/app/app-conversation-monitor.vala
+++ b/src/engine/app/app-conversation-monitor.vala
@@ -661,6 +661,7 @@ public class Geary.App.ConversationMonitor : BaseObject {
         yield load_by_sparse_id(appended_ids, required_fields, Geary.Folder.ListFlags.NONE, null);
     }
     
+    // IMPORTANT: path must be the FolderPath the removed_ids originated from
     internal void remove_emails(FolderPath path, Gee.Collection<EmailIdentifier> removed_ids) {
         debug("%d messages(s) removed from %s, trimming/removing conversations in %s...", removed_ids.size,
             path.to_string(), folder.to_string());
@@ -676,17 +677,15 @@ public class Geary.App.ConversationMonitor : BaseObject {
             if (path.equal_to(folder.path))
                 primary_email_id_to_conversation.unset(removed_id);
             
-            Conversation? conversation = all_email_id_to_conversation[removed_id];
-            if (conversation == null)
+            Conversation conversation;
+            if (!all_email_id_to_conversation.unset(removed_id, out conversation))
                 continue;
             
             Email? email = conversation.get_email_by_id(removed_id);
-            if (email == null)
-                continue;
             
             // Remove from conversation by *path*, which means it may not be fully removed if
             // detected in other paths
-            bool fully_removed = conversation.remove(email, path);
+            bool fully_removed = email != null ? conversation.remove(email, path) : false;
             
             // if conversation is empty or has no messages in primary folder path, remove it
             // entirely
@@ -696,7 +695,7 @@ public class Geary.App.ConversationMonitor : BaseObject {
                 
                 conversations.remove(conversation);
                 removed_conversations.add(conversation);
-            } else if (fully_removed) {
+            } else if (fully_removed && email != null) {
                 // since the email was fully removed from conversation, report as trimmed
                 trimmed_conversations.set(conversation, email);
             }
@@ -713,8 +712,10 @@ public class Geary.App.ConversationMonitor : BaseObject {
         if (removed_conversations.size > 0)
             debug("Removed %d conversations from %s", removed_conversations.size, folder.to_string());
         
-        foreach (Conversation conversation in removed_conversations)
+        foreach (Conversation conversation in removed_conversations) {
             notify_conversation_removed(conversation);
+            conversation.clear_owner();
+        }
     }
     
     internal async void external_append_emails_async(Folder folder, Gee.Collection<EmailIdentifier> 
appended_ids) {


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