From 473d3998ce9cae1a6eeb51867578af7cb4408834 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Tue, 4 May 2021 17:34:47 +0300 Subject: [PATCH] mu: calculate thread subjects Calculate the thread subject, that is, the subject of the (sub)thread _or_ empty if it's the same as the previous subject. This is for the UI feature of _not_ showing the subject when it's just repeating from the previous. --- lib/mu-query-results.hh | 5 ++--- lib/mu-query-threads.cc | 24 ++++++++++++++++++------ lib/mu-server.cc | 16 ++++++++-------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/lib/mu-query-results.hh b/lib/mu-query-results.hh index 9376938b..30d47140 100644 --- a/lib/mu-query-results.hh +++ b/lib/mu-query-results.hh @@ -91,11 +91,10 @@ struct QueryMatch { // (ignoring prefixes such as Re:) // // otherwise, it is empty. - std::string subject; - std::string thread_subject; /**< the thread subject for this message */ + std::string subject; /**< subject for this message */ size_t thread_level{}; /**< The thread level */ std::string thread_path; /**< The hex-numerial path in the thread, ie. '00:01:0a' */ - std::string thread_date{}; /**< date of newest message in thread */ + std::string thread_date; /**< date of newest message in thread */ bool operator<(const QueryMatch& rhs) const { return date_key < rhs.date_key; diff --git a/lib/mu-query-threads.cc b/lib/mu-query-threads.cc index 947a7e8a..8c4759fc 100644 --- a/lib/mu-query-threads.cc +++ b/lib/mu-query-threads.cc @@ -394,11 +394,20 @@ update_container (Container& container, bool descending, if (!container.children.empty()) qmatch.flags |= QueryMatch::Flags::HasChild; - // calculate the "thread-subject", which is for UI - // purposes (future use) + // see whether this message has the has the thread + // subject, ie.. the first message in this thread with the + // given subject. if (qmatch.has_flag(QueryMatch::Flags::Root) || + //qmatch.has_flag(QueryMatch::Flags::Orphan) || + prev_subject.empty() || (qmatch.subject.find(prev_subject) > 5)) - qmatch.flags |= QueryMatch::Flags::ThreadSubject; + qmatch.flags |= QueryMatch::Flags::ThreadSubject; + + // g_debug ("%c%c: '%s' vs '%s'", + // any_of(qmatch.flags & QueryMatch::Flags::Root) ? 'r' : 'c', + // any_of(qmatch.flags & QueryMatch::Flags::ThreadSubject) ? 'y' : 'n', + // qmatch.subject.c_str(), + // prev_subject.c_str()); if (descending && container.parent) { // trick xapian by giving it "inverse" sorting key so our @@ -422,13 +431,16 @@ update_containers (Containers& children, bool descending, ThreadPath& tpath, size_t seg_size) { size_t idx{0}; + std::string last_subject; for (auto&& c: children) { tpath.emplace_back(idx++); - if (c->query_match) - update_container(*c, descending, tpath, seg_size); - + if (c->query_match) { + update_container(*c, descending, tpath, seg_size, + last_subject); + last_subject = c->query_match->subject; + } update_containers(c->children, descending, tpath, seg_size); tpath.pop_back(); } diff --git a/lib/mu-server.cc b/lib/mu-server.cc index fcf3d82d..32bac340 100644 --- a/lib/mu-server.cc +++ b/lib/mu-server.cc @@ -146,21 +146,21 @@ add_thread_info (Sexp::List& items, const QueryMatch& qmatch) info.add_prop(":date-tstamp", Sexp::make_list(std::move(dlist))); if (qmatch.has_flag(QueryMatch::Flags::Root)) - info.add_prop( ":root", symbol_t()); + info.add_prop(":root", symbol_t()); if (qmatch.has_flag(QueryMatch::Flags::Related)) - info.add_prop( ":related", symbol_t()); + info.add_prop(":related", symbol_t()); if (qmatch.has_flag(QueryMatch::Flags::First)) - info.add_prop( ":first-child", symbol_t()); + info.add_prop(":first-child", symbol_t()); if (qmatch.has_flag(QueryMatch::Flags::Last)) - info.add_prop( ":last-child", symbol_t()); + info.add_prop(":last-child", symbol_t()); if (qmatch.has_flag(QueryMatch::Flags::Orphan)) - info.add_prop( ":orphan", symbol_t()); + info.add_prop(":orphan", symbol_t()); if (qmatch.has_flag(QueryMatch::Flags::Duplicate)) - info.add_prop( ":duplicate", symbol_t()); + info.add_prop(":duplicate", symbol_t()); if (qmatch.has_flag(QueryMatch::Flags::HasChild)) - info.add_prop( ":has-child", symbol_t()); + info.add_prop(":has-child", symbol_t()); if (qmatch.has_flag(QueryMatch::Flags::ThreadSubject)) - info.add_prop( ":thread_subject", symbol_t()); + info.add_prop(":thread-subject", symbol_t()); items.add_prop(":thread", Sexp::make_list(std::move(info))); }