Hidden events: Incorporate suggestions from review

- Set TitleHint flag on dialog
- Store hidden events as QSet<QString> instead of std::vector<bool>
- Change wording in dialog (disable events instead of turning the hiding
  on)
pull/891/head
tastytea 3 years ago committed by Nicolas Werner
parent d4cc3507f8
commit f0bb64030e
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
  1. 20
      resources/qml/dialogs/HiddenEventsDialog.qml
  2. 4
      resources/qml/dialogs/RoomSettings.qml
  3. 62
      src/ui/RoomSettings.cpp
  4. 10
      src/ui/RoomSettings.h

@ -15,7 +15,7 @@ ApplicationWindow {
property var onAccepted: undefined property var onAccepted: undefined
modality: Qt.NonModal modality: Qt.NonModal
flags: Qt.Dialog flags: Qt.Dialog | Qt.WindowTitleHint
minimumWidth: 250 minimumWidth: 250
minimumHeight: 220 minimumHeight: 220
Component.onCompleted: Nheko.reparent(hiddenEventsDialog) Component.onCompleted: Nheko.reparent(hiddenEventsDialog)
@ -57,7 +57,7 @@ ApplicationWindow {
ToggleButton { ToggleButton {
id: toggleRoomMember id: toggleRoomMember
checked: roomSettings.eventHidden(0) checked: !roomSettings.eventHidden("m.room.member")
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
} }
@ -74,7 +74,7 @@ ApplicationWindow {
ToggleButton { ToggleButton {
id: toggleRoomPowerLevels id: toggleRoomPowerLevels
checked: roomSettings.eventHidden(1) checked: !roomSettings.eventHidden("m.room.power_levels")
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
} }
@ -86,7 +86,7 @@ ApplicationWindow {
ToggleButton { ToggleButton {
id: toggleSticker id: toggleSticker
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
checked: roomSettings.eventHidden(2) checked: !roomSettings.eventHidden("m.sticker")
} }
} }
} }
@ -96,7 +96,17 @@ ApplicationWindow {
standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel
onAccepted: { 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(); hiddenEventsDialog.close();
} }

@ -260,12 +260,12 @@ ApplicationWindow {
HiddenEventsDialog { HiddenEventsDialog {
id: hiddenEventsDialog id: hiddenEventsDialog
prompt: qsTr("Select the events you want to hide from %1").arg(roomSettings.roomName) prompt: qsTr("These events will be be <b>shown</b> in %1:").arg(roomSettings.roomName)
} }
Button { Button {
text: qsTr("Configure") 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() onClicked: hiddenEventsDialog.show()
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
} }

@ -13,8 +13,11 @@
#include <QStandardPaths> #include <QStandardPaths>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <algorithm> #include <algorithm>
#include <mtx/events/event_type.hpp>
#include <mtx/events/nheko_extensions/hidden_events.hpp>
#include <mtx/responses/common.hpp> #include <mtx/responses/common.hpp>
#include <mtx/responses/media.hpp> #include <mtx/responses/media.hpp>
#include <mtxclient/http/client.hpp>
#include "Cache.h" #include "Cache.h"
#include "Cache_p.h" #include "Cache_p.h"
@ -22,9 +25,6 @@
#include "Logging.h" #include "Logging.h"
#include "MatrixClient.h" #include "MatrixClient.h"
#include "Utils.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" #include "ui/TextField.h"
using namespace mtx::events; using namespace mtx::events;
@ -231,21 +231,13 @@ RoomSettings::RoomSettings(QString roomid, QObject *parent)
emit accessJoinRulesChanged(); emit accessJoinRulesChanged();
// Get room's hidden events and store it in member variable. // Get room's hidden events and store it in member variable.
using mtx::events::EventType; if (auto hiddenEvents = cache::client()->getAccountData(
if (auto hiddenEvents = mtx::events::EventType::NhekoHiddenEvents, roomid_.toStdString())) {
cache::client()->getAccountData(EventType::NhekoHiddenEvents, roomid_.toStdString())) {
if (auto tmp = std::get_if<mtx::events::EphemeralEvent< if (auto tmp = std::get_if<mtx::events::EphemeralEvent<
mtx::events::account_data::nheko_extensions::HiddenEvents>>(&*hiddenEvents)) { mtx::events::account_data::nheko_extensions::HiddenEvents>>(&*hiddenEvents)) {
const auto &types = tmp->content.hidden_event_types; for (const auto event : tmp->content.hidden_event_types) {
auto is_hidden{[&types](EventType searchFor) { hiddenEvents_.insert(mtx::events::to_string(event).data());
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)};
} }
} }
} }
@ -319,17 +311,9 @@ RoomSettings::accessJoinRules()
} }
bool bool
RoomSettings::eventHidden(int index) RoomSettings::eventHidden(const QString event) const
{ {
try { return hiddenEvents_.contains(event);
// 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;
} }
void void
@ -443,30 +427,18 @@ RoomSettings::openEditModal()
} }
void void
RoomSettings::saveHiddenEventsSettings(const bool toggleRoomMember, RoomSettings::saveHiddenEventsSettings(const QSet<QString> events)
const bool toggleRoomPowerLevels,
const bool toggleSticker)
{ {
const auto roomid = roomid_.toStdString(); // TODO: Make this reusable for global account settings.
nhlog::ui()->debug("Setting events to hidden in room {}: m.room.member={}, "
"m.room.power_levels={}, m.sticker={}",
roomid,
toggleRoomMember,
toggleRoomPowerLevels,
toggleSticker);
mtx::events::account_data::nheko_extensions::HiddenEvents hiddenEvents; mtx::events::account_data::nheko_extensions::HiddenEvents hiddenEvents;
hiddenEvents.hidden_event_types = { hiddenEvents.hidden_event_types = {
EventType::Reaction, EventType::CallCandidates, EventType::Unsupported}; EventType::Reaction, EventType::CallCandidates, EventType::Unsupported};
if (toggleRoomMember) { for (const auto &event : events) {
hiddenEvents.hidden_event_types.emplace_back(mtx::events::EventType::RoomMember); hiddenEvents.hidden_event_types.emplace_back(
} mtx::events::getEventType(event.toStdString()));
if (toggleRoomPowerLevels) {
hiddenEvents.hidden_event_types.emplace_back(mtx::events::EventType::RoomPowerLevels);
}
if (toggleSticker) {
hiddenEvents.hidden_event_types.emplace_back(mtx::events::EventType::Sticker);
} }
const auto roomid = roomid_.toStdString();
http::client()->put_room_account_data(roomid, hiddenEvents, [&roomid](mtx::http::RequestErr e) { http::client()->put_room_account_data(roomid, hiddenEvents, [&roomid](mtx::http::RequestErr e) {
if (e) { if (e) {
nhlog::net()->error("Failed to update room account data in {}: {}", roomid, *e); nhlog::net()->error("Failed to update room account data in {}: {}", roomid, *e);

@ -8,10 +8,11 @@
#include <QLabel> #include <QLabel>
#include <QObject> #include <QObject>
#include <QPushButton> #include <QPushButton>
#include <QSet>
#include <QString> #include <QString>
#include <mtx/events/event_type.hpp>
#include <mtx/events/guest_access.hpp> #include <mtx/events/guest_access.hpp>
#include <vector>
#include "CacheStructs.h" #include "CacheStructs.h"
@ -108,11 +109,10 @@ public:
Q_INVOKABLE void enableEncryption(); Q_INVOKABLE void enableEncryption();
Q_INVOKABLE void updateAvatar(); Q_INVOKABLE void updateAvatar();
Q_INVOKABLE void openEditModal(); Q_INVOKABLE void openEditModal();
Q_INVOKABLE void Q_INVOKABLE void saveHiddenEventsSettings(QSet<QString> events);
saveHiddenEventsSettings(bool toggleRoomMember, bool toggleRoomPowerLevels, bool toggleSticker);
Q_INVOKABLE void changeAccessRules(int index); Q_INVOKABLE void changeAccessRules(int index);
Q_INVOKABLE void changeNotifications(int currentIndex); Q_INVOKABLE void changeNotifications(int currentIndex);
Q_INVOKABLE bool eventHidden(int index); Q_INVOKABLE bool eventHidden(QString event) const;
signals: signals:
void loadingChanged(); void loadingChanged();
@ -141,5 +141,5 @@ private:
RoomInfo info_; RoomInfo info_;
int notifications_ = 0; int notifications_ = 0;
int accessRules_ = 0; int accessRules_ = 0;
std::vector<bool> hiddenEvents_; QSet<QString> hiddenEvents_;
}; };

Loading…
Cancel
Save