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
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();
}

@ -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 <b>shown</b> 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
}

@ -13,8 +13,11 @@
#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>
#include <mtx/responses/media.hpp>
#include <mtxclient/http/client.hpp>
#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<mtx::events::EphemeralEvent<
mtx::events::account_data::nheko_extensions::HiddenEvents>>(&*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<QString> 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);

@ -8,10 +8,11 @@
#include <QLabel>
#include <QObject>
#include <QPushButton>
#include <QSet>
#include <QString>
#include <mtx/events/event_type.hpp>
#include <mtx/events/guest_access.hpp>
#include <vector>
#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<QString> 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<bool> hiddenEvents_;
QSet<QString> hiddenEvents_;
};

Loading…
Cancel
Save