summary refs log tree commit diff
path: root/src/ui
diff options
context:
space:
mode:
authortastytea <tastytea@tastytea.de>2022-01-13 00:39:26 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2022-02-10 00:48:35 +0100
commit49b313e3b85911acfc8186e548608bd44324a986 (patch)
tree8894a01053f87576af6b9bbb1740078723603359 /src/ui
parentHidden events: Change title and prompt depending on isRoomSetting (diff)
downloadnheko-49b313e3b85911acfc8186e548608bd44324a986.tar.xz
Hidden events: Make save-function reusable for global account data
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/RoomSettings.cpp24
-rw-r--r--src/ui/RoomSettings.h3
2 files changed, 18 insertions, 9 deletions
diff --git a/src/ui/RoomSettings.cpp b/src/ui/RoomSettings.cpp
index 0502b281..3d68aebb 100644
--- a/src/ui/RoomSettings.cpp
+++ b/src/ui/RoomSettings.cpp
@@ -427,9 +427,8 @@ RoomSettings::openEditModal()
 }
 
 void
-RoomSettings::saveHiddenEventsSettings(const QSet<QString> events)
+RoomSettings::saveHiddenEventsSettings(const QSet<QString> &events, const QString &roomId)
 {
-    // TODO: Make this reusable for global account settings.
     mtx::events::account_data::nheko_extensions::HiddenEvents hiddenEvents;
     hiddenEvents.hidden_event_types = {
       EventType::Reaction, EventType::CallCandidates, EventType::Unsupported};
@@ -438,12 +437,21 @@ RoomSettings::saveHiddenEventsSettings(const QSet<QString> events)
           mtx::events::getEventType(event.toStdString()));
     }
 
-    const auto roomid = roomid_.toStdString();
-    http::client()->put_room_account_data(roomid, hiddenEvents, [&roomid](mtx::http::RequestErr e) {
-        if (e) {
-            nhlog::net()->error("Failed to update room account data in {}: {}", roomid, *e);
-        }
-    });
+    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
diff --git a/src/ui/RoomSettings.h b/src/ui/RoomSettings.h
index d5d42ce0..c6f4e95a 100644
--- a/src/ui/RoomSettings.h
+++ b/src/ui/RoomSettings.h
@@ -109,7 +109,8 @@ public:
     Q_INVOKABLE void enableEncryption();
     Q_INVOKABLE void updateAvatar();
     Q_INVOKABLE void openEditModal();
-    Q_INVOKABLE void saveHiddenEventsSettings(QSet<QString> events);
+    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 bool eventHidden(QString event) const;