diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2021-11-21 20:10:19 +0100 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2021-11-21 20:10:43 +0100 |
commit | 70592911a17aa683c2aae229c1510d4954c13ee5 (patch) | |
tree | 004b56c826c84f2f19a9acab0d64d8988be470ea /src/Cache_p.h | |
parent | Translated using Weblate (French) (diff) | |
download | nheko-70592911a17aa683c2aae229c1510d4954c13ee5.tar.xz |
Return nullopt for state events in rooms we are not in
Diffstat (limited to 'src/Cache_p.h')
-rw-r--r-- | src/Cache_p.h | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/src/Cache_p.h b/src/Cache_p.h index b995eed1..67185298 100644 --- a/src/Cache_p.h +++ b/src/Cache_p.h @@ -451,40 +451,40 @@ private: const std::string &room_id, std::string_view state_key = "") { - constexpr auto type = mtx::events::state_content_to_type<T>; - static_assert(type != mtx::events::EventType::Unsupported, - "Not a supported type in state events."); - - if (room_id.empty()) - return std::nullopt; - const auto typeStr = to_string(type); + try { + constexpr auto type = mtx::events::state_content_to_type<T>; + static_assert(type != mtx::events::EventType::Unsupported, + "Not a supported type in state events."); - std::string_view value; - if (state_key.empty()) { - auto db = getStatesDb(txn, room_id); - if (!db.get(txn, typeStr, value)) { + if (room_id.empty()) return std::nullopt; - } - } else { - auto db = getStatesKeyDb(txn, room_id); - std::string d = json::object({{"key", state_key}}).dump(); - std::string_view data = d; - std::string_view typeStrV = typeStr; + const auto typeStr = to_string(type); - auto cursor = lmdb::cursor::open(txn, db); - if (!cursor.get(typeStrV, data, MDB_GET_BOTH)) - return std::nullopt; + std::string_view value; + if (state_key.empty()) { + auto db = getStatesDb(txn, room_id); + if (!db.get(txn, typeStr, value)) { + return std::nullopt; + } + } else { + auto db = getStatesKeyDb(txn, room_id); + std::string d = json::object({{"key", state_key}}).dump(); + std::string_view data = d; + std::string_view typeStrV = typeStr; + + auto cursor = lmdb::cursor::open(txn, db); + if (!cursor.get(typeStrV, data, MDB_GET_BOTH)) + return std::nullopt; - try { - auto eventsDb = getEventsDb(txn, room_id); - if (!eventsDb.get(txn, json::parse(data)["id"].get<std::string>(), value)) + try { + auto eventsDb = getEventsDb(txn, room_id); + if (!eventsDb.get(txn, json::parse(data)["id"].get<std::string>(), value)) + return std::nullopt; + } catch (std::exception &e) { return std::nullopt; - } catch (std::exception &e) { - return std::nullopt; + } } - } - try { return json::parse(value).get<mtx::events::StateEvent<T>>(); } catch (std::exception &e) { return std::nullopt; |