Remove redundant alias function

pull/1101/head
Nicolas Werner 2 years ago
parent b150aea8b9
commit 28acea55e2
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
  1. 25
      src/Cache.cpp
  2. 1
      src/Cache_p.h
  3. 5
      src/ChatPage.cpp
  4. 12
      src/RoomsModel.cpp
  5. 43
      src/dbus/NhekoDBusBackend.cpp
  6. 9
      src/timeline/TimelineModel.cpp

@ -2756,31 +2756,6 @@ Cache::getRoomIsSpace(lmdb::txn &txn, lmdb::dbi &statesdb)
return false; 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 QString
Cache::getInviteRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb) Cache::getInviteRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb)
{ {

@ -68,7 +68,6 @@ public:
std::vector<std::string> joinedRooms(); std::vector<std::string> joinedRooms();
QMap<QString, RoomInfo> roomInfo(bool withInvites = true); QMap<QString, RoomInfo> roomInfo(bool withInvites = true);
std::optional<mtx::events::state::CanonicalAlias> getRoomAliases(const std::string &roomid);
QHash<QString, RoomInfo> invites(); QHash<QString, RoomInfo> invites();
std::optional<RoomInfo> invite(std::string_view roomid); std::optional<RoomInfo> invite(std::string_view roomid);
QMap<QString, std::optional<RoomInfo>> spaces(); QMap<QString, std::optional<RoomInfo>> spaces();

@ -1480,9 +1480,10 @@ ChatPage::handleMatrixUri(QString uri)
auto targetRoomAlias = mxid1.toStdString(); auto targetRoomAlias = mxid1.toStdString();
for (const auto &roomid : joined_rooms) { 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) {
if (aliases->alias == targetRoomAlias) { if (aliases->content.alias == targetRoomAlias) {
view_manager_->rooms()->setCurrentRoom(QString::fromStdString(roomid)); view_manager_->rooms()->setCurrentRoom(QString::fromStdString(roomid));
if (!mxid2.isEmpty()) if (!mxid2.isEmpty())
view_manager_->showEvent(QString::fromStdString(roomid), mxid2); view_manager_->showEvent(QString::fromStdString(roomid), mxid2);

@ -23,17 +23,19 @@ RoomsModel::RoomsModel(bool showOnlyRoomWithAliases, QObject *parent)
} }
for (const auto &r : rooms_) { for (const auto &r : rooms_) {
auto roomAliasesList = cache::client()->getRoomAliases(r); auto roomAliasesList =
cache::client()->getStateEvent<mtx::events::state::CanonicalAlias>(r);
if (showOnlyRoomWithAliases_) { if (showOnlyRoomWithAliases_) {
if (roomAliasesList && !roomAliasesList->alias.empty()) { if (roomAliasesList && !roomAliasesList->content.alias.empty()) {
roomids.push_back(QString::fromStdString(r)); roomids.push_back(QString::fromStdString(r));
roomAliases.push_back(QString::fromStdString(roomAliasesList->alias)); roomAliases.push_back(QString::fromStdString(roomAliasesList->content.alias));
} }
} else { } else {
roomids.push_back(QString::fromStdString(r)); roomids.push_back(QString::fromStdString(r));
roomAliases.push_back(roomAliasesList ? QString::fromStdString(roomAliasesList->alias) roomAliases.push_back(roomAliasesList
: QLatin1String("")); ? QString::fromStdString(roomAliasesList->content.alias)
: QLatin1String(""));
} }
} }
} }

@ -26,29 +26,30 @@ NhekoDBusBackend::rooms(const QDBusMessage &message)
new QVector<nheko::dbus::RoomInfoItem>}; new QVector<nheko::dbus::RoomInfoItem>};
for (const auto &room : roomListModel) { for (const auto &room : roomListModel) {
auto addRoom = auto addRoom = [room, roomListModelSize = roomListModel.size(), message, model](
[room, roomListModelSize = roomListModel.size(), message, model](const QImage &image) { const QImage &image) {
const auto aliases = cache::client()->getRoomAliases(room->roomId().toStdString()); const auto aliases = cache::client()->getStateEvent<mtx::events::state::CanonicalAlias>(
QString alias; room->roomId().toStdString());
if (aliases.has_value()) { QString alias;
const auto &val = aliases.value(); if (aliases.has_value()) {
if (!val.alias.empty()) const auto &val = aliases.value().content;
alias = QString::fromStdString(val.alias); if (!val.alias.empty())
else if (val.alt_aliases.size() > 0) alias = QString::fromStdString(val.alias);
alias = QString::fromStdString(val.alt_aliases.front()); else if (val.alt_aliases.size() > 0)
} alias = QString::fromStdString(val.alt_aliases.front());
}
model->push_back(nheko::dbus::RoomInfoItem{ model->push_back(nheko::dbus::RoomInfoItem{
room->roomId(), alias, room->roomName(), image, room->notificationCount()}); room->roomId(), alias, room->roomName(), image, room->notificationCount()});
if (model->length() == roomListModelSize) { if (model->length() == roomListModelSize) {
auto reply = message.createReply(); auto reply = message.createReply();
nhlog::ui()->debug("Sending {} rooms over D-Bus...", model->size()); nhlog::ui()->debug("Sending {} rooms over D-Bus...", model->size());
reply << QVariant::fromValue(*model); reply << QVariant::fromValue(*model);
QDBusConnection::sessionBus().send(reply); QDBusConnection::sessionBus().send(reply);
nhlog::ui()->debug("Rooms successfully sent to D-Bus."); nhlog::ui()->debug("Rooms successfully sent to D-Bus.");
} }
}; };
auto avatarUrl = room->roomAvatarUrl(); auto avatarUrl = room->roomAvatarUrl();
if (avatarUrl.isEmpty()) if (avatarUrl.isEmpty())

@ -1761,12 +1761,13 @@ TimelineModel::copyLinkToEvent(const QString &eventId) const
{ {
QStringList vias; QStringList vias;
auto alias = cache::client()->getRoomAliases(room_id_.toStdString()); auto alias =
cache::client()->getStateEvent<mtx::events::state::CanonicalAlias>(room_id_.toStdString());
QString room; QString room;
if (alias) { if (alias) {
room = QString::fromStdString(alias->alias); room = QString::fromStdString(alias->content.alias);
if (room.isEmpty() && !alias->alt_aliases.empty()) { if (room.isEmpty() && !alias->content.alt_aliases.empty()) {
room = QString::fromStdString(alias->alt_aliases.front()); room = QString::fromStdString(alias->content.alt_aliases.front());
} }
} }

Loading…
Cancel
Save