lib: implement mu_store_update

This commit is contained in:
Dirk-Jan C. Binnema 2020-06-10 09:04:47 +03:00
parent 2ee65f5b1a
commit fe6582c6d6
2 changed files with 28 additions and 1 deletions

View File

@ -343,12 +343,29 @@ Store::add_message (const std::string& path)
const auto docid{add_or_update_msg (store, 0, msg, &gerr)};
mu_msg_unref (msg);
if (G_UNLIKELY(docid == MU_STORE_INVALID_DOCID))
throw Error{Error::Code::Message, "failed to store message: %s",
throw Error{Error::Code::Message, "failed to add message: %s",
gerr ? gerr->message : "something went wrong"};
return docid;
}
bool
Store::update_message (MuMsg *msg, unsigned docid)
{
auto store{reinterpret_cast<MuStore*>(this)}; // yuk.
GError *gerr{};
const auto docid2{add_or_update_msg (store, docid, msg, &gerr)};
if (G_UNLIKELY(docid != docid2))
throw Error{Error::Code::Internal, "failed to update message",
gerr ? gerr->message : "something went wrong"};
return true;
}
bool
Store::remove_message (const std::string& path)
{

View File

@ -122,6 +122,16 @@ public:
*/
unsigned add_message (const std::string& path);
/**
* Update a message in the store.
*
* @param msg a message
* @param docid a docid
*
* @return false in case of failure; true ottherwise.
*/
bool update_message (MuMsg *msg, unsigned docid);
/**
* Add a message to the store.
*