Skip to content
Snippets Groups Projects
Verified Commit 70592911 authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Return nullopt for state events in rooms we are not in

parent a6e633cd
No related branches found
No related tags found
No related merge requests found
Pipeline #2143 passed
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment