[PATCH 02/11] lib: use new addresses structure for thread authors

Jameson Graef Rollins jrollins at finestructure.net
Sun Aug 19 18:52:41 PDT 2012


Now that we have the infrastructure in place, we modify the thread
object and associated functions to use the new addresses structure for
storing thread authors.
---
 lib/thread.cc |   41 +++++++++++------------------------------
 1 file changed, 11 insertions(+), 30 deletions(-)

diff --git a/lib/thread.cc b/lib/thread.cc
index 7af9eeb..9e0e5cb 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -36,11 +36,7 @@ struct visible _notmuch_thread {
     notmuch_database_t *notmuch;
     char *thread_id;
     char *subject;
-    GHashTable *authors_hash;
-    GPtrArray *authors_array;
-    GHashTable *matched_authors_hash;
-    GPtrArray *matched_authors_array;
-    char *authors;
+    notmuch_thread_addresses_t *authors;
     GHashTable *tags;
 
     notmuch_message_list_t *message_list;
@@ -66,21 +62,9 @@ _notmuch_thread_addresses_destructor (notmuch_thread_addresses_t *addresses)
 static int
 _notmuch_thread_destructor (notmuch_thread_t *thread)
 {
-    g_hash_table_unref (thread->authors_hash);
-    g_hash_table_unref (thread->matched_authors_hash);
+    _notmuch_thread_addresses_destructor (thread->authors);
     g_hash_table_unref (thread->tags);
     g_hash_table_unref (thread->message_hash);
-
-    if (thread->authors_array) {
-	g_ptr_array_free (thread->authors_array, TRUE);
-	thread->authors_array = NULL;
-    }
-
-    if (thread->matched_authors_array) {
-	g_ptr_array_free (thread->matched_authors_array, TRUE);
-	thread->matched_authors_array = NULL;
-    }
-
     return 0;
 }
 
@@ -341,7 +325,7 @@ _thread_add_message (notmuch_thread_t *thread,
 		author = internet_address_mailbox_get_addr (mailbox);
 	    }
 	    clean_author = _thread_cleanup_author (thread, author, from);
-	    _thread_add_author (thread, clean_author);
+	    _thread_add_address (thread->authors, clean_author, FALSE);
 	    notmuch_message_set_author (message, clean_author);
 	}
 	g_object_unref (G_OBJECT (list));
@@ -436,7 +420,7 @@ _thread_add_matched_message (notmuch_thread_t *thread,
 				  NOTMUCH_MESSAGE_FLAG_MATCH, 1);
     }
 
-    _thread_add_matched_author (thread, notmuch_message_get_author (hashed_message));
+    _thread_add_address (thread->authors, notmuch_message_get_author (hashed_message), TRUE);
 }
 
 static void
@@ -555,14 +539,11 @@ _notmuch_thread_create (void *ctx,
     thread->notmuch = notmuch;
     thread->thread_id = talloc_strdup (thread, thread_id);
     thread->subject = NULL;
-    thread->authors_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
-						  NULL, NULL);
-    thread->authors_array = g_ptr_array_new ();
-    thread->matched_authors_hash = g_hash_table_new_full (g_str_hash,
-							  g_str_equal,
-							  NULL, NULL);
-    thread->matched_authors_array = g_ptr_array_new ();
-    thread->authors = NULL;
+
+    thread->authors = _thread_addresses_init (thread);
+    if (unlikely (thread->authors == NULL))
+	return NULL;
+
     thread->tags = g_hash_table_new_full (g_str_hash, g_str_equal,
 					  free, NULL);
 
@@ -607,7 +588,7 @@ _notmuch_thread_create (void *ctx,
 
     notmuch_query_destroy (thread_id_query);
 
-    _resolve_thread_authors_string (thread);
+    _resolve_thread_addresses_string (thread->authors);
 
     _resolve_thread_relationships (thread);
 
@@ -641,7 +622,7 @@ notmuch_thread_get_matched_messages (notmuch_thread_t *thread)
 const char *
 notmuch_thread_get_authors (notmuch_thread_t *thread)
 {
-    return thread->authors;
+    return thread->authors->string;
 }
 
 const char *
-- 
1.7.10.4



More information about the notmuch mailing list