diff --git a/resources/qml/dialogs/HiddenEventsDialog.qml b/resources/qml/dialogs/HiddenEventsDialog.qml
index d4fc7626..f6fc830d 100644
--- a/resources/qml/dialogs/HiddenEventsDialog.qml
+++ b/resources/qml/dialogs/HiddenEventsDialog.qml
@@ -15,7 +15,7 @@ ApplicationWindow {
property var onAccepted: undefined
modality: Qt.NonModal
- flags: Qt.Dialog
+ flags: Qt.Dialog | Qt.WindowTitleHint
minimumWidth: 250
minimumHeight: 220
Component.onCompleted: Nheko.reparent(hiddenEventsDialog)
@@ -57,7 +57,7 @@ ApplicationWindow {
ToggleButton {
id: toggleRoomMember
- checked: roomSettings.eventHidden(0)
+ checked: !roomSettings.eventHidden("m.room.member")
Layout.alignment: Qt.AlignRight
}
@@ -74,7 +74,7 @@ ApplicationWindow {
ToggleButton {
id: toggleRoomPowerLevels
- checked: roomSettings.eventHidden(1)
+ checked: !roomSettings.eventHidden("m.room.power_levels")
Layout.alignment: Qt.AlignRight
}
@@ -86,7 +86,7 @@ ApplicationWindow {
ToggleButton {
id: toggleSticker
Layout.alignment: Qt.AlignRight
- checked: roomSettings.eventHidden(2)
+ checked: !roomSettings.eventHidden("m.sticker")
}
}
}
@@ -96,7 +96,17 @@ ApplicationWindow {
standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel
onAccepted: {
- roomSettings.saveHiddenEventsSettings(toggleRoomMember.checked, toggleRoomPowerLevels.checked, toggleSticker.checked);
+ let events = new Array;
+ if (!toggleRoomMember.checked) {
+ events.push("m.room.member");
+ }
+ if (!toggleRoomPowerLevels.checked) {
+ events.push("m.room.power_levels");
+ }
+ if (!toggleSticker.checked) {
+ events.push("m.sticker");
+ }
+ roomSettings.saveHiddenEventsSettings(events);
hiddenEventsDialog.close();
}
diff --git a/resources/qml/dialogs/RoomSettings.qml b/resources/qml/dialogs/RoomSettings.qml
index dbf22b29..00743a20 100644
--- a/resources/qml/dialogs/RoomSettings.qml
+++ b/resources/qml/dialogs/RoomSettings.qml
@@ -260,12 +260,12 @@ ApplicationWindow {
HiddenEventsDialog {
id: hiddenEventsDialog
- prompt: qsTr("Select the events you want to hide from %1").arg(roomSettings.roomName)
+ prompt: qsTr("These events will be be shown in %1:").arg(roomSettings.roomName)
}
Button {
text: qsTr("Configure")
- ToolTip.text: qsTr("Change which events are hidden in this room")
+ ToolTip.text: qsTr("Select events to hide in this room")
onClicked: hiddenEventsDialog.show()
Layout.alignment: Qt.AlignRight
}
diff --git a/src/ui/RoomSettings.cpp b/src/ui/RoomSettings.cpp
index 2180b5c1..0502b281 100644
--- a/src/ui/RoomSettings.cpp
+++ b/src/ui/RoomSettings.cpp
@@ -13,8 +13,11 @@
#include
#include
#include
+#include
+#include
#include
#include
+#include
#include "Cache.h"
#include "Cache_p.h"
@@ -22,9 +25,6 @@
#include "Logging.h"
#include "MatrixClient.h"
#include "Utils.h"
-#include "mtx/events/event_type.hpp"
-#include "mtx/events/nheko_extensions/hidden_events.hpp"
-#include "mtxclient/http/client.hpp"
#include "ui/TextField.h"
using namespace mtx::events;
@@ -231,21 +231,13 @@ RoomSettings::RoomSettings(QString roomid, QObject *parent)
emit accessJoinRulesChanged();
// Get room's hidden events and store it in member variable.
- using mtx::events::EventType;
- if (auto hiddenEvents =
- cache::client()->getAccountData(EventType::NhekoHiddenEvents, roomid_.toStdString())) {
+ if (auto hiddenEvents = cache::client()->getAccountData(
+ mtx::events::EventType::NhekoHiddenEvents, roomid_.toStdString())) {
if (auto tmp = std::get_if>(&*hiddenEvents)) {
- const auto &types = tmp->content.hidden_event_types;
- auto is_hidden{[&types](EventType searchFor) {
- return std::find_if(types.begin(), types.end(), [&searchFor](const auto curType) {
- return curType == searchFor;
- }) != types.end();
- }};
-
- hiddenEvents_ = {is_hidden(EventType::RoomMember),
- is_hidden(EventType::RoomPowerLevels),
- is_hidden(EventType::Sticker)};
+ for (const auto event : tmp->content.hidden_event_types) {
+ hiddenEvents_.insert(mtx::events::to_string(event).data());
+ }
}
}
}
@@ -319,17 +311,9 @@ RoomSettings::accessJoinRules()
}
bool
-RoomSettings::eventHidden(int index)
+RoomSettings::eventHidden(const QString event) const
{
- try {
- // Is empty if there are no preferences stored for this room.
- if (!hiddenEvents_.empty()) {
- return hiddenEvents_.at(index);
- }
- } catch (...) {
- nhlog::db()->warn("Failed to retrieve hidden event setting at {}", index);
- }
- return false;
+ return hiddenEvents_.contains(event);
}
void
@@ -443,30 +427,18 @@ RoomSettings::openEditModal()
}
void
-RoomSettings::saveHiddenEventsSettings(const bool toggleRoomMember,
- const bool toggleRoomPowerLevels,
- const bool toggleSticker)
+RoomSettings::saveHiddenEventsSettings(const QSet events)
{
- const auto roomid = roomid_.toStdString();
- nhlog::ui()->debug("Setting events to hidden in room {}: m.room.member={}, "
- "m.room.power_levels={}, m.sticker={}",
- roomid,
- toggleRoomMember,
- toggleRoomPowerLevels,
- toggleSticker);
-
+ // 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};
- if (toggleRoomMember) {
- hiddenEvents.hidden_event_types.emplace_back(mtx::events::EventType::RoomMember);
- }
- if (toggleRoomPowerLevels) {
- hiddenEvents.hidden_event_types.emplace_back(mtx::events::EventType::RoomPowerLevels);
- }
- if (toggleSticker) {
- hiddenEvents.hidden_event_types.emplace_back(mtx::events::EventType::Sticker);
+ for (const auto &event : events) {
+ hiddenEvents.hidden_event_types.emplace_back(
+ 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);
diff --git a/src/ui/RoomSettings.h b/src/ui/RoomSettings.h
index ee353d44..d5d42ce0 100644
--- a/src/ui/RoomSettings.h
+++ b/src/ui/RoomSettings.h
@@ -8,10 +8,11 @@
#include
#include
#include
+#include
#include
+#include
#include
-#include
#include "CacheStructs.h"
@@ -108,11 +109,10 @@ public:
Q_INVOKABLE void enableEncryption();
Q_INVOKABLE void updateAvatar();
Q_INVOKABLE void openEditModal();
- Q_INVOKABLE void
- saveHiddenEventsSettings(bool toggleRoomMember, bool toggleRoomPowerLevels, bool toggleSticker);
+ Q_INVOKABLE void saveHiddenEventsSettings(QSet events);
Q_INVOKABLE void changeAccessRules(int index);
Q_INVOKABLE void changeNotifications(int currentIndex);
- Q_INVOKABLE bool eventHidden(int index);
+ Q_INVOKABLE bool eventHidden(QString event) const;
signals:
void loadingChanged();
@@ -141,5 +141,5 @@ private:
RoomInfo info_;
int notifications_ = 0;
int accessRules_ = 0;
- std::vector hiddenEvents_;
+ QSet hiddenEvents_;
};