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

@ -2688,10 +2688,13 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
if (event.contains("content") && if (event.contains("content") &&
event["content"].contains("m.relates_to")) { event["content"].contains("m.relates_to")) {
auto temp = event["content"]["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"]["event_id"] temp["m.in_reply_to"].is_object()
: temp["event_id"]; ? 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()) { if (!relates_to.empty()) {
lmdb::dbi_del(txn, lmdb::dbi_del(txn,
@ -2780,10 +2783,13 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
if (event.contains("content") && if (event.contains("content") &&
event["content"].contains("m.relates_to")) { event["content"].contains("m.relates_to")) {
auto temp = event["content"]["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"]["event_id"] temp["m.in_reply_to"].is_object()
: temp["event_id"]; ? 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()) if (!relates_to.empty())
lmdb::dbi_put( lmdb::dbi_put(
@ -2869,10 +2875,13 @@ Cache::saveOldMessages(const std::string &room_id, const mtx::responses::Message
} }
if (event.contains("content") && event["content"].contains("m.relates_to")) { if (event.contains("content") && event["content"].contains("m.relates_to")) {
auto temp = event["content"]["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["m.in_reply_to"]["event_id"] temp.contains("m.in_reply_to") && temp["m.in_reply_to"].is_object()
: temp["event_id"]; ? 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()) if (!relates_to.empty())
lmdb::dbi_put(txn, relationsDb, lmdb::val(relates_to), event_id); lmdb::dbi_put(txn, relationsDb, lmdb::val(relates_to), event_id);