diff options
author | tastytea <tastytea@tastytea.de> | 2022-01-13 00:39:26 +0100 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-02-10 00:48:35 +0100 |
commit | 49b313e3b85911acfc8186e548608bd44324a986 (patch) | |
tree | 8894a01053f87576af6b9bbb1740078723603359 /src/ui | |
parent | Hidden events: Change title and prompt depending on isRoomSetting (diff) | |
download | nheko-49b313e3b85911acfc8186e548608bd44324a986.tar.xz |
Hidden events: Make save-function reusable for global account data
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/RoomSettings.cpp | 24 | ||||
-rw-r--r-- | src/ui/RoomSettings.h | 3 |
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; |