Fix crash when persisting null relations

This commit is contained in:
Nicolas Werner 2021-01-19 14:15:02 +01:00
parent 3d8f16e6c5
commit 5105d2cb96

View file

@ -2689,9 +2689,12 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
if (event.contains("content") &&
event["content"].contains("m.relates_to")) {
auto temp = event["content"]["m.relates_to"];
std::string relates_to = temp.contains("m.in_reply_to")
json relates_to_j = temp.contains("m.in_reply_to") &&
temp["m.in_reply_to"].is_object()
? temp["m.in_reply_to"]["event_id"]
: temp["event_id"];
std::string relates_to =
relates_to_j.is_string() ? relates_to_j.get<std::string>() : "";
if (!relates_to.empty()) {
lmdb::dbi_del(txn,
@ -2781,9 +2784,12 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
if (event.contains("content") &&
event["content"].contains("m.relates_to")) {
auto temp = event["content"]["m.relates_to"];
std::string relates_to = temp.contains("m.in_reply_to")
json relates_to_j = temp.contains("m.in_reply_to") &&
temp["m.in_reply_to"].is_object()
? temp["m.in_reply_to"]["event_id"]
: temp["event_id"];
std::string relates_to =
relates_to_j.is_string() ? relates_to_j.get<std::string>() : "";
if (!relates_to.empty())
lmdb::dbi_put(
@ -2870,9 +2876,12 @@ Cache::saveOldMessages(const std::string &room_id, const mtx::responses::Message
if (event.contains("content") && event["content"].contains("m.relates_to")) {
auto temp = event["content"]["m.relates_to"];
std::string relates_to = temp.contains("m.in_reply_to")
json relates_to_j =
temp.contains("m.in_reply_to") && temp["m.in_reply_to"].is_object()
? temp["m.in_reply_to"]["event_id"]
: temp["event_id"];
std::string relates_to =
relates_to_j.is_string() ? relates_to_j.get<std::string>() : "";
if (!relates_to.empty())
lmdb::dbi_put(txn, relationsDb, lmdb::val(relates_to), event_id);