mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Return nullopt for state events in rooms we are not in
This commit is contained in:
parent
a6e633cdab
commit
70592911a1
1 changed files with 33 additions and 33 deletions
|
@ -451,40 +451,40 @@ private:
|
||||||
const std::string &room_id,
|
const std::string &room_id,
|
||||||
std::string_view state_key = "")
|
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);
|
|
||||||
|
|
||||||
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))
|
|
||||||
return std::nullopt;
|
|
||||||
} catch (std::exception &e) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
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.");
|
||||||
|
|
||||||
|
if (room_id.empty())
|
||||||
|
return std::nullopt;
|
||||||
|
const auto typeStr = to_string(type);
|
||||||
|
|
||||||
|
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))
|
||||||
|
return std::nullopt;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return json::parse(value).get<mtx::events::StateEvent<T>>();
|
return json::parse(value).get<mtx::events::StateEvent<T>>();
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|
Loading…
Reference in a new issue