]> granicus.if.org Git - neomutt/commitdiff
mutt_link_threads: factor out Context
authorRichard Russon <rich@flatcap.org>
Thu, 10 Jan 2019 15:27:30 +0000 (15:27 +0000)
committerRichard Russon <rich@flatcap.org>
Fri, 8 Feb 2019 14:34:07 +0000 (14:34 +0000)
index.c
mutt_thread.c
mutt_thread.h

diff --git a/index.c b/index.c
index d97496aaf993bcbeca7121282470ffb949ba3a57..a6ed03ff43d24187f3fce6e2d4dffc1388481833 100644 (file)
--- a/index.c
+++ b/index.c
@@ -2406,8 +2406,10 @@ int mutt_index_menu(void)
         else
         {
           struct Email *oldcur = CUR_EMAIL;
+          struct EmailList el = STAILQ_HEAD_INITIALIZER(el);
+          el_add_tagged(&el, Context, Context->last_tag, tag);
 
-          if (mutt_link_threads(CUR_EMAIL, tag ? NULL : Context->last_tag, Context))
+          if (mutt_link_threads(CUR_EMAIL, &el, Context->mailbox))
           {
             mutt_sort_headers(Context, true);
             menu->current = oldcur->virtual;
@@ -2417,6 +2419,8 @@ int mutt_index_menu(void)
           }
           else
             mutt_error(_("No thread linked"));
+
+          el_free(&el);
         }
 
         if (menu->menu == MENU_PAGER)
index 5478e1522f76618ee018bf29d362b361a20d264e..5c551fbcd7bddde759c3f9a4f6e0483a8d489d8c 100644 (file)
@@ -1451,8 +1451,8 @@ struct Hash *mutt_make_id_hash(struct Mailbox *m)
 
 /**
  * link_threads - Forcibly link messages together
- * @param parent Header of parent message
- * @param child  Header of child message
+ * @param parent Parent Email
+ * @param child  Child Email
  * @param m      Mailbox
  * @retval true On success
  */
@@ -1472,30 +1472,23 @@ static bool link_threads(struct Email *parent, struct Email *child, struct Mailb
 
 /**
  * mutt_link_threads - Forcibly link threads together
- * @param cur  Header of current message
- * @param last Header of thread to link (OPTIONAL)
- * @param ctx  Mailbox
+ * @param parent   Parent Email
+ * @param children List of children Emails
+ * @param m        Mailbox
  * @retval true On success
- *
- * if last is omitted, all the tagged threads will be used.
  */
-bool mutt_link_threads(struct Email *cur, struct Email *last, struct Context *ctx)
+bool mutt_link_threads(struct Email *parent, struct EmailList *children, struct Mailbox *m)
 {
-  if (!ctx || !ctx->mailbox)
+  if (!parent || !children || !m)
     return false;
 
-  struct Mailbox *m = ctx->mailbox;
-
   bool changed = false;
 
-  if (!last)
+  struct EmailNode *en = NULL;
+  STAILQ_FOREACH(en, children, entries)
   {
-    for (int i = 0; i < m->msg_count; i++)
-      if (message_is_tagged(ctx, i))
-        changed |= link_threads(cur, m->emails[i], ctx->mailbox);
+    changed |= link_threads(parent, en->email, m);
   }
-  else
-    changed = link_threads(cur, last, ctx->mailbox);
 
   return changed;
 }
index 2cf9bedfd574d5c5691411f247fe445c5adf561c..fb1c4f58a4e95bda3283302682e88abfc50e3f48 100644 (file)
@@ -63,7 +63,7 @@ int mutt_traverse_thread(struct Context *ctx, struct Email *cur, int flag);
 #define mutt_thread_contains_flagged(x, y) mutt_traverse_thread(x, y, MUTT_THREAD_FLAGGED)
 #define mutt_thread_next_unread(x, y)      mutt_traverse_thread(x, y, MUTT_THREAD_NEXT_UNREAD)
 
-bool mutt_link_threads(struct Email *cur, struct Email *last, struct Context *ctx);
+bool mutt_link_threads(struct Email *parent, struct EmailList *children, struct Mailbox *m);
 int mutt_messages_in_thread(struct Mailbox *m, struct Email *e, int flag);
 void mutt_draw_tree(struct Context *ctx);