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.
This commit is contained in:
Dirk-Jan C. Binnema
2021-05-04 17:34:47 +03:00
parent 6d67e146fe
commit 473d3998ce
3 changed files with 28 additions and 17 deletions

View File

@ -91,11 +91,10 @@ struct QueryMatch {
// (ignoring prefixes such as Re:) // (ignoring prefixes such as Re:)
// //
// otherwise, it is empty. // otherwise, it is empty.
std::string subject; std::string subject; /**< subject for this message */
std::string thread_subject; /**< the thread subject for this message */
size_t thread_level{}; /**< The thread level */ 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_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 { bool operator<(const QueryMatch& rhs) const {
return date_key < rhs.date_key; return date_key < rhs.date_key;

View File

@ -394,11 +394,20 @@ update_container (Container& container, bool descending,
if (!container.children.empty()) if (!container.children.empty())
qmatch.flags |= QueryMatch::Flags::HasChild; qmatch.flags |= QueryMatch::Flags::HasChild;
// calculate the "thread-subject", which is for UI // see whether this message has the has the thread
// purposes (future use) // subject, ie.. the first message in this thread with the
// given subject.
if (qmatch.has_flag(QueryMatch::Flags::Root) || if (qmatch.has_flag(QueryMatch::Flags::Root) ||
//qmatch.has_flag(QueryMatch::Flags::Orphan) ||
prev_subject.empty() ||
(qmatch.subject.find(prev_subject) > 5)) (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) { if (descending && container.parent) {
// trick xapian by giving it "inverse" sorting key so our // 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 seg_size)
{ {
size_t idx{0}; size_t idx{0};
std::string last_subject;
for (auto&& c: children) { for (auto&& c: children) {
tpath.emplace_back(idx++); tpath.emplace_back(idx++);
if (c->query_match) if (c->query_match) {
update_container(*c, descending, tpath, seg_size); update_container(*c, descending, tpath, seg_size,
last_subject);
last_subject = c->query_match->subject;
}
update_containers(c->children, descending, tpath, seg_size); update_containers(c->children, descending, tpath, seg_size);
tpath.pop_back(); tpath.pop_back();
} }

View File

@ -146,21 +146,21 @@ add_thread_info (Sexp::List& items, const QueryMatch& qmatch)
info.add_prop(":date-tstamp", Sexp::make_list(std::move(dlist))); info.add_prop(":date-tstamp", Sexp::make_list(std::move(dlist)));
if (qmatch.has_flag(QueryMatch::Flags::Root)) 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)) 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)) 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)) 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)) 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)) 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)) 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)) 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))); items.add_prop(":thread", Sexp::make_list(std::move(info)));
} }