Skip to content
Snippets Groups Projects
Commit 3ef2038a authored by Adrien Béraud's avatar Adrien Béraud
Browse files

message engine: only save non-empty message lists

Change-Id: I222a7f6aa81ccf40e5c7037b86c26e4c82f5155b
parent ff66cac2
Branches
No related tags found
No related merge requests found
......@@ -305,34 +305,35 @@ MessageEngine::save_() const
payloads[p.first] = p.second;
peerRoot[to_hex_string(m.first)] = std::move(msg);
}
if (peerRoot.size() == 0) continue;
root[c.first] = std::move(peerRoot);
}
// Save asynchronously
dht::ThreadPool::computation().run([path = savePath_,
root = std::move(root),
accountID = account_.getAccountID(),
messageNum = messages_.size()] {
accountID = account_.getAccountID()] {
std::lock_guard<std::mutex> lock(fileutils::getFileLock(path));
try {
Json::StreamWriterBuilder wbuilder;
wbuilder["commentStyle"] = "None";
wbuilder["indentation"] = "";
const std::unique_ptr<Json::StreamWriter> writer(wbuilder.newStreamWriter());
std::unique_ptr<Json::StreamWriter> writer(wbuilder.newStreamWriter());
std::ofstream file;
file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
fileutils::openStream(file, path, std::ios::trunc);
if (file.is_open())
writer->write(root, &file);
} catch (const std::exception& e) {
JAMI_ERR("[Account %s] Couldn't save messages to %s: %s",
accountID.c_str(),
path.c_str(),
JAMI_ERROR("[Account {:s}] Couldn't save messages to {:s}: {:s}",
accountID,
path,
e.what());
}
JAMI_DBG("[Account %s] saved %zu messages to %s",
accountID.c_str(),
messageNum,
path.c_str());
JAMI_DEBUG("[Account {:s}] saved {:d} messages to {:s}",
accountID,
root.size(),
path);
});
} catch (const std::exception& e) {
JAMI_ERR("[Account %s] couldn't save messages to %s: %s",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment