From 72cfb06208e80252717541fa51d64e9f93bf0657 Mon Sep 17 00:00:00 2001 From: tastytea 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 8f2d01fd..5973f4fd 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 shown in %1:").arg(roomSettings.roomName); } else { - return qsTr("These events will be be shown:"); + return qsTr("These events will be be shown 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 3d68aebb..288dac4e 100644 --- a/src/ui/RoomSettings.cpp +++ b/src/ui/RoomSettings.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -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 &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 &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 c6f4e95a..db1b6988 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 &events, const QString &roomId = {}); Q_INVOKABLE void changeAccessRules(int index); Q_INVOKABLE void changeNotifications(int currentIndex); + Q_INVOKABLE void + saveHiddenEventsSettings(const QSet &events, const QString &roomId = {}); Q_INVOKABLE bool eventHidden(QString event) const; signals: