]> granicus.if.org Git - neomutt/commitdiff
make modify-labels-then-hide hide or unhide 602/head
authorJulian Andres Klode <jak@jak-linux.org>
Thu, 1 Jun 2017 16:53:14 +0000 (18:53 +0200)
committerRichard Russon <rich@flatcap.org>
Sat, 24 Jun 2017 12:26:07 +0000 (13:26 +0100)
If the message is no longer in the current query after modifying
the label it will be hidden as before, but if it is in the current
query (again), it will be unhidden.

Related to #601

curs_main.c
mutt_notmuch.c
mutt_notmuch.h

index 3df269a36d2db38a1efb22f7a3e0d0267c10be45..fec967e7d7505f9e30c9c88ca55be3d668b4da51 100644 (file)
@@ -1864,9 +1864,12 @@ int mutt_index_menu(void)
               if (!Context->quiet)
                 mutt_progress_update(&progress, ++px, -1);
               nm_modify_message_tags(Context, Context->hdrs[Context->v2r[j]], buf);
+
+              bool still_queried =
+                  nm_message_is_still_queried(Context, Context->hdrs[Context->v2r[j]]);
               if (op == OP_MAIN_MODIFY_LABELS_THEN_HIDE)
               {
-                Context->hdrs[Context->v2r[j]]->quasi_deleted = true;
+                Context->hdrs[Context->v2r[j]]->quasi_deleted = !still_queried;
                 Context->changed = true;
               }
             }
@@ -1883,7 +1886,8 @@ int mutt_index_menu(void)
           }
           if (op == OP_MAIN_MODIFY_LABELS_THEN_HIDE)
           {
-            CURHDR->quasi_deleted = true;
+            bool still_queried = nm_message_is_still_queried(Context, CURHDR);
+            CURHDR->quasi_deleted = !still_queried;
             Context->changed = true;
           }
           if (menu->menu == MENU_PAGER)
index c7d9f8db0be5a6edcae20cd74e66e7c9884b156c..c2a2d83dd63015687eaed1381a9a1cf939f130a9 100644 (file)
@@ -1899,6 +1899,66 @@ done:
   return rc;
 }
 
+bool nm_message_is_still_queried(struct Context *ctx, struct Header *hdr)
+{
+  char *orig_str = NULL;
+  char *new_str = NULL;
+  struct NmCtxdata *data = get_ctxdata(ctx);
+  notmuch_database_t *db = NULL;
+  notmuch_query_t *q = NULL;
+  bool result = false;
+
+  db = get_db(data, false);
+  orig_str = get_query_string(data, true);
+
+  if (!db || !orig_str)
+    return false;
+
+  if (safe_asprintf(&new_str, "id:%s and (%s)", header_get_id(hdr), orig_str) < 0)
+    return false;
+
+  mutt_debug(2, "nm: checking if message is still queried: %s\n", new_str);
+
+  q = notmuch_query_create(db, new_str);
+
+  switch (get_query_type(data))
+  {
+    case NM_QUERY_TYPE_MESGS:
+    {
+      notmuch_messages_t *messages = NULL;
+#if LIBNOTMUCH_CHECK_VERSION(4, 3, 0)
+      if (notmuch_query_search_messages_st(q, &messages) != NOTMUCH_STATUS_SUCCESS)
+        return false;
+#else
+      messages = notmuch_query_search_messages(q);
+#endif
+      result = notmuch_messages_valid(messages);
+      notmuch_messages_destroy(messages);
+      break;
+    }
+    case NM_QUERY_TYPE_THREADS:
+    {
+      notmuch_threads_t *threads = NULL;
+#if LIBNOTMUCH_CHECK_VERSION(4, 3, 0)
+      if (notmuch_query_search_threads_st(q, &threads) != NOTMUCH_STATUS_SUCCESS)
+        return false;
+#else
+      threads = notmuch_query_search_threads(q);
+#endif
+      result = notmuch_threads_valid(threads);
+      notmuch_threads_destroy(threads);
+      break;
+    }
+  }
+
+  notmuch_query_destroy(q);
+
+  mutt_debug(2, "nm: checking if message is still queried: %s = %s\n", new_str,
+             result ? "true" : "false");
+
+  return result;
+}
+
 int nm_update_filename(struct Context *ctx, const char *old, const char *new,
                        struct Header *h)
 {
index 03ddee814f95750d021616927849cfba16bcc4c7..1e749e424f546e49ff893faef6f31fc56cb3d513 100644 (file)
@@ -32,6 +32,7 @@ int nm_update_filename(struct Context *ctx, const char *old, const char *new, st
 bool nm_normalize_uri(char *new_uri, const char *orig_uri, size_t new_uri_sz);
 char *nm_uri_from_query(struct Context *ctx, char *buf, size_t bufsz);
 int nm_modify_message_tags(struct Context *ctx, struct Header *hdr, char *buf);
+bool nm_message_is_still_queried(struct Context *ctx, struct Header *hdr);
 
 void nm_query_window_backward(void);
 void nm_query_window_forward(void);