mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
message engine: only save non-empty message lists
Change-Id: I222a7f6aa81ccf40e5c7037b86c26e4c82f5155b
This commit is contained in:
@ -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",
|
||||
|
Reference in New Issue
Block a user