server: when marking-as-read, include duplicates
When marking a message a read, do the same for the duplicates; this was the old behavior and the intention of the new behavior but didn't quite work. Fixes: #2071.
This commit is contained in:
@ -20,6 +20,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "mu-msg-fields.h"
|
#include "mu-msg-fields.h"
|
||||||
|
#include "mu-msg.hh"
|
||||||
#include "mu-server.hh"
|
#include "mu-server.hh"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -106,7 +107,6 @@ struct Server::Private {
|
|||||||
void sent_handler (const Parameters& params);
|
void sent_handler (const Parameters& params);
|
||||||
void view_handler (const Parameters& params);
|
void view_handler (const Parameters& params);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// helpers
|
// helpers
|
||||||
Sexp build_message_sexp(MuMsg *msg, unsigned docid,
|
Sexp build_message_sexp(MuMsg *msg, unsigned docid,
|
||||||
@ -119,6 +119,9 @@ private:
|
|||||||
const std::string& maildirarg,
|
const std::string& maildirarg,
|
||||||
MuFlags flags, bool new_name, bool no_view);
|
MuFlags flags, bool new_name, bool no_view);
|
||||||
|
|
||||||
|
bool maybe_mark_as_read (MuMsg *msg, Store::Id docid);
|
||||||
|
bool maybe_mark_msgid_as_read (const Mu::Query& query, const char* msgid);
|
||||||
|
|
||||||
Store& store_;
|
Store& store_;
|
||||||
Server::Output output_;
|
Server::Output output_;
|
||||||
const CommandMap command_map_;
|
const CommandMap command_map_;
|
||||||
@ -1127,13 +1130,12 @@ Server::Private::sent_handler (const Parameters& params)
|
|||||||
output_sexp (std::move(lst));
|
output_sexp (std::move(lst));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
|
||||||
maybe_mark_as_read (Mu::Store& store, MuMsg *msg, Store::Id docid)
|
bool
|
||||||
|
Server::Private::maybe_mark_as_read (MuMsg *msg, Store::Id docid)
|
||||||
{
|
{
|
||||||
if (!msg)
|
if (!msg)
|
||||||
throw Error{Error::Code::Store, "missing message"};
|
throw Error{Error::Code::Store, "missing message"};
|
||||||
if (docid == Store::InvalidId)
|
|
||||||
throw Error{Error::Code::Store, "invalid docid"};
|
|
||||||
|
|
||||||
const auto oldflags{mu_msg_get_flags (msg)};
|
const auto oldflags{mu_msg_get_flags (msg)};
|
||||||
const auto newflags{get_flags (mu_msg_get_path(msg), "+S-u-N")};
|
const auto newflags{get_flags (mu_msg_get_path(msg), "+S-u-N")};
|
||||||
@ -1149,31 +1151,60 @@ maybe_mark_as_read (Mu::Store& store, MuMsg *msg, Store::Id docid)
|
|||||||
&gerr))
|
&gerr))
|
||||||
throw Error{Error::Code::File, &gerr, "failed to move message"};
|
throw Error{Error::Code::File, &gerr, "failed to move message"};
|
||||||
|
|
||||||
/* after mu_msg_move_to_maildir, path will be the *new* path, and flags
|
/* after mu_msg_move_to_maildir, path will be the *new* path, and flags and maildir fields
|
||||||
* and maildir fields will be updated as wel */
|
* will be updated as wel */
|
||||||
if (!store.update_message (msg, docid))
|
if (!store().update_message (msg, docid))
|
||||||
throw Error{Error::Code::Store, "failed to store updated message"};
|
throw Error{Error::Code::Store, "failed to store updated message"};
|
||||||
|
|
||||||
|
/* send an update */
|
||||||
|
Sexp::List update;
|
||||||
|
update.add_prop(":update", build_message_sexp(msg, docid, {}, MU_MSG_OPTION_NONE));
|
||||||
|
output_sexp(Sexp::make_list(std::move(update)));
|
||||||
|
|
||||||
g_debug ("marked message %d as read => %s", docid, mu_msg_get_path(msg));
|
g_debug ("marked message %d as read => %s", docid, mu_msg_get_path(msg));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Server::Private::maybe_mark_msgid_as_read (const Mu::Query& query, const char* msgid)
|
||||||
|
{
|
||||||
|
if (!msgid)
|
||||||
|
return false; // nothing to do.
|
||||||
|
|
||||||
|
const auto docids{docids_for_msgid(query, std::string{msgid})};
|
||||||
|
for (auto&& docid: docids) {
|
||||||
|
MuMsg *msg = store().find_message(docid);
|
||||||
|
if (!msg)
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
maybe_mark_as_read(msg, docid);
|
||||||
|
} catch (...) {
|
||||||
|
mu_msg_unref(msg);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Server::Private::view_handler (const Parameters& params)
|
Server::Private::view_handler (const Parameters& params)
|
||||||
{
|
{
|
||||||
std::vector<Store::Id> docids;
|
Store::Id docid{Store::InvalidId};
|
||||||
const auto path{get_string_or(params, ":path")};
|
const auto path{get_string_or(params, ":path")};
|
||||||
const auto mark_as_read{get_bool_or(params, ":mark-as-read")};
|
const auto mark_as_read{get_bool_or(params, ":mark-as-read")};
|
||||||
|
|
||||||
GError *gerr{};
|
GError *gerr{};
|
||||||
MuMsg *msg{};
|
MuMsg *msg{};
|
||||||
|
|
||||||
if (!path.empty()) {
|
if (!path.empty()) { /* only use for old view (embedded msgs) */
|
||||||
/* only use for old view (embedded msgs) */
|
docid = Store::InvalidId;
|
||||||
msg = mu_msg_new_from_file (path.c_str(), NULL, &gerr);
|
msg = mu_msg_new_from_file (path.c_str(), NULL, &gerr);
|
||||||
} else {
|
} else {
|
||||||
docids = determine_docids(query(), params);
|
docid = determine_docids(query(), params).at(0);
|
||||||
msg = store().find_message(docids.at(0));
|
msg = store().find_message(docid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!msg)
|
if (!msg)
|
||||||
@ -1181,16 +1212,16 @@ Server::Private::view_handler (const Parameters& params)
|
|||||||
"failed to find message for view"};
|
"failed to find message for view"};
|
||||||
|
|
||||||
if (mark_as_read) {
|
if (mark_as_read) {
|
||||||
/* mark _all_ messsage with given docid as read. */
|
// maybe mark the main message as read.
|
||||||
for (auto&& docid: docids)
|
maybe_mark_as_read(msg, docid);
|
||||||
maybe_mark_as_read (store(), msg, docid);
|
/* maybe mark _all_ messsage with same message-id as read */
|
||||||
|
maybe_mark_msgid_as_read(query(), mu_msg_get_msgid(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
Sexp::List seq;
|
Sexp::List seq;
|
||||||
seq.add_prop(":view", build_message_sexp(
|
seq.add_prop(":view", build_message_sexp(
|
||||||
msg, docids.at(0), {}, message_options(params)));
|
msg, docid, {}, message_options(params)));
|
||||||
mu_msg_unref(msg);
|
mu_msg_unref(msg);
|
||||||
|
|
||||||
output_sexp (std::move(seq));
|
output_sexp (std::move(seq));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user