diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-06-16 01:49:51 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-06-17 03:14:48 +0200 |
commit | 28acea55e2efd76dd85bba4f343a668c3015db3b (patch) | |
tree | 68f43d66ea938357d7e4649daaf5dbc661811045 | |
parent | Translated using Weblate (Finnish) (diff) | |
download | nheko-28acea55e2efd76dd85bba4f343a668c3015db3b.tar.xz |
Remove redundant alias function
Diffstat (limited to '')
-rw-r--r-- | src/Cache.cpp | 25 | ||||
-rw-r--r-- | src/Cache_p.h | 1 | ||||
-rw-r--r-- | src/ChatPage.cpp | 5 | ||||
-rw-r--r-- | src/RoomsModel.cpp | 12 | ||||
-rw-r--r-- | src/dbus/NhekoDBusBackend.cpp | 43 | ||||
-rw-r--r-- | src/timeline/TimelineModel.cpp | 9 |
6 files changed, 37 insertions, 58 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp index 2b83fbb5..756e50ad 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -2756,31 +2756,6 @@ Cache::getRoomIsSpace(lmdb::txn &txn, lmdb::dbi &statesdb) return false; } -std::optional<mtx::events::state::CanonicalAlias> -Cache::getRoomAliases(const std::string &roomid) -{ - using namespace mtx::events; - using namespace mtx::events::state; - - auto txn = ro_txn(env_); - auto statesdb = getStatesDb(txn, roomid); - - std::string_view event; - bool res = statesdb.get(txn, to_string(mtx::events::EventType::RoomCanonicalAlias), event); - - if (res) { - try { - StateEvent<CanonicalAlias> msg = json::parse(event); - - return msg.content; - } catch (const json::exception &e) { - nhlog::db()->warn("failed to parse m.room.canonical_alias event: {}", e.what()); - } - } - - return std::nullopt; -} - QString Cache::getInviteRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb) { diff --git a/src/Cache_p.h b/src/Cache_p.h index 67755575..7addb1e4 100644 --- a/src/Cache_p.h +++ b/src/Cache_p.h @@ -68,7 +68,6 @@ public: std::vector<std::string> joinedRooms(); QMap<QString, RoomInfo> roomInfo(bool withInvites = true); - std::optional<mtx::events::state::CanonicalAlias> getRoomAliases(const std::string &roomid); QHash<QString, RoomInfo> invites(); std::optional<RoomInfo> invite(std::string_view roomid); QMap<QString, std::optional<RoomInfo>> spaces(); diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index ed1bafd2..d42d0a61 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -1480,9 +1480,10 @@ ChatPage::handleMatrixUri(QString uri) auto targetRoomAlias = mxid1.toStdString(); for (const auto &roomid : joined_rooms) { - auto aliases = cache::client()->getRoomAliases(roomid); + auto aliases = + cache::client()->getStateEvent<mtx::events::state::CanonicalAlias>(roomid); if (aliases) { - if (aliases->alias == targetRoomAlias) { + if (aliases->content.alias == targetRoomAlias) { view_manager_->rooms()->setCurrentRoom(QString::fromStdString(roomid)); if (!mxid2.isEmpty()) view_manager_->showEvent(QString::fromStdString(roomid), mxid2); diff --git a/src/RoomsModel.cpp b/src/RoomsModel.cpp index 782c4971..68cfaf1b 100644 --- a/src/RoomsModel.cpp +++ b/src/RoomsModel.cpp @@ -23,17 +23,19 @@ RoomsModel::RoomsModel(bool showOnlyRoomWithAliases, QObject *parent) } for (const auto &r : rooms_) { - auto roomAliasesList = cache::client()->getRoomAliases(r); + auto roomAliasesList = + cache::client()->getStateEvent<mtx::events::state::CanonicalAlias>(r); if (showOnlyRoomWithAliases_) { - if (roomAliasesList && !roomAliasesList->alias.empty()) { + if (roomAliasesList && !roomAliasesList->content.alias.empty()) { roomids.push_back(QString::fromStdString(r)); - roomAliases.push_back(QString::fromStdString(roomAliasesList->alias)); + roomAliases.push_back(QString::fromStdString(roomAliasesList->content.alias)); } } else { roomids.push_back(QString::fromStdString(r)); - roomAliases.push_back(roomAliasesList ? QString::fromStdString(roomAliasesList->alias) - : QLatin1String("")); + roomAliases.push_back(roomAliasesList + ? QString::fromStdString(roomAliasesList->content.alias) + : QLatin1String("")); } } } diff --git a/src/dbus/NhekoDBusBackend.cpp b/src/dbus/NhekoDBusBackend.cpp index f0ed9df1..836475ee 100644 --- a/src/dbus/NhekoDBusBackend.cpp +++ b/src/dbus/NhekoDBusBackend.cpp @@ -26,29 +26,30 @@ NhekoDBusBackend::rooms(const QDBusMessage &message) new QVector<nheko::dbus::RoomInfoItem>}; for (const auto &room : roomListModel) { - auto addRoom = - [room, roomListModelSize = roomListModel.size(), message, model](const QImage &image) { - const auto aliases = cache::client()->getRoomAliases(room->roomId().toStdString()); - QString alias; - if (aliases.has_value()) { - const auto &val = aliases.value(); - if (!val.alias.empty()) - alias = QString::fromStdString(val.alias); - else if (val.alt_aliases.size() > 0) - alias = QString::fromStdString(val.alt_aliases.front()); - } + auto addRoom = [room, roomListModelSize = roomListModel.size(), message, model]( + const QImage &image) { + const auto aliases = cache::client()->getStateEvent<mtx::events::state::CanonicalAlias>( + room->roomId().toStdString()); + QString alias; + if (aliases.has_value()) { + const auto &val = aliases.value().content; + if (!val.alias.empty()) + alias = QString::fromStdString(val.alias); + else if (val.alt_aliases.size() > 0) + alias = QString::fromStdString(val.alt_aliases.front()); + } - model->push_back(nheko::dbus::RoomInfoItem{ - room->roomId(), alias, room->roomName(), image, room->notificationCount()}); + model->push_back(nheko::dbus::RoomInfoItem{ + room->roomId(), alias, room->roomName(), image, room->notificationCount()}); - if (model->length() == roomListModelSize) { - auto reply = message.createReply(); - nhlog::ui()->debug("Sending {} rooms over D-Bus...", model->size()); - reply << QVariant::fromValue(*model); - QDBusConnection::sessionBus().send(reply); - nhlog::ui()->debug("Rooms successfully sent to D-Bus."); - } - }; + if (model->length() == roomListModelSize) { + auto reply = message.createReply(); + nhlog::ui()->debug("Sending {} rooms over D-Bus...", model->size()); + reply << QVariant::fromValue(*model); + QDBusConnection::sessionBus().send(reply); + nhlog::ui()->debug("Rooms successfully sent to D-Bus."); + } + }; auto avatarUrl = room->roomAvatarUrl(); if (avatarUrl.isEmpty()) diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 2151a4ae..8e9a21db 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -1761,12 +1761,13 @@ TimelineModel::copyLinkToEvent(const QString &eventId) const { QStringList vias; - auto alias = cache::client()->getRoomAliases(room_id_.toStdString()); + auto alias = + cache::client()->getStateEvent<mtx::events::state::CanonicalAlias>(room_id_.toStdString()); QString room; if (alias) { - room = QString::fromStdString(alias->alias); - if (room.isEmpty() && !alias->alt_aliases.empty()) { - room = QString::fromStdString(alias->alt_aliases.front()); + room = QString::fromStdString(alias->content.alias); + if (room.isEmpty() && !alias->content.alt_aliases.empty()) { + room = QString::fromStdString(alias->content.alt_aliases.front()); } } |