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;
}
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)
{

@ -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();

@ -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);

@ -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(""));
}
}
}

@ -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())

@ -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());
}
}

Loading…
Cancel
Save