summary refs log tree commit diff
path: root/src/ui/RoomSettings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/RoomSettings.cpp')
-rw-r--r--src/ui/RoomSettings.cpp69
1 files changed, 33 insertions, 36 deletions
diff --git a/src/ui/RoomSettings.cpp b/src/ui/RoomSettings.cpp

index 3d68aebb..288dac4e 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() { @@ -427,34 +419,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) { notifications_ = 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); +}