From 7de1fc62e8a90bc571b342e8990e3890f7f5ffc1 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 18 May 2020 03:30:04 +0200 Subject: [PATCH 1/3] Tag rooms via context menu --- CMakeLists.txt | 2 +- io.github.NhekoReborn.Nheko.json | 4 +- resources/langs/nheko_de.ts | 73 +++++++++++++++++---- resources/langs/nheko_el.ts | 73 +++++++++++++++++---- resources/langs/nheko_en.ts | 73 +++++++++++++++++---- resources/langs/nheko_fi.ts | 73 +++++++++++++++++---- resources/langs/nheko_fr.ts | 73 +++++++++++++++++---- resources/langs/nheko_ja.ts | 73 +++++++++++++++++---- resources/langs/nheko_nl.ts | 73 +++++++++++++++++---- resources/langs/nheko_pl.ts | 73 +++++++++++++++++---- resources/langs/nheko_ru.ts | 73 +++++++++++++++++---- resources/langs/nheko_zh_CN.ts | 73 +++++++++++++++++---- src/Cache.cpp | 6 +- src/ChatPage.h | 2 + src/CommunitiesList.cpp | 12 ++++ src/CommunitiesList.h | 1 + src/CommunitiesListItem.cpp | 2 + src/RoomInfoListItem.cpp | 105 ++++++++++++++++++++++++++++++- 18 files changed, 747 insertions(+), 117 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 669ce980..b5b046f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -332,7 +332,7 @@ if(USE_BUNDLED_MTXCLIENT) FetchContent_Declare( MatrixClient GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git - GIT_TAG 1018c0822b80cdfc5d6b589fe94d1fd759113ef6 + GIT_TAG f5c78f4331b62a1e25a2d839cb38b07bb9bd7829 ) FetchContent_MakeAvailable(MatrixClient) else() diff --git a/io.github.NhekoReborn.Nheko.json b/io.github.NhekoReborn.Nheko.json index 3de04370..50fa3b33 100644 --- a/io.github.NhekoReborn.Nheko.json +++ b/io.github.NhekoReborn.Nheko.json @@ -146,9 +146,9 @@ "name": "mtxclient", "sources": [ { - "sha256": "537f4e6b280f351ad950cd6598c2407505a55f0d6c856b4ff97a9c59fc6fdb7a", + "sha256": "16203a92b03c488178b31bedca9d9015b1d406443f7e5363a2e09171e50f8dfc", "type": "archive", - "url": "https://github.com/Nheko-Reborn/mtxclient/archive/1018c0822b80cdfc5d6b589fe94d1fd759113ef6.tar.gz" + "url": "https://github.com/Nheko-Reborn/mtxclient/archive/f5c78f4331b62a1e25a2d839cb38b07bb9bd7829.tar.gz" } ] }, diff --git a/resources/langs/nheko_de.ts b/resources/langs/nheko_de.ts index a05bdf4d..341bd01f 100644 --- a/resources/langs/nheko_de.ts +++ b/resources/langs/nheko_de.ts @@ -445,12 +445,58 @@ Beispiel: https://mein.server:8787 RoomInfoListItem - + Leave room Raum verlassen - + + Tag room as: + + + + + Favourite + Standard matrix tag for favourites + + + + + Low Priority + Standard matrix tag for low priority rooms + + + + + Server Notice + Standard matrix tag for server notices + + + + + Adds or removes the specified tag. + WhatsThis hint for tag menu actions + + + + + New tag... + Add a new tag to the room + + + + + New Tag + Tag name prompt title + + + + + Tag: + + + + Accept Akzeptieren @@ -751,7 +797,7 @@ Beispiel: https://mein.server:8787 TimelineRow - + Reply Antworten @@ -764,7 +810,7 @@ Beispiel: https://mein.server:8787 TimelineView - + Reply Antworten @@ -804,7 +850,7 @@ Beispiel: https://mein.server:8787 Kein Raum geöffnet - + Close Schließen @@ -866,7 +912,7 @@ Beispiel: https://mein.server:8787 UserSettingsPage - + Minimize to tray Ins Benachrichtigungsfeld minimieren @@ -920,6 +966,11 @@ Beispiel: https://mein.server:8787 Desktop notifications Desktopbenachrichtigungen + + + Highlight message on hover + + Scale factor @@ -951,7 +1002,7 @@ Beispiel: https://mein.server:8787 Gerätefingerabdruck - + Session Keys Sitzungsschlüssel @@ -971,22 +1022,22 @@ Beispiel: https://mein.server:8787 VERSCHLÜSSELUNG - + GENERAL ALLGEMEINES - + INTERFACE OBERFLÄCHE - + Emoji Font Family Emojischriftart - + Open Sessions File Öffne Sessions Datei diff --git a/resources/langs/nheko_el.ts b/resources/langs/nheko_el.ts index a6e4ff7d..b84b1b1d 100644 --- a/resources/langs/nheko_el.ts +++ b/resources/langs/nheko_el.ts @@ -441,12 +441,58 @@ Example: https://server.my:8787 RoomInfoListItem - + Leave room Βγές - + + Tag room as: + + + + + Favourite + Standard matrix tag for favourites + + + + + Low Priority + Standard matrix tag for low priority rooms + + + + + Server Notice + Standard matrix tag for server notices + + + + + Adds or removes the specified tag. + WhatsThis hint for tag menu actions + + + + + New tag... + Add a new tag to the room + + + + + New Tag + Tag name prompt title + + + + + Tag: + + + + Accept Αποδοχή @@ -747,7 +793,7 @@ Example: https://server.my:8787 TimelineRow - + Reply @@ -760,7 +806,7 @@ Example: https://server.my:8787 TimelineView - + Reply @@ -800,7 +846,7 @@ Example: https://server.my:8787 - + Close @@ -862,7 +908,7 @@ Example: https://server.my:8787 UserSettingsPage - + Minimize to tray Ελαχιστοποίηση @@ -916,6 +962,11 @@ Example: https://server.my:8787 Desktop notifications + + + Highlight message on hover + + Scale factor @@ -947,7 +998,7 @@ Example: https://server.my:8787 - + Session Keys @@ -967,22 +1018,22 @@ Example: https://server.my:8787 - + GENERAL ΓΕΝΙΚΑ - + INTERFACE - + Emoji Font Family - + Open Sessions File diff --git a/resources/langs/nheko_en.ts b/resources/langs/nheko_en.ts index 1fd9b86c..72fbc8ad 100644 --- a/resources/langs/nheko_en.ts +++ b/resources/langs/nheko_en.ts @@ -445,12 +445,58 @@ Example: https://server.my:8787 RoomInfoListItem - + Leave room Leave room - + + Tag room as: + + + + + Favourite + Standard matrix tag for favourites + + + + + Low Priority + Standard matrix tag for low priority rooms + + + + + Server Notice + Standard matrix tag for server notices + + + + + Adds or removes the specified tag. + WhatsThis hint for tag menu actions + + + + + New tag... + Add a new tag to the room + + + + + New Tag + Tag name prompt title + + + + + Tag: + + + + Accept Accept @@ -751,7 +797,7 @@ Example: https://server.my:8787 TimelineRow - + Reply Reply @@ -764,7 +810,7 @@ Example: https://server.my:8787 TimelineView - + Reply Reply @@ -804,7 +850,7 @@ Example: https://server.my:8787 No room open - + Close Close @@ -866,7 +912,7 @@ Example: https://server.my:8787 UserSettingsPage - + Minimize to tray Minimize to tray @@ -920,6 +966,11 @@ Example: https://server.my:8787 Desktop notifications Desktop notifications + + + Highlight message on hover + + Scale factor @@ -951,7 +1002,7 @@ Example: https://server.my:8787 Device Fingerprint - + Session Keys Session Keys @@ -971,22 +1022,22 @@ Example: https://server.my:8787 ENCRYPTION - + GENERAL GENERAL - + INTERFACE INTERFACE - + Emoji Font Family Emoji Font Family - + Open Sessions File Open Sessions File diff --git a/resources/langs/nheko_fi.ts b/resources/langs/nheko_fi.ts index 069fb6b2..271b45c4 100644 --- a/resources/langs/nheko_fi.ts +++ b/resources/langs/nheko_fi.ts @@ -441,12 +441,58 @@ Example: https://server.my:8787 RoomInfoListItem - + Leave room Poistu huoneesta - + + Tag room as: + + + + + Favourite + Standard matrix tag for favourites + + + + + Low Priority + Standard matrix tag for low priority rooms + + + + + Server Notice + Standard matrix tag for server notices + + + + + Adds or removes the specified tag. + WhatsThis hint for tag menu actions + + + + + New tag... + Add a new tag to the room + + + + + New Tag + Tag name prompt title + + + + + Tag: + + + + Accept Hyväksy @@ -747,7 +793,7 @@ Example: https://server.my:8787 TimelineRow - + Reply @@ -760,7 +806,7 @@ Example: https://server.my:8787 TimelineView - + Reply @@ -800,7 +846,7 @@ Example: https://server.my:8787 - + Close Sulje @@ -862,7 +908,7 @@ Example: https://server.my:8787 UserSettingsPage - + Minimize to tray Pienennä ilmoitusalueelle @@ -916,6 +962,11 @@ Example: https://server.my:8787 Desktop notifications Työpöytäilmoitukset + + + Highlight message on hover + + Scale factor @@ -947,7 +998,7 @@ Example: https://server.my:8787 Laitteen sormenjälki - + Session Keys Istunnon avaimet @@ -967,22 +1018,22 @@ Example: https://server.my:8787 SALAUS - + GENERAL YLEISET ASETUKSET - + INTERFACE - + Emoji Font Family - + Open Sessions File Avaa Istuntoavaintiedosto diff --git a/resources/langs/nheko_fr.ts b/resources/langs/nheko_fr.ts index d50b5fb8..4fcb34dd 100644 --- a/resources/langs/nheko_fr.ts +++ b/resources/langs/nheko_fr.ts @@ -441,12 +441,58 @@ Example: https://server.my:8787 RoomInfoListItem - + Leave room Quitter le salon - + + Tag room as: + + + + + Favourite + Standard matrix tag for favourites + + + + + Low Priority + Standard matrix tag for low priority rooms + + + + + Server Notice + Standard matrix tag for server notices + + + + + Adds or removes the specified tag. + WhatsThis hint for tag menu actions + + + + + New tag... + Add a new tag to the room + + + + + New Tag + Tag name prompt title + + + + + Tag: + + + + Accept Accepter @@ -747,7 +793,7 @@ Example: https://server.my:8787 TimelineRow - + Reply @@ -760,7 +806,7 @@ Example: https://server.my:8787 TimelineView - + Reply @@ -800,7 +846,7 @@ Example: https://server.my:8787 - + Close @@ -862,7 +908,7 @@ Example: https://server.my:8787 UserSettingsPage - + Minimize to tray Réduire à la barre des tâches @@ -916,6 +962,11 @@ Example: https://server.my:8787 Desktop notifications + + + Highlight message on hover + + Scale factor @@ -947,7 +998,7 @@ Example: https://server.my:8787 - + Session Keys @@ -967,22 +1018,22 @@ Example: https://server.my:8787 - + GENERAL GÉNÉRAL - + INTERFACE - + Emoji Font Family - + Open Sessions File diff --git a/resources/langs/nheko_ja.ts b/resources/langs/nheko_ja.ts index 63522065..5d080342 100644 --- a/resources/langs/nheko_ja.ts +++ b/resources/langs/nheko_ja.ts @@ -441,12 +441,58 @@ Example: https://server.my:8787 RoomInfoListItem - + Leave room 部屋を出る - + + Tag room as: + + + + + Favourite + Standard matrix tag for favourites + + + + + Low Priority + Standard matrix tag for low priority rooms + + + + + Server Notice + Standard matrix tag for server notices + + + + + Adds or removes the specified tag. + WhatsThis hint for tag menu actions + + + + + New tag... + Add a new tag to the room + + + + + New Tag + Tag name prompt title + + + + + Tag: + + + + Accept 容認 @@ -746,7 +792,7 @@ Example: https://server.my:8787 TimelineRow - + Reply 返信 @@ -759,7 +805,7 @@ Example: https://server.my:8787 TimelineView - + Reply 返信 @@ -799,7 +845,7 @@ Example: https://server.my:8787 部屋が開いていません - + Close 閉じる @@ -861,7 +907,7 @@ Example: https://server.my:8787 UserSettingsPage - + Minimize to tray トレイへ最小化 @@ -915,6 +961,11 @@ Example: https://server.my:8787 Desktop notifications デスクトップ通知 + + + Highlight message on hover + + Scale factor @@ -946,7 +997,7 @@ Example: https://server.my:8787 デバイスの指紋 - + Session Keys セッション鍵 @@ -966,22 +1017,22 @@ Example: https://server.my:8787 暗号化 - + GENERAL 全般 - + INTERFACE - + Emoji Font Family - + Open Sessions File セッションファイルを開く diff --git a/resources/langs/nheko_nl.ts b/resources/langs/nheko_nl.ts index 2c3eeee3..31490bc3 100644 --- a/resources/langs/nheko_nl.ts +++ b/resources/langs/nheko_nl.ts @@ -441,12 +441,58 @@ Example: https://server.my:8787 RoomInfoListItem - + Leave room Kamer verlaten - + + Tag room as: + + + + + Favourite + Standard matrix tag for favourites + + + + + Low Priority + Standard matrix tag for low priority rooms + + + + + Server Notice + Standard matrix tag for server notices + + + + + Adds or removes the specified tag. + WhatsThis hint for tag menu actions + + + + + New tag... + Add a new tag to the room + + + + + New Tag + Tag name prompt title + + + + + Tag: + + + + Accept Accepteren @@ -747,7 +793,7 @@ Example: https://server.my:8787 TimelineRow - + Reply @@ -760,7 +806,7 @@ Example: https://server.my:8787 TimelineView - + Reply @@ -800,7 +846,7 @@ Example: https://server.my:8787 - + Close @@ -862,7 +908,7 @@ Example: https://server.my:8787 UserSettingsPage - + Minimize to tray Minimaliseren naar systeemvak @@ -916,6 +962,11 @@ Example: https://server.my:8787 Desktop notifications + + + Highlight message on hover + + Scale factor @@ -947,7 +998,7 @@ Example: https://server.my:8787 - + Session Keys @@ -967,22 +1018,22 @@ Example: https://server.my:8787 - + GENERAL ALGEMEEN - + INTERFACE - + Emoji Font Family - + Open Sessions File diff --git a/resources/langs/nheko_pl.ts b/resources/langs/nheko_pl.ts index f68ca8b3..e77f2f00 100644 --- a/resources/langs/nheko_pl.ts +++ b/resources/langs/nheko_pl.ts @@ -441,12 +441,58 @@ Example: https://server.my:8787 RoomInfoListItem - + Leave room Opuść pokój - + + Tag room as: + + + + + Favourite + Standard matrix tag for favourites + + + + + Low Priority + Standard matrix tag for low priority rooms + + + + + Server Notice + Standard matrix tag for server notices + + + + + Adds or removes the specified tag. + WhatsThis hint for tag menu actions + + + + + New tag... + Add a new tag to the room + + + + + New Tag + Tag name prompt title + + + + + Tag: + + + + Accept Akceptuj @@ -748,7 +794,7 @@ Example: https://server.my:8787 TimelineRow - + Reply @@ -761,7 +807,7 @@ Example: https://server.my:8787 TimelineView - + Reply @@ -801,7 +847,7 @@ Example: https://server.my:8787 - + Close @@ -863,7 +909,7 @@ Example: https://server.my:8787 UserSettingsPage - + Minimize to tray Zminimalizuj do paska zadań @@ -917,6 +963,11 @@ Example: https://server.my:8787 Desktop notifications Powiadomienia na pulpicie + + + Highlight message on hover + + Scale factor @@ -948,7 +999,7 @@ Example: https://server.my:8787 Odcisk palca urządzenia - + Session Keys @@ -968,22 +1019,22 @@ Example: https://server.my:8787 SZYFROWANIE - + GENERAL OGÓLNE - + INTERFACE - + Emoji Font Family - + Open Sessions File diff --git a/resources/langs/nheko_ru.ts b/resources/langs/nheko_ru.ts index 95f75081..f9da93b7 100644 --- a/resources/langs/nheko_ru.ts +++ b/resources/langs/nheko_ru.ts @@ -441,12 +441,58 @@ Example: https://server.my:8787 RoomInfoListItem - + Leave room Покинуть комнату - + + Tag room as: + + + + + Favourite + Standard matrix tag for favourites + + + + + Low Priority + Standard matrix tag for low priority rooms + + + + + Server Notice + Standard matrix tag for server notices + + + + + Adds or removes the specified tag. + WhatsThis hint for tag menu actions + + + + + New tag... + Add a new tag to the room + + + + + New Tag + Tag name prompt title + + + + + Tag: + + + + Accept Принять @@ -748,7 +794,7 @@ Example: https://server.my:8787 TimelineRow - + Reply @@ -761,7 +807,7 @@ Example: https://server.my:8787 TimelineView - + Reply @@ -801,7 +847,7 @@ Example: https://server.my:8787 - + Close Закрыть @@ -863,7 +909,7 @@ Example: https://server.my:8787 UserSettingsPage - + Minimize to tray Сворачивать в системную панель @@ -917,6 +963,11 @@ Example: https://server.my:8787 Desktop notifications Уведомления на рабочем столе + + + Highlight message on hover + + Scale factor @@ -948,7 +999,7 @@ Example: https://server.my:8787 Отпечаток устройства - + Session Keys Ключи сеанса @@ -968,22 +1019,22 @@ Example: https://server.my:8787 ШИФРОВАНИЕ - + GENERAL ГЛАВНОЕ - + INTERFACE - + Emoji Font Family - + Open Sessions File Открыть файл сеансов diff --git a/resources/langs/nheko_zh_CN.ts b/resources/langs/nheko_zh_CN.ts index 6b6c0646..27e5c3cd 100644 --- a/resources/langs/nheko_zh_CN.ts +++ b/resources/langs/nheko_zh_CN.ts @@ -441,12 +441,58 @@ Example: https://server.my:8787 RoomInfoListItem - + Leave room 离开聊天室 - + + Tag room as: + + + + + Favourite + Standard matrix tag for favourites + + + + + Low Priority + Standard matrix tag for low priority rooms + + + + + Server Notice + Standard matrix tag for server notices + + + + + Adds or removes the specified tag. + WhatsThis hint for tag menu actions + + + + + New tag... + Add a new tag to the room + + + + + New Tag + Tag name prompt title + + + + + Tag: + + + + Accept 接受 @@ -746,7 +792,7 @@ Example: https://server.my:8787 TimelineRow - + Reply @@ -759,7 +805,7 @@ Example: https://server.my:8787 TimelineView - + Reply @@ -799,7 +845,7 @@ Example: https://server.my:8787 - + Close @@ -861,7 +907,7 @@ Example: https://server.my:8787 UserSettingsPage - + Minimize to tray 最小化至托盘 @@ -915,6 +961,11 @@ Example: https://server.my:8787 Desktop notifications 桌面通知 + + + Highlight message on hover + + Scale factor @@ -946,7 +997,7 @@ Example: https://server.my:8787 设备指纹 - + Session Keys 会话密钥 @@ -966,22 +1017,22 @@ Example: https://server.my:8787 加密 - + GENERAL 通用 - + INTERFACE - + Emoji Font Family - + Open Sessions File 打开会话文件 diff --git a/src/Cache.cpp b/src/Cache.cpp index 3a388bb9..1061e60e 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -915,8 +915,8 @@ Cache::saveState(const mtx::responses::Sync &res) bool has_new_tags = false; for (const auto &evt : room.second.account_data.events) { // for now only fetch tag events - if (std::holds_alternative>(evt)) { - auto tags_evt = std::get>(evt); + if (std::holds_alternative>(evt)) { + auto tags_evt = std::get>(evt); has_new_tags = true; for (const auto &tag : tags_evt.content.tags) { updatedInfo.tags.push_back(tag.first); @@ -1081,7 +1081,7 @@ Cache::roomsWithTagUpdates(const mtx::responses::Sync &res) for (const auto &room : res.rooms.join) { bool hasUpdates = false; for (const auto &evt : room.second.account_data.events) { - if (std::holds_alternative>(evt)) { + if (std::holds_alternative>(evt)) { hasUpdates = true; } } diff --git a/src/ChatPage.h b/src/ChatPage.h index 46630692..83b4e76d 100644 --- a/src/ChatPage.h +++ b/src/ChatPage.h @@ -77,6 +77,8 @@ public: QSharedPointer userSettings() { return userSettings_; } void deleteConfigs(); + CommunitiesList *communitiesList() { return communitiesList_; } + //! Calculate the width of the message timeline. uint64_t timelineWidth(); bool isSideBarExpanded(); diff --git a/src/CommunitiesList.cpp b/src/CommunitiesList.cpp index bb57ca40..8a938646 100644 --- a/src/CommunitiesList.cpp +++ b/src/CommunitiesList.cpp @@ -257,6 +257,18 @@ CommunitiesList::roomList(const QString &id) const return {}; } +std::vector +CommunitiesList::currentTags() const +{ + std::vector tags; + for (auto &entry : communities_) { + CommunitiesListItem *item = entry.second.data(); + if (item->is_tag()) + tags.push_back(entry.first.mid(4).toStdString()); + } + return tags; +} + void CommunitiesList::sortEntries() { diff --git a/src/CommunitiesList.h b/src/CommunitiesList.h index d3cbeeff..63f7af07 100644 --- a/src/CommunitiesList.h +++ b/src/CommunitiesList.h @@ -28,6 +28,7 @@ public: void syncTags(const std::map &info); void setTagsForRoom(const QString &id, const std::vector &tags); + std::vector currentTags() const; signals: void communityChanged(const QString &id); diff --git a/src/CommunitiesListItem.cpp b/src/CommunitiesListItem.cpp index 274271e5..c56c74a2 100644 --- a/src/CommunitiesListItem.cpp +++ b/src/CommunitiesListItem.cpp @@ -137,6 +137,8 @@ CommunitiesListItem::updateTooltip() setToolTip(tr("Favourite rooms")); else if (tag == "m.lowpriority") setToolTip(tr("Low priority rooms")); + else if (tag == "m.server_notice") + setToolTip(tr("Server Notices", "Tag translation for m.server_notice")); else if (tag.startsWith("u.")) setToolTip(tag.right(tag.size() - 2) + tr(" (tag)")); else diff --git a/src/RoomInfoListItem.cpp b/src/RoomInfoListItem.cpp index ee8d532d..ad774360 100644 --- a/src/RoomInfoListItem.cpp +++ b/src/RoomInfoListItem.cpp @@ -16,6 +16,7 @@ */ #include +#include #include #include #include @@ -23,7 +24,10 @@ #include "AvatarProvider.h" #include "Cache.h" +#include "ChatPage.h" #include "Config.h" +#include "Logging.h" +#include "MatrixClient.h" #include "RoomInfoListItem.h" #include "Splitter.h" #include "UserSettingsPage.h" @@ -97,7 +101,106 @@ RoomInfoListItem::init(QWidget *parent) menu_ = new Menu(this); leaveRoom_ = new QAction(tr("Leave room"), this); connect(leaveRoom_, &QAction::triggered, this, [this]() { emit leaveRoom(roomId_); }); - menu_->addAction(leaveRoom_); + + connect(menu_, &QMenu::aboutToShow, this, [this]() { + menu_->clear(); + menu_->addAction(leaveRoom_); + + menu_->addSection(QIcon(":/icons/icons/ui/tag.png"), tr("Tag room as:")); + + auto roomInfo = cache::singleRoomInfo(roomId_.toStdString()); + + auto tags = ChatPage::instance()->communitiesList()->currentTags(); + + // add default tag, remove server notice tag + if (std::find(tags.begin(), tags.end(), "m.favourite") == tags.end()) + tags.push_back("m.favourite"); + if (std::find(tags.begin(), tags.end(), "m.lowpriority") == tags.end()) + tags.push_back("m.lowpriority"); + if (auto it = std::find(tags.begin(), tags.end(), "m.server_notice"); + it != tags.end()) + tags.erase(it); + + for (const auto &tag : tags) { + QString tagName; + if (tag == "m.favourite") + tagName = tr("Favourite", "Standard matrix tag for favourites"); + else if (tag == "m.lowpriority") + tagName = + tr("Low Priority", "Standard matrix tag for low priority rooms"); + else if (tag == "m.server_notice") + tagName = + tr("Server Notice", "Standard matrix tag for server notices"); + else if ((tag.size() > 2 && tag.substr(0, 2) == "u.") || + tag.find(".") != + std::string::npos) // tag manager creates tags without u., which + // is wrong, but we still want to display them + tagName = QString::fromStdString(tag.substr(2)); + + if (tagName.isEmpty()) + continue; + + auto tagAction = menu_->addAction(tagName); + tagAction->setCheckable(true); + tagAction->setWhatsThis(tr("Adds or removes the specified tag.", + "WhatsThis hint for tag menu actions")); + + for (const auto &riTag : roomInfo.tags) + if (riTag == tag) { + tagAction->setChecked(true); + break; + } + + connect(tagAction, &QAction::triggered, this, [this, tag](bool checked) { + if (checked) + http::client()->put_tag( + roomId_.toStdString(), + tag, + {}, + [tag](mtx::http::RequestErr err) { + if (err) { + nhlog::ui()->error( + "Failed to add tag: {}, {}", + tag, + err->matrix_error.error); + } + }); + else + http::client()->delete_tag( + roomId_.toStdString(), + tag, + [tag](mtx::http::RequestErr err) { + if (err) { + nhlog::ui()->error( + "Failed to delete tag: {}, {}", + tag, + err->matrix_error.error); + } + }); + }); + } + + auto newTagAction = menu_->addAction(tr("New tag...", "Add a new tag to the room")); + connect(newTagAction, &QAction::triggered, this, [this]() { + QString tagName = + QInputDialog::getText(this, + tr("New Tag", "Tag name prompt title"), + tr("Tag:", "Tag name prompt")); + if (tagName.isEmpty()) + return; + + std::string tag = "u." + tagName.toStdString(); + + http::client()->put_tag( + roomId_.toStdString(), tag, {}, [tag](mtx::http::RequestErr err) { + if (err) { + nhlog::ui()->error("Failed to add tag: {}, {}", + tag, + err->matrix_error.error); + } + }); + }); + }); } RoomInfoListItem::RoomInfoListItem(QString room_id, From 23e4408fa8a840b78984c97aa927a120a465fd12 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 18 May 2020 14:02:14 +0200 Subject: [PATCH 2/3] Add /roomnick command --- src/ChatPage.cpp | 23 +++++++++++++++++++++++ src/TextInputWidget.cpp | 2 ++ src/TextInputWidget.h | 1 + 3 files changed, 26 insertions(+) diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index d0ca4670..90abc63e 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -300,6 +300,29 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) connect(text_input_, &TextInputWidget::sendBanRoomRequest, this, &ChatPage::banUser); connect(text_input_, &TextInputWidget::sendUnbanRoomRequest, this, &ChatPage::unbanUser); + connect( + text_input_, &TextInputWidget::changeRoomNick, this, [this](const QString &displayName) { + mtx::events::state::Member member; + member.display_name = displayName.toStdString(); + member.avatar_url = + cache::avatarUrl(currentRoom(), + QString::fromStdString(http::client()->user_id().to_string())) + .toStdString(); + member.membership = mtx::events::state::Membership::Join; + + http::client() + ->send_state_event( + currentRoom().toStdString(), + http::client()->user_id().to_string(), + member, + [](mtx::responses::EventId, mtx::http::RequestErr err) { + if (err) + nhlog::net()->error("Failed to set room displayname: {}", + err->matrix_error.error); + }); + }); + connect( text_input_, &TextInputWidget::uploadMedia, diff --git a/src/TextInputWidget.cpp b/src/TextInputWidget.cpp index af5c278e..d2359910 100644 --- a/src/TextInputWidget.cpp +++ b/src/TextInputWidget.cpp @@ -576,6 +576,8 @@ TextInputWidget::command(QString command, QString args) sendBanRoomRequest(args.section(' ', 0, 0), args.section(' ', 1, -1)); } else if (command == "unban") { sendUnbanRoomRequest(args.section(' ', 0, 0), args.section(' ', 1, -1)); + } else if (command == "roomnick") { + changeRoomNick(args); } else if (command == "shrug") { sendTextMessage("¯\\_(ツ)_/¯"); } else if (command == "fliptable") { diff --git a/src/TextInputWidget.h b/src/TextInputWidget.h index addb61ec..a0105eb0 100644 --- a/src/TextInputWidget.h +++ b/src/TextInputWidget.h @@ -167,6 +167,7 @@ signals: void sendKickRoomRequest(const QString &userid, const QString &reason); void sendBanRoomRequest(const QString &userid, const QString &reason); void sendUnbanRoomRequest(const QString &userid, const QString &reason); + void changeRoomNick(const QString &displayname); void startedTyping(); void stoppedTyping(); From bdf1147a807a8d72eccfcf37c95604331653e0f7 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 18 May 2020 14:02:54 +0200 Subject: [PATCH 3/3] add a bit of additional logging to image paste --- src/TextInputWidget.cpp | 1 + src/dialogs/PreviewUploadOverlay.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/TextInputWidget.cpp b/src/TextInputWidget.cpp index d2359910..3e3915bb 100644 --- a/src/TextInputWidget.cpp +++ b/src/TextInputWidget.cpp @@ -279,6 +279,7 @@ FilteredTextEdit::canInsertFromMimeData(const QMimeData *source) const void FilteredTextEdit::insertFromMimeData(const QMimeData *source) { + qInfo() << "Got mime formats: \n" << source->formats(); const auto formats = source->formats().filter("/"); const auto image = formats.filter("image/", Qt::CaseInsensitive); const auto audio = formats.filter("audio/", Qt::CaseInsensitive); diff --git a/src/dialogs/PreviewUploadOverlay.cpp b/src/dialogs/PreviewUploadOverlay.cpp index 42558d67..20959b0a 100644 --- a/src/dialogs/PreviewUploadOverlay.cpp +++ b/src/dialogs/PreviewUploadOverlay.cpp @@ -136,6 +136,11 @@ PreviewUploadOverlay::setLabels(const QString &type, const QString &mime, uint64 void PreviewUploadOverlay::setPreview(const QImage &src, const QString &mime) { + nhlog::ui()->info("Pasting image with size: {}x{}, format: {}", + src.height(), + src.width(), + mime.toStdString()); + auto const &split = mime.split('/'); auto const &type = split[1];