summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2022-01-03 03:57:57 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2022-01-03 03:57:57 +0100
commitf14f978c481b9b0031591d8356d422c2e943fa9d (patch)
tree6d75ba47e16198e81ddd9704656fbcb309275ee1 /src
parentFix download icon size (diff)
downloadnheko-f14f978c481b9b0031591d8356d422c2e943fa9d.tar.xz
Possibly fix crash on accepting invites
fixes #857
Diffstat (limited to 'src')
-rw-r--r--src/Cache.cpp52
1 files changed, 28 insertions, 24 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp

index cf8a808b..d04da275 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp
@@ -2788,40 +2788,44 @@ Cache::getMembers(const std::string &room_id, std::size_t startIndex, std::size_ std::vector<RoomMember> Cache::getMembersFromInvite(const std::string &room_id, std::size_t startIndex, std::size_t len) { - auto txn = ro_txn(env_); - auto db = getInviteMembersDb(txn, room_id); - auto cursor = lmdb::cursor::open(txn, db); + auto txn = ro_txn(env_); + std::vector<RoomMember> members; - std::size_t currentIndex = 0; + try { + auto db = getInviteMembersDb(txn, room_id); + auto cursor = lmdb::cursor::open(txn, db); - const auto endIndex = std::min(startIndex + len, db.size(txn)); + std::size_t currentIndex = 0; - std::vector<RoomMember> members; + const auto endIndex = std::min(startIndex + len, db.size(txn)); - std::string_view user_id, user_data; - while (cursor.get(user_id, user_data, MDB_NEXT)) { - if (currentIndex < startIndex) { - currentIndex += 1; - continue; - } + std::string_view user_id, user_data; + while (cursor.get(user_id, user_data, MDB_NEXT)) { + if (currentIndex < startIndex) { + currentIndex += 1; + continue; + } - if (currentIndex >= endIndex) - break; + if (currentIndex >= endIndex) + break; - try { - MemberInfo tmp = json::parse(user_data); - members.emplace_back(RoomMember{QString::fromStdString(std::string(user_id)), - QString::fromStdString(tmp.name), - tmp.is_direct}); - } catch (const json::exception &e) { - nhlog::db()->warn("{}", e.what()); + try { + MemberInfo tmp = json::parse(user_data); + members.emplace_back(RoomMember{QString::fromStdString(std::string(user_id)), + QString::fromStdString(tmp.name), + tmp.is_direct}); + } catch (const json::exception &e) { + nhlog::db()->warn("{}", e.what()); + } + + currentIndex += 1; } - currentIndex += 1; + cursor.close(); + } catch (const lmdb::error &e) { + nhlog::db()->warn("Failed to retrieve members {}", e.what()); } - cursor.close(); - return members; }