diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2021-05-24 14:04:07 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2021-05-24 14:04:07 +0200 |
commit | c290b0747f34a6f683365f93d64ce93dc4428ca8 (patch) | |
tree | c53f337a2bb4ad6e1a439277f288119229ec99e8 /src/Cache.cpp | |
parent | Reenable userInfo settings menu (diff) | |
download | nheko-c290b0747f34a6f683365f93d64ce93dc4428ca8.tar.xz |
Reenable invites
Diffstat (limited to 'src/Cache.cpp')
-rw-r--r-- | src/Cache.cpp | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp index c41b66cc..4a99dd59 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -2045,21 +2045,57 @@ Cache::getLastMessageInfo(lmdb::txn &txn, const std::string &room_id) return fallbackDesc; } -std::map<QString, bool> +QHash<QString, RoomInfo> Cache::invites() { - std::map<QString, bool> result; + QHash<QString, RoomInfo> result; auto txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY); auto cursor = lmdb::cursor::open(txn, invitesDb_); - std::string_view room_id, unused; + std::string_view room_id, room_data; - while (cursor.get(room_id, unused, MDB_NEXT)) - result.emplace(QString::fromStdString(std::string(room_id)), true); + while (cursor.get(room_id, room_data, MDB_NEXT)) { + try { + RoomInfo tmp = json::parse(room_data); + tmp.member_count = getInviteMembersDb(txn, std::string(room_id)).size(txn); + result.insert(QString::fromStdString(std::string(room_id)), std::move(tmp)); + } catch (const json::exception &e) { + nhlog::db()->warn("failed to parse room info for invite: " + "room_id ({}), {}: {}", + room_id, + std::string(room_data), + e.what()); + } + } cursor.close(); - txn.commit(); + + return result; +} + +std::optional<RoomInfo> +Cache::invite(std::string_view roomid) +{ + std::optional<RoomInfo> result; + + auto txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY); + + std::string_view room_data; + + if (invitesDb_.get(txn, roomid, room_data)) { + try { + RoomInfo tmp = json::parse(room_data); + tmp.member_count = getInviteMembersDb(txn, std::string(roomid)).size(txn); + result = std::move(tmp); + } catch (const json::exception &e) { + nhlog::db()->warn("failed to parse room info for invite: " + "room_id ({}), {}: {}", + roomid, + std::string(room_data), + e.what()); + } + } return result; } @@ -4064,7 +4100,7 @@ roomInfo(bool withInvites) { return instance_->roomInfo(withInvites); } -std::map<QString, bool> +QHash<QString, RoomInfo> invites() { return instance_->invites(); |