-/* Return one or more thread_ids, (as a GPtrArray of strings), for the
- * given message based on looking into the database for any messages
- * referenced in parents, and also for any messages in the database
- * referencing message_id.
- *
- * Caller should free all strings in the array and the array itself,
- * (g_ptr_array_free) when done. */
-static GPtrArray *
-find_thread_ids (notmuch_database_t *notmuch,
- GPtrArray *parents,
- const char *message_id)
-{
- Xapian::PostingIterator child, children_end;
- Xapian::Document doc;
- GHashTable *thread_ids;
- GList *keys, *l;
- unsigned int i;
- const char *parent_message_id;
- GPtrArray *result;
-
- thread_ids = g_hash_table_new_full (g_str_hash, g_str_equal,
- free, NULL);
-
- find_doc_ids (notmuch, "ref", message_id, &child, &children_end);
- for ( ; child != children_end; child++) {
- doc = find_document_for_doc_id (notmuch, *child);
- insert_thread_id (thread_ids, doc);
- }
-
- for (i = 0; i < parents->len; i++) {
- notmuch_message_t *parent;
- notmuch_thread_ids_t *ids;
-
- parent_message_id = (char *) g_ptr_array_index (parents, i);
- parent = notmuch_database_find_message (notmuch, parent_message_id);
- if (parent == NULL)
- continue;
-
- for (ids = notmuch_message_get_thread_ids (parent);
- notmuch_thread_ids_has_more (ids);
- notmuch_thread_ids_advance (ids))
- {
- const char *id;
-
- id = notmuch_thread_ids_get (ids);
- g_hash_table_insert (thread_ids, strdup (id), NULL);
- }
-
- notmuch_message_destroy (parent);
- }
-
- result = g_ptr_array_new ();
-
- keys = g_hash_table_get_keys (thread_ids);
- for (l = keys; l; l = l->next) {
- char *id = (char *) l->data;
- g_ptr_array_add (result, id);
- }
- g_list_free (keys);
-
- /* We're done with the hash table, but we've taken the pointers to
- * the allocated strings and put them into our result array, so
- * tell the hash not to free them on its way out. */
- g_hash_table_steal_all (thread_ids);
- g_hash_table_unref (thread_ids);
-
- return result;
-}
-