mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-23 03:18:49 +03:00
Fix potential crash when trying to read room info too early
This commit is contained in:
parent
6e8adc7320
commit
dbea031a86
1 changed files with 22 additions and 16 deletions
|
@ -1586,26 +1586,32 @@ Cache::roomsWithStateUpdates(const mtx::responses::Sync &res)
|
||||||
RoomInfo
|
RoomInfo
|
||||||
Cache::singleRoomInfo(const std::string &room_id)
|
Cache::singleRoomInfo(const std::string &room_id)
|
||||||
{
|
{
|
||||||
auto txn = ro_txn(env_);
|
auto txn = ro_txn(env_);
|
||||||
auto statesdb = getStatesDb(txn, room_id);
|
|
||||||
|
|
||||||
std::string_view data;
|
try {
|
||||||
|
auto statesdb = getStatesDb(txn, room_id);
|
||||||
|
|
||||||
// Check if the room is joined.
|
std::string_view data;
|
||||||
if (roomsDb_.get(txn, room_id, data)) {
|
|
||||||
try {
|
|
||||||
RoomInfo tmp = json::parse(data);
|
|
||||||
tmp.member_count = getMembersDb(txn, room_id).size(txn);
|
|
||||||
tmp.join_rule = getRoomJoinRule(txn, statesdb);
|
|
||||||
tmp.guest_access = getRoomGuestAccess(txn, statesdb);
|
|
||||||
|
|
||||||
return tmp;
|
// Check if the room is joined.
|
||||||
} catch (const json::exception &e) {
|
if (roomsDb_.get(txn, room_id, data)) {
|
||||||
nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}",
|
try {
|
||||||
room_id,
|
RoomInfo tmp = json::parse(data);
|
||||||
std::string(data.data(), data.size()),
|
tmp.member_count = getMembersDb(txn, room_id).size(txn);
|
||||||
e.what());
|
tmp.join_rule = getRoomJoinRule(txn, statesdb);
|
||||||
|
tmp.guest_access = getRoomGuestAccess(txn, statesdb);
|
||||||
|
|
||||||
|
return tmp;
|
||||||
|
} catch (const json::exception &e) {
|
||||||
|
nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}",
|
||||||
|
room_id,
|
||||||
|
std::string(data.data(), data.size()),
|
||||||
|
e.what());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (const lmdb::error &e) {
|
||||||
|
nhlog::db()->warn(
|
||||||
|
"failed to read room info from db: room_id ({}), {}", room_id, e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
return RoomInfo();
|
return RoomInfo();
|
||||||
|
|
Loading…
Reference in a new issue