mirror of https://github.com/Nheko-Reborn/nheko
Merge pull request #891 from tastytea/hidden-events-gui
Add GUI to change hidden events per roompull/939/head
commit
a930e3c804
@ -0,0 +1,127 @@ |
||||
// SPDX-FileCopyrightText: 2022 Nheko Contributors |
||||
// |
||||
// SPDX-License-Identifier: GPL-3.0-or-later |
||||
|
||||
import ".." |
||||
import QtQuick 2.12 |
||||
import QtQuick.Controls 2.5 |
||||
import QtQuick.Layouts 1.3 |
||||
import im.nheko 1.0 |
||||
|
||||
ApplicationWindow { |
||||
id: hiddenEventsDialog |
||||
|
||||
property string roomid: "" |
||||
property string roomName: "" |
||||
property var onAccepted: undefined |
||||
|
||||
modality: Qt.NonModal |
||||
flags: Qt.Dialog | Qt.WindowTitleHint |
||||
minimumWidth: 250 |
||||
minimumHeight: 220 |
||||
|
||||
HiddenEvents { |
||||
id: hiddenEvents |
||||
|
||||
roomid: hiddenEventsDialog.roomid |
||||
} |
||||
|
||||
title: { |
||||
if (roomid) { |
||||
return qsTr("Hidden events for %1").arg(roomName); |
||||
} |
||||
else { |
||||
return qsTr("Hidden events"); |
||||
} |
||||
} |
||||
|
||||
Shortcut { |
||||
sequence: StandardKey.Cancel |
||||
onActivated: dbb.rejected() |
||||
} |
||||
|
||||
ColumnLayout { |
||||
spacing: Nheko.paddingMedium |
||||
anchors.margins: Nheko.paddingMedium |
||||
anchors.fill: parent |
||||
|
||||
MatrixText { |
||||
id: promptLabel |
||||
text: { |
||||
if (roomid) { |
||||
return qsTr("These events will be be <b>shown</b> in %1:").arg(roomName); |
||||
} |
||||
else { |
||||
return qsTr("These events will be be <b>shown</b> in all rooms:"); |
||||
} |
||||
} |
||||
font.pixelSize: Math.floor(fontMetrics.font.pixelSize * 1.2) |
||||
Layout.fillWidth: true |
||||
Layout.fillHeight: false |
||||
} |
||||
|
||||
GridLayout { |
||||
columns: 2 |
||||
rowSpacing: Nheko.paddingMedium |
||||
Layout.fillWidth: true |
||||
Layout.fillHeight: true |
||||
|
||||
MatrixText { |
||||
text: qsTr("User events") |
||||
ToolTip.text: qsTr("Joins, leaves, avatar and name changes, bans, …") |
||||
ToolTip.visible: hh1.hovered |
||||
Layout.fillWidth: true |
||||
|
||||
HoverHandler { |
||||
id: hh1 |
||||
} |
||||
} |
||||
|
||||
ToggleButton { |
||||
Layout.alignment: Qt.AlignRight |
||||
checked: !hiddenEvents.hiddenEvents.includes(MtxEvent.Member) |
||||
onToggled: hiddenEvents.toggle(MtxEvent.Member) |
||||
} |
||||
|
||||
MatrixText { |
||||
text: qsTr("Power level changes") |
||||
ToolTip.text: qsTr("Sent when a moderator is added/removed or the permissions of a room are changed.") |
||||
ToolTip.visible: hh2.hovered |
||||
Layout.fillWidth: true |
||||
|
||||
HoverHandler { |
||||
id: hh2 |
||||
} |
||||
} |
||||
|
||||
ToggleButton { |
||||
Layout.alignment: Qt.AlignRight |
||||
checked: !hiddenEvents.hiddenEvents.includes(MtxEvent.PowerLevels) |
||||
onToggled: hiddenEvents.toggle(MtxEvent.PowerLevels) |
||||
} |
||||
|
||||
MatrixText { |
||||
text: qsTr("Stickers") |
||||
Layout.fillWidth: true |
||||
} |
||||
|
||||
ToggleButton { |
||||
Layout.alignment: Qt.AlignRight |
||||
checked: !hiddenEvents.hiddenEvents.includes(MtxEvent.Sticker) |
||||
onToggled: hiddenEvents.toggle(MtxEvent.Sticker) |
||||
} |
||||
} |
||||
} |
||||
|
||||
footer: DialogButtonBox { |
||||
id: dbb |
||||
|
||||
standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel |
||||
onAccepted: { |
||||
hiddenEvents.save(); |
||||
hiddenEventsDialog.close(); |
||||
} |
||||
onRejected: hiddenEventsDialog.close(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,93 @@ |
||||
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "HiddenEvents.h" |
||||
|
||||
#include "Cache_p.h" |
||||
#include "MainWindow.h" |
||||
#include "MatrixClient.h" |
||||
|
||||
void |
||||
HiddenEvents::load() |
||||
{ |
||||
using namespace mtx::events; |
||||
mtx::events::account_data::nheko_extensions::HiddenEvents hiddenEvents; |
||||
hiddenEvents.hidden_event_types = std::vector{ |
||||
EventType::Reaction, |
||||
EventType::CallCandidates, |
||||
EventType::Unsupported, |
||||
}; |
||||
|
||||
if (auto temp = |
||||
cache::client()->getAccountData(mtx::events::EventType::NhekoHiddenEvents, "")) { |
||||
auto h = std::get< |
||||
mtx::events::AccountDataEvent<mtx::events::account_data::nheko_extensions::HiddenEvents>>( |
||||
*temp); |
||||
if (h.content.hidden_event_types) |
||||
hiddenEvents = std::move(h.content); |
||||
} |
||||
|
||||
if (!roomid_.isEmpty()) { |
||||
if (auto temp = cache::client()->getAccountData(mtx::events::EventType::NhekoHiddenEvents, |
||||
roomid_.toStdString())) { |
||||
auto h = std::get<mtx::events::AccountDataEvent< |
||||
mtx::events::account_data::nheko_extensions::HiddenEvents>>(*temp); |
||||
if (h.content.hidden_event_types) |
||||
hiddenEvents = std::move(h.content); |
||||
} |
||||
} |
||||
|
||||
hiddenEvents_.clear(); |
||||
hiddenEvents_ = std::move(hiddenEvents.hidden_event_types.value()); |
||||
emit hiddenEventsChanged(); |
||||
} |
||||
|
||||
Q_INVOKABLE void |
||||
HiddenEvents::toggle(int type) |
||||
{ |
||||
auto t = qml_mtx_events::fromRoomEventType(static_cast<qml_mtx_events::EventType>(type)); |
||||
if (auto it = std::find(begin(hiddenEvents_), end(hiddenEvents_), t); it != end(hiddenEvents_)) |
||||
hiddenEvents_.erase(it); |
||||
else |
||||
hiddenEvents_.push_back(t); |
||||
emit hiddenEventsChanged(); |
||||
} |
||||
|
||||
QVariantList |
||||
HiddenEvents::hiddenEvents() const |
||||
{ |
||||
QVariantList l; |
||||
for (const auto &e : hiddenEvents_) { |
||||
l.push_back(qml_mtx_events::toRoomEventType(e)); |
||||
} |
||||
|
||||
return l; |
||||
} |
||||
|
||||
void |
||||
HiddenEvents::save() |
||||
{ |
||||
mtx::events::account_data::nheko_extensions::HiddenEvents hiddenEvents; |
||||
hiddenEvents.hidden_event_types = hiddenEvents_; |
||||
|
||||
if (roomid_.isEmpty()) |
||||
http::client()->put_account_data(hiddenEvents, [](mtx::http::RequestErr e) { |
||||
if (e) { |
||||
nhlog::net()->error("Failed to set hidden events: {}", *e); |
||||
MainWindow::instance()->showNotification( |
||||
tr("Failed to set hidden events: %1") |
||||
.arg(QString::fromStdString(e->matrix_error.error))); |
||||
} |
||||
}); |
||||
else |
||||
http::client()->put_room_account_data( |
||||
roomid_.toStdString(), hiddenEvents, [](mtx::http::RequestErr e) { |
||||
if (e) { |
||||
nhlog::net()->error("Failed to set hidden events: {}", *e); |
||||
MainWindow::instance()->showNotification( |
||||
tr("Failed to set hidden events: %1") |
||||
.arg(QString::fromStdString(e->matrix_error.error))); |
||||
} |
||||
}); |
||||
} |
@ -0,0 +1,46 @@ |
||||
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once |
||||
|
||||
#include <QObject> |
||||
#include <QString> |
||||
#include <QVariantList> |
||||
|
||||
#include "timeline/TimelineModel.h" |
||||
|
||||
class HiddenEvents : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
Q_PROPERTY(QString roomid READ roomid WRITE setRoomid NOTIFY roomidChanged REQUIRED) |
||||
Q_PROPERTY(QVariantList hiddenEvents READ hiddenEvents NOTIFY hiddenEventsChanged) |
||||
public: |
||||
explicit HiddenEvents(QObject *p = nullptr) |
||||
: QObject(p) |
||||
{} |
||||
|
||||
Q_INVOKABLE void toggle(int type); |
||||
Q_INVOKABLE void save(); |
||||
|
||||
[[nodiscard]] QString roomid() const { return roomid_; } |
||||
void setRoomid(const QString &r) |
||||
{ |
||||
roomid_ = r; |
||||
emit roomidChanged(); |
||||
|
||||
load(); |
||||
} |
||||
|
||||
[[nodiscard]] QVariantList hiddenEvents() const; |
||||
|
||||
signals: |
||||
void roomidChanged(); |
||||
void hiddenEventsChanged(); |
||||
|
||||
private: |
||||
QString roomid_; |
||||
std::vector<mtx::events::EventType> hiddenEvents_; |
||||
|
||||
void load(); |
||||
}; |
Loading…
Reference in new issue