From 5a951b768eb3f546327da938267c7d2b6b680de7 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 1 Jun 2017 18:53:14 +0200 Subject: [PATCH] make modify-labels-then-hide hide or unhide 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 | 8 +++++-- mutt_notmuch.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ mutt_notmuch.h | 1 + 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/curs_main.c b/curs_main.c index 3df269a36..fec967e7d 100644 --- a/curs_main.c +++ b/curs_main.c @@ -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) diff --git a/mutt_notmuch.c b/mutt_notmuch.c index c7d9f8db0..c2a2d83dd 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -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) { diff --git a/mutt_notmuch.h b/mutt_notmuch.h index 03ddee814..1e749e424 100644 --- a/mutt_notmuch.h +++ b/mutt_notmuch.h @@ -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); -- 2.49.0