From 72cfb06208e80252717541fa51d64e9f93bf0657 Mon Sep 17 00:00:00 2001
From: tastytea <tastytea@tastytea.de>
Date: Thu, 13 Jan 2022 05:24:54 +0100
Subject: [PATCH] Hidden events: Some cleanup

---
 resources/qml/dialogs/HiddenEventsDialog.qml |  2 +-
 src/ui/RoomSettings.cpp                      | 69 ++++++++++----------
 src/ui/RoomSettings.h                        |  4 +-
 3 files changed, 36 insertions(+), 39 deletions(-)

diff --git a/resources/qml/dialogs/HiddenEventsDialog.qml b/resources/qml/dialogs/HiddenEventsDialog.qml
index 8f2d01fdd..5973f4fdb 100644
--- a/resources/qml/dialogs/HiddenEventsDialog.qml
+++ b/resources/qml/dialogs/HiddenEventsDialog.qml
@@ -45,7 +45,7 @@ ApplicationWindow {
                     return qsTr("These events will be be <b>shown</b> in %1:").arg(roomSettings.roomName);
                 }
                 else {
-                    return qsTr("These events will be be <b>shown</b>:");
+                    return qsTr("These events will be be <b>shown</b> in all rooms:");
                 }
             }
             font.pixelSize: Math.floor(fontMetrics.font.pixelSize * 1.2)
diff --git a/src/ui/RoomSettings.cpp b/src/ui/RoomSettings.cpp
index 3d68aebb5..288dac4e8 100644
--- a/src/ui/RoomSettings.cpp
+++ b/src/ui/RoomSettings.cpp
@@ -12,7 +12,6 @@
 #include <QMimeDatabase>
 #include <QStandardPaths>
 #include <QVBoxLayout>
-#include <algorithm>
 #include <mtx/events/event_type.hpp>
 #include <mtx/events/nheko_extensions/hidden_events.hpp>
 #include <mtx/responses/common.hpp>
@@ -230,7 +229,6 @@ RoomSettings::RoomSettings(QString roomid, QObject *parent)
     }
     emit accessJoinRulesChanged();
 
-    // Get room's hidden events and store it in member variable.
     if (auto hiddenEvents = cache::client()->getAccountData(
           mtx::events::EventType::NhekoHiddenEvents, roomid_.toStdString())) {
         if (auto tmp = std::get_if<mtx::events::EphemeralEvent<
@@ -310,12 +308,6 @@ RoomSettings::accessJoinRules()
     return accessRules_;
 }
 
-bool
-RoomSettings::eventHidden(const QString event) const
-{
-    return hiddenEvents_.contains(event);
-}
-
 void
 RoomSettings::enableEncryption()
 {
@@ -426,34 +418,6 @@ RoomSettings::openEditModal()
     });
 }
 
-void
-RoomSettings::saveHiddenEventsSettings(const QSet<QString> &events, const QString &roomId)
-{
-    mtx::events::account_data::nheko_extensions::HiddenEvents hiddenEvents;
-    hiddenEvents.hidden_event_types = {
-      EventType::Reaction, EventType::CallCandidates, EventType::Unsupported};
-    for (const auto &event : events) {
-        hiddenEvents.hidden_event_types.emplace_back(
-          mtx::events::getEventType(event.toStdString()));
-    }
-
-    if (!roomId.isEmpty()) {
-        const auto rid = roomId.toStdString();
-        http::client()->put_room_account_data(rid, hiddenEvents, [&rid](mtx::http::RequestErr e) {
-            if (e) {
-                nhlog::net()->error(
-                  "Failed to update room account data with hidden events in {}: {}", rid, *e);
-            }
-        });
-    } else {
-        http::client()->put_account_data(hiddenEvents, [](mtx::http::RequestErr e) {
-            if (e) {
-                nhlog::net()->error("Failed to update account data with hidden events: {}", *e);
-            }
-        });
-    }
-}
-
 void
 RoomSettings::changeNotifications(int currentIndex)
 {
@@ -685,3 +649,36 @@ RoomSettings::updateAvatar()
             });
       });
 }
+
+void
+RoomSettings::saveHiddenEventsSettings(const QSet<QString> &events, const QString &roomId)
+{
+    account_data::nheko_extensions::HiddenEvents hiddenEvents;
+    hiddenEvents.hidden_event_types = {
+      EventType::Reaction, EventType::CallCandidates, EventType::Unsupported};
+    for (const auto &event : events) {
+        hiddenEvents.hidden_event_types.emplace_back(getEventType(event.toStdString()));
+    }
+
+    if (!roomId.isEmpty()) {
+        const auto rid = roomId.toStdString();
+        http::client()->put_room_account_data(rid, hiddenEvents, [&rid](mtx::http::RequestErr e) {
+            if (e) {
+                nhlog::net()->error(
+                  "Failed to update room account data with hidden events in {}: {}", rid, *e);
+            }
+        });
+    } else {
+        http::client()->put_account_data(hiddenEvents, [](mtx::http::RequestErr e) {
+            if (e) {
+                nhlog::net()->error("Failed to update account data with hidden events: {}", *e);
+            }
+        });
+    }
+}
+
+bool
+RoomSettings::eventHidden(const QString event) const
+{
+    return hiddenEvents_.contains(event);
+}
diff --git a/src/ui/RoomSettings.h b/src/ui/RoomSettings.h
index c6f4e95a5..db1b69884 100644
--- a/src/ui/RoomSettings.h
+++ b/src/ui/RoomSettings.h
@@ -109,10 +109,10 @@ public:
     Q_INVOKABLE void enableEncryption();
     Q_INVOKABLE void updateAvatar();
     Q_INVOKABLE void openEditModal();
-    Q_INVOKABLE void
-    saveHiddenEventsSettings(const QSet<QString> &events, const QString &roomId = {});
     Q_INVOKABLE void changeAccessRules(int index);
     Q_INVOKABLE void changeNotifications(int currentIndex);
+    Q_INVOKABLE void
+    saveHiddenEventsSettings(const QSet<QString> &events, const QString &roomId = {});
     Q_INVOKABLE bool eventHidden(QString event) const;
 
 signals:
-- 
GitLab