diff --git a/resources/langs/nheko_de.ts b/resources/langs/nheko_de.ts index e8d71f2745996cfeb7ed5aaae5daa16b7f80be03..60deb89fa4c03ebb9d0b81d625834f89d666eded 100644 --- a/resources/langs/nheko_de.ts +++ b/resources/langs/nheko_de.ts @@ -142,7 +142,7 @@ <context> <name>LoginPage</name> <message> - <location filename="../../src/LoginPage.cpp" line="+79"/> + <location filename="../../src/LoginPage.cpp" line="+80"/> <source>Matrix ID</source> <translation>Matrix-ID</translation> </message> @@ -167,17 +167,17 @@ <translation>ANMELDEN</translation> </message> <message> - <location line="+83"/> + <location line="+84"/> <source>Autodiscovery failed. Received malformed response.</source> <translation type="unfinished"></translation> </message> <message> - <location line="+4"/> + <location line="+6"/> <source>Autodiscovery failed. Unknown error when requesting .well-known.</source> <translation type="unfinished"></translation> </message> <message> - <location line="+20"/> + <location line="+24"/> <source>The required endpoints were not found. Possibly not a Matrix server.</source> <translation type="unfinished"></translation> </message> @@ -274,6 +274,14 @@ <translation type="unfinished"></translation> </message> </context> +<context> + <name>RoomInfo</name> + <message> + <location filename="../../src/Cache.cpp" line="+2204"/> + <source>no version stored</source> + <translation type="unfinished"></translation> + </message> +</context> <context> <name>RoomInfoListItem</name> <message> @@ -802,6 +810,11 @@ Medien-Größe: %2 <source>Internal ID</source> <translation type="unfinished"></translation> </message> + <message> + <location line="+10"/> + <source>Room Version</source> + <translation type="unfinished"></translation> + </message> <message> <location line="+4"/> <source>Notifications</source> @@ -878,7 +891,7 @@ Medien-Größe: %2 </translation> </message> <message> - <location line="+70"/> + <location line="+71"/> <source>ESC</source> <translation type="unfinished"></translation> </message> diff --git a/resources/langs/nheko_el.ts b/resources/langs/nheko_el.ts index 276d25f03473de90950e4957c9bcc0ad25bde006..5a6be4cb88ff4bb81e79116327b421b14c060b40 100644 --- a/resources/langs/nheko_el.ts +++ b/resources/langs/nheko_el.ts @@ -142,7 +142,7 @@ <context> <name>LoginPage</name> <message> - <location filename="../../src/LoginPage.cpp" line="+79"/> + <location filename="../../src/LoginPage.cpp" line="+80"/> <source>Matrix ID</source> <translation>Matrix ID</translation> </message> @@ -167,17 +167,17 @@ <translation>ΕΙΣΟΔΟΣ</translation> </message> <message> - <location line="+83"/> + <location line="+84"/> <source>Autodiscovery failed. Received malformed response.</source> <translation type="unfinished"></translation> </message> <message> - <location line="+4"/> + <location line="+6"/> <source>Autodiscovery failed. Unknown error when requesting .well-known.</source> <translation type="unfinished"></translation> </message> <message> - <location line="+20"/> + <location line="+24"/> <source>The required endpoints were not found. Possibly not a Matrix server.</source> <translation type="unfinished"></translation> </message> @@ -274,6 +274,14 @@ <translation type="unfinished"></translation> </message> </context> +<context> + <name>RoomInfo</name> + <message> + <location filename="../../src/Cache.cpp" line="+2204"/> + <source>no version stored</source> + <translation type="unfinished"></translation> + </message> +</context> <context> <name>RoomInfoListItem</name> <message> @@ -800,6 +808,11 @@ Media size: %2 <source>Internal ID</source> <translation type="unfinished"></translation> </message> + <message> + <location line="+10"/> + <source>Room Version</source> + <translation type="unfinished"></translation> + </message> <message> <location line="+4"/> <source>Notifications</source> @@ -876,7 +889,7 @@ Media size: %2 </translation> </message> <message> - <location line="+70"/> + <location line="+71"/> <source>ESC</source> <translation type="unfinished"></translation> </message> diff --git a/resources/langs/nheko_en.ts b/resources/langs/nheko_en.ts index ffca08437ddc0cebdc4140a3f218730b36fa575a..f0aa0c352ddafbe45503e7be356701a648791512 100644 --- a/resources/langs/nheko_en.ts +++ b/resources/langs/nheko_en.ts @@ -142,7 +142,7 @@ <context> <name>LoginPage</name> <message> - <location filename="../../src/LoginPage.cpp" line="+79"/> + <location filename="../../src/LoginPage.cpp" line="+80"/> <source>Matrix ID</source> <translation type="unfinished"></translation> </message> @@ -167,17 +167,17 @@ <translation type="unfinished"></translation> </message> <message> - <location line="+83"/> + <location line="+84"/> <source>Autodiscovery failed. Received malformed response.</source> <translation type="unfinished"></translation> </message> <message> - <location line="+4"/> + <location line="+6"/> <source>Autodiscovery failed. Unknown error when requesting .well-known.</source> <translation type="unfinished"></translation> </message> <message> - <location line="+20"/> + <location line="+24"/> <source>The required endpoints were not found. Possibly not a Matrix server.</source> <translation type="unfinished"></translation> </message> @@ -274,6 +274,14 @@ <translation type="unfinished"></translation> </message> </context> +<context> + <name>RoomInfo</name> + <message> + <location filename="../../src/Cache.cpp" line="+2204"/> + <source>no version stored</source> + <translation type="unfinished"></translation> + </message> +</context> <context> <name>RoomInfoListItem</name> <message> @@ -800,6 +808,11 @@ Media size: %2 <source>Internal ID</source> <translation type="unfinished"></translation> </message> + <message> + <location line="+10"/> + <source>Room Version</source> + <translation type="unfinished"></translation> + </message> <message> <location line="+4"/> <source>Notifications</source> @@ -876,7 +889,7 @@ Media size: %2 </translation> </message> <message> - <location line="+70"/> + <location line="+71"/> <source>ESC</source> <translation type="unfinished"></translation> </message> diff --git a/resources/langs/nheko_fr.ts b/resources/langs/nheko_fr.ts index 0826acada228ee070cf02d0bbe5f7bebfde9a2d8..beab87521dd26c10129275c24a7fff75f2fa5e64 100644 --- a/resources/langs/nheko_fr.ts +++ b/resources/langs/nheko_fr.ts @@ -142,7 +142,7 @@ <context> <name>LoginPage</name> <message> - <location filename="../../src/LoginPage.cpp" line="+79"/> + <location filename="../../src/LoginPage.cpp" line="+80"/> <source>Matrix ID</source> <translation>Identifiant Matrix</translation> </message> @@ -167,17 +167,17 @@ <translation>CONNEXION</translation> </message> <message> - <location line="+83"/> + <location line="+84"/> <source>Autodiscovery failed. Received malformed response.</source> <translation type="unfinished"></translation> </message> <message> - <location line="+4"/> + <location line="+6"/> <source>Autodiscovery failed. Unknown error when requesting .well-known.</source> <translation type="unfinished"></translation> </message> <message> - <location line="+20"/> + <location line="+24"/> <source>The required endpoints were not found. Possibly not a Matrix server.</source> <translation type="unfinished"></translation> </message> @@ -275,6 +275,14 @@ <translation type="unfinished"></translation> </message> </context> +<context> + <name>RoomInfo</name> + <message> + <location filename="../../src/Cache.cpp" line="+2204"/> + <source>no version stored</source> + <translation type="unfinished"></translation> + </message> +</context> <context> <name>RoomInfoListItem</name> <message> @@ -803,6 +811,11 @@ Taille du média : %2 <source>Internal ID</source> <translation type="unfinished"></translation> </message> + <message> + <location line="+10"/> + <source>Room Version</source> + <translation type="unfinished"></translation> + </message> <message> <location line="+4"/> <source>Notifications</source> @@ -879,7 +892,7 @@ Taille du média : %2 </translation> </message> <message> - <location line="+70"/> + <location line="+71"/> <source>ESC</source> <translation type="unfinished"></translation> </message> diff --git a/resources/langs/nheko_nl.ts b/resources/langs/nheko_nl.ts index d91e883d7a9f59ffd6e43a5940464a52ef217aec..4c81ec7619fda0ea202b553f6f2dc3edd0628954 100644 --- a/resources/langs/nheko_nl.ts +++ b/resources/langs/nheko_nl.ts @@ -142,7 +142,7 @@ <context> <name>LoginPage</name> <message> - <location filename="../../src/LoginPage.cpp" line="+79"/> + <location filename="../../src/LoginPage.cpp" line="+80"/> <source>Matrix ID</source> <translation>Matrix-id</translation> </message> @@ -167,17 +167,17 @@ <translation>INLOGGEN</translation> </message> <message> - <location line="+83"/> + <location line="+84"/> <source>Autodiscovery failed. Received malformed response.</source> <translation type="unfinished"></translation> </message> <message> - <location line="+4"/> + <location line="+6"/> <source>Autodiscovery failed. Unknown error when requesting .well-known.</source> <translation type="unfinished"></translation> </message> <message> - <location line="+20"/> + <location line="+24"/> <source>The required endpoints were not found. Possibly not a Matrix server.</source> <translation type="unfinished"></translation> </message> @@ -274,6 +274,14 @@ <translation type="unfinished"></translation> </message> </context> +<context> + <name>RoomInfo</name> + <message> + <location filename="../../src/Cache.cpp" line="+2204"/> + <source>no version stored</source> + <translation type="unfinished"></translation> + </message> +</context> <context> <name>RoomInfoListItem</name> <message> @@ -802,6 +810,11 @@ Mediagrootte: %2 <source>Internal ID</source> <translation type="unfinished"></translation> </message> + <message> + <location line="+10"/> + <source>Room Version</source> + <translation type="unfinished"></translation> + </message> <message> <location line="+4"/> <source>Notifications</source> @@ -878,7 +891,7 @@ Mediagrootte: %2 </translation> </message> <message> - <location line="+70"/> + <location line="+71"/> <source>ESC</source> <translation type="unfinished"></translation> </message> diff --git a/resources/langs/nheko_pl.ts b/resources/langs/nheko_pl.ts index 358f97a97caacea8e7aea0127f6f4a0ccba0f753..edea85b925a7d7ba9d7eb5380a7b1f3ddf483e60 100644 --- a/resources/langs/nheko_pl.ts +++ b/resources/langs/nheko_pl.ts @@ -142,7 +142,7 @@ <context> <name>LoginPage</name> <message> - <location filename="../../src/LoginPage.cpp" line="+79"/> + <location filename="../../src/LoginPage.cpp" line="+80"/> <source>Matrix ID</source> <translation>ID Matrixa</translation> </message> @@ -167,17 +167,17 @@ <translation>ZALOGUJ</translation> </message> <message> - <location line="+83"/> + <location line="+84"/> <source>Autodiscovery failed. Received malformed response.</source> <translation type="unfinished"></translation> </message> <message> - <location line="+4"/> + <location line="+6"/> <source>Autodiscovery failed. Unknown error when requesting .well-known.</source> <translation type="unfinished"></translation> </message> <message> - <location line="+20"/> + <location line="+24"/> <source>The required endpoints were not found. Possibly not a Matrix server.</source> <translation>Nie odnaleziono wymaganych punktów koÅ„cowych. To może nie być serwer Matriksa.</translation> </message> @@ -274,6 +274,14 @@ <translation type="unfinished">Wyloguj</translation> </message> </context> +<context> + <name>RoomInfo</name> + <message> + <location filename="../../src/Cache.cpp" line="+2204"/> + <source>no version stored</source> + <translation type="unfinished"></translation> + </message> +</context> <context> <name>RoomInfoListItem</name> <message> @@ -802,6 +810,11 @@ Rozmiar multimediów: %2 <source>Internal ID</source> <translation>WewnÄ™trzne ID</translation> </message> + <message> + <location line="+10"/> + <source>Room Version</source> + <translation type="unfinished"></translation> + </message> <message> <location line="+4"/> <source>Notifications</source> @@ -881,7 +894,7 @@ Rozmiar multimediów: %2 </translation> </message> <message> - <location line="+70"/> + <location line="+71"/> <source>ESC</source> <translation type="unfinished"></translation> </message> diff --git a/resources/langs/nheko_ru.ts b/resources/langs/nheko_ru.ts index b6651c84493199086395f5e6f60018eeeb8f2fc1..4c1578848a0f87cc99237421567ec5985cde7105 100644 --- a/resources/langs/nheko_ru.ts +++ b/resources/langs/nheko_ru.ts @@ -142,7 +142,7 @@ <context> <name>LoginPage</name> <message> - <location filename="../../src/LoginPage.cpp" line="+79"/> + <location filename="../../src/LoginPage.cpp" line="+80"/> <source>Matrix ID</source> <translation>Идентификатор Matrix</translation> </message> @@ -167,17 +167,17 @@ <translation>ВОЙТИ</translation> </message> <message> - <location line="+83"/> + <location line="+84"/> <source>Autodiscovery failed. Received malformed response.</source> <translation type="unfinished"></translation> </message> <message> - <location line="+4"/> + <location line="+6"/> <source>Autodiscovery failed. Unknown error when requesting .well-known.</source> <translation type="unfinished"></translation> </message> <message> - <location line="+20"/> + <location line="+24"/> <source>The required endpoints were not found. Possibly not a Matrix server.</source> <translation>Ðеобходимые конечные точки не найдены. Возможно, Ñто не Ñервер Matrix.</translation> </message> @@ -274,6 +274,14 @@ <translation type="unfinished">Выйти</translation> </message> </context> +<context> + <name>RoomInfo</name> + <message> + <location filename="../../src/Cache.cpp" line="+2204"/> + <source>no version stored</source> + <translation type="unfinished"></translation> + </message> +</context> <context> <name>RoomInfoListItem</name> <message> @@ -803,6 +811,11 @@ Media size: %2 <source>Internal ID</source> <translation>Внутренний ID</translation> </message> + <message> + <location line="+10"/> + <source>Room Version</source> + <translation type="unfinished"></translation> + </message> <message> <location line="+4"/> <source>Notifications</source> @@ -880,7 +893,7 @@ Media size: %2 </translation> </message> <message> - <location line="+70"/> + <location line="+71"/> <source>ESC</source> <translation></translation> </message> diff --git a/resources/langs/nheko_zh_CN.ts b/resources/langs/nheko_zh_CN.ts index 634867a54527aee7c0ae3e6d8db67ee5b92d514a..ca7c6e2209107a70d267c3f3ea47f4faaa8b1ec4 100644 --- a/resources/langs/nheko_zh_CN.ts +++ b/resources/langs/nheko_zh_CN.ts @@ -142,7 +142,7 @@ <context> <name>LoginPage</name> <message> - <location filename="../../src/LoginPage.cpp" line="+79"/> + <location filename="../../src/LoginPage.cpp" line="+80"/> <source>Matrix ID</source> <translation></translation> </message> @@ -167,17 +167,17 @@ <translation>登录</translation> </message> <message> - <location line="+83"/> + <location line="+84"/> <source>Autodiscovery failed. Received malformed response.</source> <translation type="unfinished"></translation> </message> <message> - <location line="+4"/> + <location line="+6"/> <source>Autodiscovery failed. Unknown error when requesting .well-known.</source> <translation type="unfinished"></translation> </message> <message> - <location line="+20"/> + <location line="+24"/> <source>The required endpoints were not found. Possibly not a Matrix server.</source> <translation>æ²¡æ‰¾åˆ°è¦æ±‚的终端。å¯èƒ½ä¸æ˜¯ä¸€ä¸ª Matrix æœåŠ¡å™¨ã€‚</translation> </message> @@ -274,6 +274,14 @@ <translation type="unfinished">登出</translation> </message> </context> +<context> + <name>RoomInfo</name> + <message> + <location filename="../../src/Cache.cpp" line="+2204"/> + <source>no version stored</source> + <translation type="unfinished"></translation> + </message> +</context> <context> <name>RoomInfoListItem</name> <message> @@ -802,6 +810,11 @@ Media size: %2 <source>Internal ID</source> <translation>内部 ID</translation> </message> + <message> + <location line="+10"/> + <source>Room Version</source> + <translation type="unfinished"></translation> + </message> <message> <location line="+4"/> <source>Notifications</source> @@ -879,7 +892,7 @@ Media size: %2 </translation> </message> <message> - <location line="+70"/> + <location line="+71"/> <source>ESC</source> <translation type="unfinished"></translation> </message> diff --git a/src/Cache.cpp b/src/Cache.cpp index 81054ddce9999a25db012c960cb7ad776c71b451..5aad89ed261176fce4c8468749b11a2a515fa842 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -19,6 +19,7 @@ #include <stdexcept> #include <QByteArray> +#include <QCoreApplication> #include <QFile> #include <QHash> #include <QSettings> @@ -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<Create> 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<std::vector<std::string>>(); +} diff --git a/src/Cache.h b/src/Cache.h index b9cf0aebd742cb3f1ad99fcfc6b270ca69cc5055..65c5263d8c1cfe6fe4983646fec99bb4f80d5e97 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<std::string> 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; - - if (info.member_count != 0) - j["member_count"] = info.member_count; - - if (info.tags.size() != 0) - j["tags"] = info.tags; -} +void +to_json(json &j, const RoomInfo &info); -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<std::vector<std::string>>(); -} +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<RoomMember> getMembers(const std::string &room_id, diff --git a/src/dialogs/RoomSettings.cpp b/src/dialogs/RoomSettings.cpp index f9b7e9134aa2a66ccf7256986f8b139277ce5e93..a34b44f0a3ba2e525978afc9d7f57881d740b5da 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);