From 5b016cbc6843029d62f79602a36203d4a4f9e230 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 1 Jul 2021 12:45:47 +0200 Subject: [PATCH] Remove dead code to calculate last message --- src/Cache.cpp | 92 ---------------------------------- src/CacheStructs.h | 2 - src/Cache_p.h | 1 - src/timeline/RoomlistModel.cpp | 6 +-- 4 files changed, 3 insertions(+), 98 deletions(-) diff --git a/src/Cache.cpp b/src/Cache.cpp index 144a2d9a..aba76406 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -1794,8 +1794,6 @@ Cache::roomInfo(bool withInvites) while (roomsCursor.get(room_id, room_data, MDB_NEXT)) { RoomInfo tmp = json::parse(std::move(room_data)); tmp.member_count = getMembersDb(txn, std::string(room_id)).size(txn); - tmp.msgInfo = getLastMessageInfo(txn, std::string(room_id)); - result.insert(QString::fromStdString(std::string(room_id)), std::move(tmp)); } roomsCursor.close(); @@ -2022,96 +2020,6 @@ Cache::getTimelineEventId(const std::string &room_id, uint64_t index) return std::string(val); } -DescInfo -Cache::getLastMessageInfo(lmdb::txn &txn, const std::string &room_id) -{ - lmdb::dbi orderDb; - try { - orderDb = getOrderToMessageDb(txn, room_id); - } catch (lmdb::runtime_error &e) { - nhlog::db()->error("Can't open db for room '{}', probably doesn't exist yet. ({})", - room_id, - e.what()); - return {}; - } - - lmdb::dbi eventsDb; - try { - eventsDb = getEventsDb(txn, room_id); - } catch (lmdb::runtime_error &e) { - nhlog::db()->error("Can't open db for room '{}', probably doesn't exist yet. ({})", - room_id, - e.what()); - return {}; - } - - lmdb::dbi membersdb; - try { - membersdb = getMembersDb(txn, room_id); - } catch (lmdb::runtime_error &e) { - nhlog::db()->error("Can't open db for room '{}', probably doesn't exist yet. ({})", - room_id, - e.what()); - return {}; - } - - if (orderDb.size(txn) == 0) - return DescInfo{}; - - const auto local_user = utils::localUser(); - - DescInfo fallbackDesc{}; - - std::string_view indexVal, event_id; - - auto cursor = lmdb::cursor::open(txn, orderDb); - bool first = true; - while (cursor.get(indexVal, event_id, first ? MDB_LAST : MDB_PREV)) { - first = false; - - std::string_view event; - bool success = eventsDb.get(txn, event_id, event); - if (!success) - continue; - - auto obj = json::parse(event); - - if (fallbackDesc.event_id.isEmpty() && obj["type"] == "m.room.member" && - obj["state_key"] == local_user.toStdString() && - obj["content"]["membership"] == "join") { - uint64_t ts = obj["origin_server_ts"]; - auto time = QDateTime::fromMSecsSinceEpoch(ts); - fallbackDesc = DescInfo{QString::fromStdString(obj["event_id"]), - local_user, - tr("You joined this room."), - utils::descriptiveTime(time), - ts, - time}; - } - - if (!(obj["type"] == "m.room.message" || obj["type"] == "m.sticker" || - obj["type"] == "m.call.invite" || obj["type"] == "m.call.answer" || - obj["type"] == "m.call.hangup" || obj["type"] == "m.room.encrypted")) - continue; - - mtx::events::collections::TimelineEvent te; - mtx::events::collections::from_json(obj, te); - - std::string_view info; - MemberInfo m; - if (membersdb.get(txn, obj["sender"].get(), info)) { - m = json::parse(std::string_view(info.data(), info.size())); - } - - cursor.close(); - return utils::getMessageDescription( - te.data, local_user, QString::fromStdString(m.name)); - } - cursor.close(); - - return fallbackDesc; -} - QHash Cache::invites() { diff --git a/src/CacheStructs.h b/src/CacheStructs.h index 1d0f0d70..28c70055 100644 --- a/src/CacheStructs.h +++ b/src/CacheStructs.h @@ -83,8 +83,6 @@ struct RoomInfo //! Who can access to the room. mtx::events::state::JoinRule join_rule = mtx::events::state::JoinRule::Public; bool guest_access = false; - //! Metadata describing the last message in the timeline. - DescInfo msgInfo; //! The list of tags associated with this room std::vector tags; }; diff --git a/src/Cache_p.h b/src/Cache_p.h index cfcf9c9e..c76cc717 100644 --- a/src/Cache_p.h +++ b/src/Cache_p.h @@ -334,7 +334,6 @@ private: std::optional getMember(const std::string &room_id, const std::string &user_id); std::string getLastEventId(lmdb::txn &txn, const std::string &room_id); - DescInfo getLastMessageInfo(lmdb::txn &txn, const std::string &room_id); void saveTimelineMessages(lmdb::txn &txn, lmdb::dbi &eventsDb, const std::string &room_id, diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp index 7f59b112..6a90ab6e 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp @@ -116,11 +116,11 @@ RoomlistModel::data(const QModelIndex &index, int role) const case Roles::RoomId: return roomid; case Roles::LastMessage: - return room.msgInfo.body; + return QString(); case Roles::Time: - return room.msgInfo.descriptiveTime; + return QString(); case Roles::Timestamp: - return QVariant(static_cast(room.msgInfo.timestamp)); + return QVariant(static_cast(0)); case Roles::HasUnreadMessages: case Roles::HasLoudNotification: return false;