From 713f9dbe892c1df2f01ffdfd83030dfb409c32e9 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 27 Jun 2019 20:53:44 +0200 Subject: [PATCH] Show room version in settings --- resources/langs/nheko_de.ts | 23 +++++++++--- resources/langs/nheko_el.ts | 23 +++++++++--- resources/langs/nheko_en.ts | 23 +++++++++--- resources/langs/nheko_fr.ts | 23 +++++++++--- resources/langs/nheko_nl.ts | 23 +++++++++--- resources/langs/nheko_pl.ts | 23 +++++++++--- resources/langs/nheko_ru.ts | 23 +++++++++--- resources/langs/nheko_zh_CN.ts | 23 +++++++++--- src/Cache.cpp | 64 ++++++++++++++++++++++++++++++++++ src/Cache.h | 40 +++++---------------- src/dialogs/RoomSettings.cpp | 11 ++++++ 11 files changed, 227 insertions(+), 72 deletions(-) diff --git a/resources/langs/nheko_de.ts b/resources/langs/nheko_de.ts index e8d71f27..60deb89f 100644 --- a/resources/langs/nheko_de.ts +++ b/resources/langs/nheko_de.ts @@ -142,7 +142,7 @@ LoginPage - + Matrix ID Matrix-ID @@ -167,17 +167,17 @@ ANMELDEN - + Autodiscovery failed. Received malformed response. - + Autodiscovery failed. Unknown error when requesting .well-known. - + The required endpoints were not found. Possibly not a Matrix server. @@ -274,6 +274,14 @@ + + RoomInfo + + + no version stored + + + RoomInfoListItem @@ -802,6 +810,11 @@ Medien-Größe: %2 Internal ID + + + Room Version + + Notifications @@ -878,7 +891,7 @@ Medien-Größe: %2 - + ESC diff --git a/resources/langs/nheko_el.ts b/resources/langs/nheko_el.ts index 276d25f0..5a6be4cb 100644 --- a/resources/langs/nheko_el.ts +++ b/resources/langs/nheko_el.ts @@ -142,7 +142,7 @@ LoginPage - + Matrix ID Matrix ID @@ -167,17 +167,17 @@ ΕΙΣΟΔΟΣ - + Autodiscovery failed. Received malformed response. - + Autodiscovery failed. Unknown error when requesting .well-known. - + The required endpoints were not found. Possibly not a Matrix server. @@ -274,6 +274,14 @@ + + RoomInfo + + + no version stored + + + RoomInfoListItem @@ -800,6 +808,11 @@ Media size: %2 Internal ID + + + Room Version + + Notifications @@ -876,7 +889,7 @@ Media size: %2 - + ESC diff --git a/resources/langs/nheko_en.ts b/resources/langs/nheko_en.ts index ffca0843..f0aa0c35 100644 --- a/resources/langs/nheko_en.ts +++ b/resources/langs/nheko_en.ts @@ -142,7 +142,7 @@ LoginPage - + Matrix ID @@ -167,17 +167,17 @@ - + Autodiscovery failed. Received malformed response. - + Autodiscovery failed. Unknown error when requesting .well-known. - + The required endpoints were not found. Possibly not a Matrix server. @@ -274,6 +274,14 @@ + + RoomInfo + + + no version stored + + + RoomInfoListItem @@ -800,6 +808,11 @@ Media size: %2 Internal ID + + + Room Version + + Notifications @@ -876,7 +889,7 @@ Media size: %2 - + ESC diff --git a/resources/langs/nheko_fr.ts b/resources/langs/nheko_fr.ts index 0826acad..beab8752 100644 --- a/resources/langs/nheko_fr.ts +++ b/resources/langs/nheko_fr.ts @@ -142,7 +142,7 @@ LoginPage - + Matrix ID Identifiant Matrix @@ -167,17 +167,17 @@ CONNEXION - + Autodiscovery failed. Received malformed response. - + Autodiscovery failed. Unknown error when requesting .well-known. - + The required endpoints were not found. Possibly not a Matrix server. @@ -275,6 +275,14 @@ + + RoomInfo + + + no version stored + + + RoomInfoListItem @@ -803,6 +811,11 @@ Taille du média : %2 Internal ID + + + Room Version + + Notifications @@ -879,7 +892,7 @@ Taille du média : %2 - + ESC diff --git a/resources/langs/nheko_nl.ts b/resources/langs/nheko_nl.ts index d91e883d..4c81ec76 100644 --- a/resources/langs/nheko_nl.ts +++ b/resources/langs/nheko_nl.ts @@ -142,7 +142,7 @@ LoginPage - + Matrix ID Matrix-id @@ -167,17 +167,17 @@ INLOGGEN - + Autodiscovery failed. Received malformed response. - + Autodiscovery failed. Unknown error when requesting .well-known. - + The required endpoints were not found. Possibly not a Matrix server. @@ -274,6 +274,14 @@ + + RoomInfo + + + no version stored + + + RoomInfoListItem @@ -802,6 +810,11 @@ Mediagrootte: %2 Internal ID + + + Room Version + + Notifications @@ -878,7 +891,7 @@ Mediagrootte: %2 - + ESC diff --git a/resources/langs/nheko_pl.ts b/resources/langs/nheko_pl.ts index 358f97a9..edea85b9 100644 --- a/resources/langs/nheko_pl.ts +++ b/resources/langs/nheko_pl.ts @@ -142,7 +142,7 @@ LoginPage - + Matrix ID ID Matrixa @@ -167,17 +167,17 @@ ZALOGUJ - + Autodiscovery failed. Received malformed response. - + Autodiscovery failed. Unknown error when requesting .well-known. - + The required endpoints were not found. Possibly not a Matrix server. Nie odnaleziono wymaganych punktów końcowych. To może nie być serwer Matriksa. @@ -274,6 +274,14 @@ Wyloguj + + RoomInfo + + + no version stored + + + RoomInfoListItem @@ -802,6 +810,11 @@ Rozmiar multimediów: %2 Internal ID Wewnętrzne ID + + + Room Version + + Notifications @@ -881,7 +894,7 @@ Rozmiar multimediów: %2 - + ESC diff --git a/resources/langs/nheko_ru.ts b/resources/langs/nheko_ru.ts index b6651c84..4c157884 100644 --- a/resources/langs/nheko_ru.ts +++ b/resources/langs/nheko_ru.ts @@ -142,7 +142,7 @@ LoginPage - + Matrix ID Идентификатор Matrix @@ -167,17 +167,17 @@ ВОЙТИ - + Autodiscovery failed. Received malformed response. - + Autodiscovery failed. Unknown error when requesting .well-known. - + The required endpoints were not found. Possibly not a Matrix server. Необходимые конечные точки не найдены. Возможно, это не сервер Matrix. @@ -274,6 +274,14 @@ Выйти + + RoomInfo + + + no version stored + + + RoomInfoListItem @@ -803,6 +811,11 @@ Media size: %2 Internal ID Внутренний ID + + + Room Version + + Notifications @@ -880,7 +893,7 @@ Media size: %2 - + ESC diff --git a/resources/langs/nheko_zh_CN.ts b/resources/langs/nheko_zh_CN.ts index 634867a5..ca7c6e22 100644 --- a/resources/langs/nheko_zh_CN.ts +++ b/resources/langs/nheko_zh_CN.ts @@ -142,7 +142,7 @@ LoginPage - + Matrix ID @@ -167,17 +167,17 @@ 登录 - + Autodiscovery failed. Received malformed response. - + Autodiscovery failed. Unknown error when requesting .well-known. - + The required endpoints were not found. Possibly not a Matrix server. 没找到要求的终端。可能不是一个 Matrix 服务器。 @@ -274,6 +274,14 @@ 登出 + + RoomInfo + + + no version stored + + + RoomInfoListItem @@ -802,6 +810,11 @@ Media size: %2 Internal ID 内部 ID + + + Room Version + + Notifications @@ -879,7 +892,7 @@ Media size: %2 - + ESC diff --git a/src/Cache.cpp b/src/Cache.cpp index 81054ddc..5aad89ed 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -958,6 +959,7 @@ Cache::saveState(const mtx::responses::Sync &res) updatedInfo.avatar_url = getRoomAvatarUrl(txn, statesdb, membersdb, QString::fromStdString(room.first)) .toStdString(); + updatedInfo.version = getRoomVersion(txn, statesdb).toStdString(); // Process the account_data associated with this room bool has_new_tags = false; @@ -1551,6 +1553,32 @@ Cache::getRoomTopic(lmdb::txn &txn, lmdb::dbi &statesdb) return QString(); } +QString +Cache::getRoomVersion(lmdb::txn &txn, lmdb::dbi &statesdb) +{ + using namespace mtx::events; + using namespace mtx::events::state; + + lmdb::val event; + bool res = lmdb::dbi_get( + txn, statesdb, lmdb::val(to_string(mtx::events::EventType::RoomCreate)), event); + + if (res) { + try { + StateEvent msg = + json::parse(std::string(event.data(), event.size())); + + if (!msg.content.room_version.empty()) + return QString::fromStdString(msg.content.room_version); + } catch (const json::exception &e) { + nhlog::db()->warn("failed to parse m.room.create event: {}", e.what()); + } + } + + nhlog::db()->warn("m.room.create event is missing room version, assuming version \"1\""); + return QString("1"); +} + QString Cache::getInviteRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb) { @@ -2148,3 +2176,39 @@ Cache::clearUserColors() { UserColors.clear(); } + +void +to_json(json &j, const RoomInfo &info) +{ + j["name"] = info.name; + j["topic"] = info.topic; + j["avatar_url"] = info.avatar_url; + j["version"] = info.version; + j["is_invite"] = info.is_invite; + j["join_rule"] = info.join_rule; + j["guest_access"] = info.guest_access; + + if (info.member_count != 0) + j["member_count"] = info.member_count; + + if (info.tags.size() != 0) + j["tags"] = info.tags; +} + +void +from_json(const json &j, RoomInfo &info) +{ + info.name = j.at("name"); + info.topic = j.at("topic"); + info.avatar_url = j.at("avatar_url"); + info.version = j.value("version", QCoreApplication::translate("RoomInfo", "no version stored").toStdString()); + info.is_invite = j.at("is_invite"); + info.join_rule = j.at("join_rule"); + info.guest_access = j.at("guest_access"); + + if (j.count("member_count")) + info.member_count = j.at("member_count"); + + if (j.count("tags")) + info.tags = j.at("tags").get>(); +} diff --git a/src/Cache.h b/src/Cache.h index b9cf0aeb..65c5263d 100644 --- a/src/Cache.h +++ b/src/Cache.h @@ -106,6 +106,8 @@ struct RoomInfo std::string topic; //! The calculated avatar url of the room. std::string avatar_url; + //! The calculated version of this room set at creation time. + std::string version; //! Whether or not the room is an invite. bool is_invite = false; //! Total number of members in the room. @@ -119,39 +121,11 @@ struct RoomInfo std::vector tags; }; -inline void -to_json(json &j, const RoomInfo &info) -{ - j["name"] = info.name; - j["topic"] = info.topic; - j["avatar_url"] = info.avatar_url; - j["is_invite"] = info.is_invite; - j["join_rule"] = info.join_rule; - j["guest_access"] = info.guest_access; +void +to_json(json &j, const RoomInfo &info); - if (info.member_count != 0) - j["member_count"] = info.member_count; - - if (info.tags.size() != 0) - j["tags"] = info.tags; -} - -inline void -from_json(const json &j, RoomInfo &info) -{ - info.name = j.at("name"); - info.topic = j.at("topic"); - info.avatar_url = j.at("avatar_url"); - info.is_invite = j.at("is_invite"); - info.join_rule = j.at("join_rule"); - info.guest_access = j.at("guest_access"); - - if (j.count("member_count")) - info.member_count = j.at("member_count"); - - if (j.count("tags")) - info.tags = j.at("tags").get>(); -} +void +from_json(const json &j, RoomInfo &info); //! Basic information per member; struct MemberInfo @@ -322,6 +296,8 @@ public: lmdb::dbi &statesdb, lmdb::dbi &membersdb, const QString &room_id); + //! Retrieve the version of the room if any. + QString getRoomVersion(lmdb::txn &txn, lmdb::dbi &statesdb); //! Retrieve member info from a room. std::vector getMembers(const std::string &room_id, diff --git a/src/dialogs/RoomSettings.cpp b/src/dialogs/RoomSettings.cpp index f9b7e913..a34b44f0 100644 --- a/src/dialogs/RoomSettings.cpp +++ b/src/dialogs/RoomSettings.cpp @@ -199,6 +199,16 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) Qt::AlignBottom | Qt::AlignLeft); roomIdLayout->addWidget(roomIdLabel, 0, Qt::AlignBottom | Qt::AlignRight); + auto roomVersionLabel = new QLabel(QString::fromStdString(info_.version), this); + roomVersionLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); + roomVersionLabel->setFont(monospaceFont); + + auto roomVersionLayout = new QHBoxLayout; + roomVersionLayout->setMargin(0); + roomVersionLayout->addWidget(new QLabel(tr("Room Version"), this), + Qt::AlignBottom | Qt::AlignLeft); + roomVersionLayout->addWidget(roomVersionLabel, 0, Qt::AlignBottom | Qt::AlignRight); + auto notifLabel = new QLabel(tr("Notifications"), this); auto notifCombo = new QComboBox(this); notifCombo->setDisabled(true); @@ -400,6 +410,7 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) layout->addLayout(keyRequestsLayout); layout->addWidget(infoLabel, Qt::AlignLeft); layout->addLayout(roomIdLayout); + layout->addLayout(roomVersionLayout); layout->addWidget(errorLabel_); layout->addLayout(buttonLayout); layout->addLayout(spinnerLayout);