mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-29 14:18:49 +03:00
Hidden events: Refactor slightly for reusability
This commit is contained in:
parent
7ebced29e9
commit
47b822604d
12 changed files with 269 additions and 152 deletions
|
@ -332,6 +332,7 @@ set(SRC_FILES
|
||||||
src/timeline/RoomlistModel.cpp
|
src/timeline/RoomlistModel.cpp
|
||||||
|
|
||||||
# UI components
|
# UI components
|
||||||
|
src/ui/HiddenEvents.cpp
|
||||||
src/ui/MxcAnimatedImage.cpp
|
src/ui/MxcAnimatedImage.cpp
|
||||||
src/ui/MxcMediaProxy.cpp
|
src/ui/MxcMediaProxy.cpp
|
||||||
src/ui/NhekoCursorShape.cpp
|
src/ui/NhekoCursorShape.cpp
|
||||||
|
@ -403,7 +404,7 @@ if(USE_BUNDLED_MTXCLIENT)
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
MatrixClient
|
MatrixClient
|
||||||
GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
|
GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
|
||||||
GIT_TAG 8c03d9ac58274695a71d0eb32519ebce29bc536e
|
GIT_TAG 31a703c9febdfcaaf4e8a74abd424b6fc462e573
|
||||||
)
|
)
|
||||||
set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "")
|
set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "")
|
||||||
set(BUILD_LIB_TESTS OFF CACHE INTERNAL "")
|
set(BUILD_LIB_TESTS OFF CACHE INTERNAL "")
|
||||||
|
@ -527,6 +528,7 @@ qt5_wrap_cpp(MOC_HEADERS
|
||||||
src/timeline/RoomlistModel.h
|
src/timeline/RoomlistModel.h
|
||||||
|
|
||||||
# UI components
|
# UI components
|
||||||
|
src/ui/HiddenEvents.h
|
||||||
src/ui/MxcAnimatedImage.h
|
src/ui/MxcAnimatedImage.h
|
||||||
src/ui/MxcMediaProxy.h
|
src/ui/MxcMediaProxy.h
|
||||||
src/ui/NhekoCursorShape.h
|
src/ui/NhekoCursorShape.h
|
||||||
|
|
|
@ -191,7 +191,7 @@ modules:
|
||||||
buildsystem: cmake-ninja
|
buildsystem: cmake-ninja
|
||||||
name: mtxclient
|
name: mtxclient
|
||||||
sources:
|
sources:
|
||||||
- commit: 8c03d9ac58274695a71d0eb32519ebce29bc536e
|
- commit: 31a703c9febdfcaaf4e8a74abd424b6fc462e573
|
||||||
#tag: v0.6.1
|
#tag: v0.6.1
|
||||||
type: git
|
type: git
|
||||||
url: https://github.com/Nheko-Reborn/mtxclient.git
|
url: https://github.com/Nheko-Reborn/mtxclient.git
|
||||||
|
|
|
@ -11,17 +11,24 @@ import im.nheko 1.0
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
id: hiddenEventsDialog
|
id: hiddenEventsDialog
|
||||||
|
|
||||||
property var isRoomSetting: false
|
property string roomid: ""
|
||||||
|
property string roomName: ""
|
||||||
property var onAccepted: undefined
|
property var onAccepted: undefined
|
||||||
|
|
||||||
modality: Qt.NonModal
|
modality: Qt.NonModal
|
||||||
flags: Qt.Dialog | Qt.WindowTitleHint
|
flags: Qt.Dialog | Qt.WindowTitleHint
|
||||||
minimumWidth: 250
|
minimumWidth: 250
|
||||||
minimumHeight: 220
|
minimumHeight: 220
|
||||||
Component.onCompleted: Nheko.reparent(hiddenEventsDialog)
|
|
||||||
|
HiddenEvents {
|
||||||
|
id: hiddenEvents
|
||||||
|
|
||||||
|
roomid: hiddenEventsDialog.roomid
|
||||||
|
}
|
||||||
|
|
||||||
title: {
|
title: {
|
||||||
if (isRoomSetting) {
|
if (roomid) {
|
||||||
return qsTr("Hidden events for %1").arg(roomSettings.roomName);
|
return qsTr("Hidden events for %1").arg(roomName);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return qsTr("Hidden events");
|
return qsTr("Hidden events");
|
||||||
|
@ -41,8 +48,8 @@ ApplicationWindow {
|
||||||
MatrixText {
|
MatrixText {
|
||||||
id: promptLabel
|
id: promptLabel
|
||||||
text: {
|
text: {
|
||||||
if (isRoomSetting) {
|
if (roomid) {
|
||||||
return qsTr("These events will be be <b>shown</b> in %1:").arg(roomSettings.roomName);
|
return qsTr("These events will be be <b>shown</b> in %1:").arg(roomName);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return qsTr("These events will be be <b>shown</b> in all rooms:");
|
return qsTr("These events will be be <b>shown</b> in all rooms:");
|
||||||
|
@ -71,9 +78,9 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
ToggleButton {
|
ToggleButton {
|
||||||
id: toggleRoomMember
|
|
||||||
checked: !roomSettings.eventHidden("m.room.member")
|
|
||||||
Layout.alignment: Qt.AlignRight
|
Layout.alignment: Qt.AlignRight
|
||||||
|
checked: !hiddenEvents.hiddenEvents.includes(MtxEvent.Member)
|
||||||
|
onToggled: hiddenEvents.toggle(MtxEvent.Member)
|
||||||
}
|
}
|
||||||
|
|
||||||
MatrixText {
|
MatrixText {
|
||||||
|
@ -88,9 +95,9 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
ToggleButton {
|
ToggleButton {
|
||||||
id: toggleRoomPowerLevels
|
|
||||||
checked: !roomSettings.eventHidden("m.room.power_levels")
|
|
||||||
Layout.alignment: Qt.AlignRight
|
Layout.alignment: Qt.AlignRight
|
||||||
|
checked: !hiddenEvents.hiddenEvents.includes(MtxEvent.PowerLevels)
|
||||||
|
onToggled: hiddenEvents.toggle(MtxEvent.PowerLevels)
|
||||||
}
|
}
|
||||||
|
|
||||||
MatrixText {
|
MatrixText {
|
||||||
|
@ -99,9 +106,9 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
ToggleButton {
|
ToggleButton {
|
||||||
id: toggleSticker
|
|
||||||
Layout.alignment: Qt.AlignRight
|
Layout.alignment: Qt.AlignRight
|
||||||
checked: !roomSettings.eventHidden("m.sticker")
|
checked: !hiddenEvents.hiddenEvents.includes(MtxEvent.Sticker)
|
||||||
|
onToggled: hiddenEvents.toggle(MtxEvent.Sticker)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,23 +118,10 @@ ApplicationWindow {
|
||||||
|
|
||||||
standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel
|
standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
let events = new Array;
|
hiddenEvents.save();
|
||||||
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, roomSettings.roomId);
|
|
||||||
|
|
||||||
hiddenEventsDialog.close();
|
|
||||||
}
|
|
||||||
onRejected: {
|
|
||||||
hiddenEventsDialog.close();
|
hiddenEventsDialog.close();
|
||||||
}
|
}
|
||||||
|
onRejected: hiddenEventsDialog.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -260,7 +260,8 @@ ApplicationWindow {
|
||||||
|
|
||||||
HiddenEventsDialog {
|
HiddenEventsDialog {
|
||||||
id: hiddenEventsDialog
|
id: hiddenEventsDialog
|
||||||
isRoomSetting: true
|
roomid: roomSettings.roomId
|
||||||
|
roomName: roomSettings.roomName
|
||||||
}
|
}
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
|
|
|
@ -173,24 +173,31 @@ Cache::isHiddenEvent(lmdb::txn &txn,
|
||||||
}
|
}
|
||||||
|
|
||||||
mtx::events::account_data::nheko_extensions::HiddenEvents hiddenEvents;
|
mtx::events::account_data::nheko_extensions::HiddenEvents hiddenEvents;
|
||||||
hiddenEvents.hidden_event_types = {
|
hiddenEvents.hidden_event_types = std::vector{
|
||||||
EventType::Reaction, EventType::CallCandidates, EventType::Unsupported};
|
EventType::Reaction,
|
||||||
|
EventType::CallCandidates,
|
||||||
|
EventType::Unsupported,
|
||||||
|
};
|
||||||
|
|
||||||
if (auto temp = getAccountData(txn, mtx::events::EventType::NhekoHiddenEvents, ""))
|
if (auto temp = getAccountData(txn, mtx::events::EventType::NhekoHiddenEvents, "")) {
|
||||||
hiddenEvents =
|
auto h = std::get<
|
||||||
std::move(std::get<mtx::events::AccountDataEvent<
|
mtx::events::AccountDataEvent<mtx::events::account_data::nheko_extensions::HiddenEvents>>(
|
||||||
mtx::events::account_data::nheko_extensions::HiddenEvents>>(*temp)
|
*temp);
|
||||||
.content);
|
if (h.content.hidden_event_types)
|
||||||
if (auto temp = getAccountData(txn, mtx::events::EventType::NhekoHiddenEvents, room_id))
|
hiddenEvents = std::move(h.content);
|
||||||
hiddenEvents =
|
}
|
||||||
std::move(std::get<mtx::events::AccountDataEvent<
|
if (auto temp = getAccountData(txn, mtx::events::EventType::NhekoHiddenEvents, room_id)) {
|
||||||
mtx::events::account_data::nheko_extensions::HiddenEvents>>(*temp)
|
auto h = std::get<
|
||||||
.content);
|
mtx::events::AccountDataEvent<mtx::events::account_data::nheko_extensions::HiddenEvents>>(
|
||||||
|
*temp);
|
||||||
|
if (h.content.hidden_event_types)
|
||||||
|
hiddenEvents = std::move(h.content);
|
||||||
|
}
|
||||||
|
|
||||||
return std::visit(
|
return std::visit(
|
||||||
[hiddenEvents](const auto &ev) {
|
[hiddenEvents](const auto &ev) {
|
||||||
return std::any_of(hiddenEvents.hidden_event_types.begin(),
|
return std::any_of(hiddenEvents.hidden_event_types->begin(),
|
||||||
hiddenEvents.hidden_event_types.end(),
|
hiddenEvents.hidden_event_types->end(),
|
||||||
[ev](EventType type) { return type == ev.type; });
|
[ev](EventType type) { return type == ev.type; });
|
||||||
},
|
},
|
||||||
e);
|
e);
|
||||||
|
@ -1515,6 +1522,16 @@ Cache::saveState(const mtx::responses::Sync &res)
|
||||||
for (const auto &ev : res.account_data.events)
|
for (const auto &ev : res.account_data.events)
|
||||||
std::visit(
|
std::visit(
|
||||||
[&txn, &accountDataDb](const auto &event) {
|
[&txn, &accountDataDb](const auto &event) {
|
||||||
|
if constexpr (std::is_same_v<
|
||||||
|
std::remove_cv_t<std::remove_reference_t<decltype(event)>>,
|
||||||
|
AccountDataEvent<
|
||||||
|
mtx::events::account_data::nheko_extensions::HiddenEvents>>) {
|
||||||
|
if (!event.content.hidden_event_types) {
|
||||||
|
accountDataDb.del(txn, "im.nheko.hidden_events");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto j = json(event);
|
auto j = json(event);
|
||||||
accountDataDb.put(txn, j["type"].get<std::string>(), j.dump());
|
accountDataDb.put(txn, j["type"].get<std::string>(), j.dump());
|
||||||
},
|
},
|
||||||
|
@ -1589,6 +1606,15 @@ Cache::saveState(const mtx::responses::Sync &res)
|
||||||
for (const auto &evt : room.second.account_data.events) {
|
for (const auto &evt : room.second.account_data.events) {
|
||||||
std::visit(
|
std::visit(
|
||||||
[&txn, &accountDataDb](const auto &event) {
|
[&txn, &accountDataDb](const auto &event) {
|
||||||
|
if constexpr (std::is_same_v<
|
||||||
|
std::remove_cv_t<std::remove_reference_t<decltype(event)>>,
|
||||||
|
AccountDataEvent<mtx::events::account_data::nheko_extensions::
|
||||||
|
HiddenEvents>>) {
|
||||||
|
if (!event.content.hidden_event_types) {
|
||||||
|
accountDataDb.del(txn, "im.nheko.hidden_events");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
auto j = json(event);
|
auto j = json(event);
|
||||||
accountDataDb.put(txn, j["type"].get<std::string>(), j.dump());
|
accountDataDb.put(txn, j["type"].get<std::string>(), j.dump());
|
||||||
},
|
},
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include "encryption/SelfVerificationStatus.h"
|
#include "encryption/SelfVerificationStatus.h"
|
||||||
#include "timeline/DelegateChooser.h"
|
#include "timeline/DelegateChooser.h"
|
||||||
#include "timeline/TimelineViewManager.h"
|
#include "timeline/TimelineViewManager.h"
|
||||||
|
#include "ui/HiddenEvents.h"
|
||||||
#include "ui/MxcAnimatedImage.h"
|
#include "ui/MxcAnimatedImage.h"
|
||||||
#include "ui/MxcMediaProxy.h"
|
#include "ui/MxcMediaProxy.h"
|
||||||
#include "ui/NhekoCursorShape.h"
|
#include "ui/NhekoCursorShape.h"
|
||||||
|
@ -168,6 +169,7 @@ MainWindow::registerQmlTypes()
|
||||||
qmlRegisterType<RoomDirectoryModel>("im.nheko", 1, 0, "RoomDirectoryModel");
|
qmlRegisterType<RoomDirectoryModel>("im.nheko", 1, 0, "RoomDirectoryModel");
|
||||||
qmlRegisterType<LoginPage>("im.nheko", 1, 0, "Login");
|
qmlRegisterType<LoginPage>("im.nheko", 1, 0, "Login");
|
||||||
qmlRegisterType<RegisterPage>("im.nheko", 1, 0, "Registration");
|
qmlRegisterType<RegisterPage>("im.nheko", 1, 0, "Registration");
|
||||||
|
qmlRegisterType<HiddenEvents>("im.nheko", 1, 0, "HiddenEvents");
|
||||||
qmlRegisterUncreatableType<DeviceVerificationFlow>(
|
qmlRegisterUncreatableType<DeviceVerificationFlow>(
|
||||||
"im.nheko",
|
"im.nheko",
|
||||||
1,
|
1,
|
||||||
|
|
|
@ -50,59 +50,7 @@ struct RoomEventType
|
||||||
template<class T>
|
template<class T>
|
||||||
qml_mtx_events::EventType operator()(const mtx::events::Event<T> &e)
|
qml_mtx_events::EventType operator()(const mtx::events::Event<T> &e)
|
||||||
{
|
{
|
||||||
using mtx::events::EventType;
|
return qml_mtx_events::toRoomEventType(e.type);
|
||||||
switch (e.type) {
|
|
||||||
case EventType::RoomKeyRequest:
|
|
||||||
return qml_mtx_events::EventType::KeyRequest;
|
|
||||||
case EventType::Reaction:
|
|
||||||
return qml_mtx_events::EventType::Reaction;
|
|
||||||
case EventType::RoomAliases:
|
|
||||||
return qml_mtx_events::EventType::Aliases;
|
|
||||||
case EventType::RoomAvatar:
|
|
||||||
return qml_mtx_events::EventType::Avatar;
|
|
||||||
case EventType::RoomCanonicalAlias:
|
|
||||||
return qml_mtx_events::EventType::CanonicalAlias;
|
|
||||||
case EventType::RoomCreate:
|
|
||||||
return qml_mtx_events::EventType::RoomCreate;
|
|
||||||
case EventType::RoomEncrypted:
|
|
||||||
return qml_mtx_events::EventType::Encrypted;
|
|
||||||
case EventType::RoomEncryption:
|
|
||||||
return qml_mtx_events::EventType::Encryption;
|
|
||||||
case EventType::RoomGuestAccess:
|
|
||||||
return qml_mtx_events::EventType::RoomGuestAccess;
|
|
||||||
case EventType::RoomHistoryVisibility:
|
|
||||||
return qml_mtx_events::EventType::RoomHistoryVisibility;
|
|
||||||
case EventType::RoomJoinRules:
|
|
||||||
return qml_mtx_events::EventType::RoomJoinRules;
|
|
||||||
case EventType::RoomMember:
|
|
||||||
return qml_mtx_events::EventType::Member;
|
|
||||||
case EventType::RoomMessage:
|
|
||||||
return qml_mtx_events::EventType::UnknownMessage;
|
|
||||||
case EventType::RoomName:
|
|
||||||
return qml_mtx_events::EventType::Name;
|
|
||||||
case EventType::RoomPowerLevels:
|
|
||||||
return qml_mtx_events::EventType::PowerLevels;
|
|
||||||
case EventType::RoomTopic:
|
|
||||||
return qml_mtx_events::EventType::Topic;
|
|
||||||
case EventType::RoomTombstone:
|
|
||||||
return qml_mtx_events::EventType::Tombstone;
|
|
||||||
case EventType::RoomRedaction:
|
|
||||||
return qml_mtx_events::EventType::Redaction;
|
|
||||||
case EventType::RoomPinnedEvents:
|
|
||||||
return qml_mtx_events::EventType::PinnedEvents;
|
|
||||||
case EventType::Sticker:
|
|
||||||
return qml_mtx_events::EventType::Sticker;
|
|
||||||
case EventType::Tag:
|
|
||||||
return qml_mtx_events::EventType::Tag;
|
|
||||||
case EventType::SpaceParent:
|
|
||||||
return qml_mtx_events::EventType::SpaceParent;
|
|
||||||
case EventType::SpaceChild:
|
|
||||||
return qml_mtx_events::EventType::SpaceChild;
|
|
||||||
case EventType::Unsupported:
|
|
||||||
return qml_mtx_events::EventType::Unsupported;
|
|
||||||
default:
|
|
||||||
return qml_mtx_events::EventType::UnknownMessage;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Audio> &)
|
qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Audio> &)
|
||||||
{
|
{
|
||||||
|
@ -198,6 +146,64 @@ struct RoomEventType
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qml_mtx_events::EventType
|
||||||
|
qml_mtx_events::toRoomEventType(mtx::events::EventType e)
|
||||||
|
{
|
||||||
|
using mtx::events::EventType;
|
||||||
|
switch (e) {
|
||||||
|
case EventType::RoomKeyRequest:
|
||||||
|
return qml_mtx_events::EventType::KeyRequest;
|
||||||
|
case EventType::Reaction:
|
||||||
|
return qml_mtx_events::EventType::Reaction;
|
||||||
|
case EventType::RoomAliases:
|
||||||
|
return qml_mtx_events::EventType::Aliases;
|
||||||
|
case EventType::RoomAvatar:
|
||||||
|
return qml_mtx_events::EventType::Avatar;
|
||||||
|
case EventType::RoomCanonicalAlias:
|
||||||
|
return qml_mtx_events::EventType::CanonicalAlias;
|
||||||
|
case EventType::RoomCreate:
|
||||||
|
return qml_mtx_events::EventType::RoomCreate;
|
||||||
|
case EventType::RoomEncrypted:
|
||||||
|
return qml_mtx_events::EventType::Encrypted;
|
||||||
|
case EventType::RoomEncryption:
|
||||||
|
return qml_mtx_events::EventType::Encryption;
|
||||||
|
case EventType::RoomGuestAccess:
|
||||||
|
return qml_mtx_events::EventType::RoomGuestAccess;
|
||||||
|
case EventType::RoomHistoryVisibility:
|
||||||
|
return qml_mtx_events::EventType::RoomHistoryVisibility;
|
||||||
|
case EventType::RoomJoinRules:
|
||||||
|
return qml_mtx_events::EventType::RoomJoinRules;
|
||||||
|
case EventType::RoomMember:
|
||||||
|
return qml_mtx_events::EventType::Member;
|
||||||
|
case EventType::RoomMessage:
|
||||||
|
return qml_mtx_events::EventType::UnknownMessage;
|
||||||
|
case EventType::RoomName:
|
||||||
|
return qml_mtx_events::EventType::Name;
|
||||||
|
case EventType::RoomPowerLevels:
|
||||||
|
return qml_mtx_events::EventType::PowerLevels;
|
||||||
|
case EventType::RoomTopic:
|
||||||
|
return qml_mtx_events::EventType::Topic;
|
||||||
|
case EventType::RoomTombstone:
|
||||||
|
return qml_mtx_events::EventType::Tombstone;
|
||||||
|
case EventType::RoomRedaction:
|
||||||
|
return qml_mtx_events::EventType::Redaction;
|
||||||
|
case EventType::RoomPinnedEvents:
|
||||||
|
return qml_mtx_events::EventType::PinnedEvents;
|
||||||
|
case EventType::Sticker:
|
||||||
|
return qml_mtx_events::EventType::Sticker;
|
||||||
|
case EventType::Tag:
|
||||||
|
return qml_mtx_events::EventType::Tag;
|
||||||
|
case EventType::SpaceParent:
|
||||||
|
return qml_mtx_events::EventType::SpaceParent;
|
||||||
|
case EventType::SpaceChild:
|
||||||
|
return qml_mtx_events::EventType::SpaceChild;
|
||||||
|
case EventType::Unsupported:
|
||||||
|
return qml_mtx_events::EventType::Unsupported;
|
||||||
|
default:
|
||||||
|
return qml_mtx_events::EventType::UnknownMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
qml_mtx_events::EventType
|
qml_mtx_events::EventType
|
||||||
toRoomEventType(const mtx::events::collections::TimelineEvents &event)
|
toRoomEventType(const mtx::events::collections::TimelineEvents &event)
|
||||||
{
|
{
|
||||||
|
|
|
@ -125,6 +125,8 @@ enum EventType
|
||||||
};
|
};
|
||||||
Q_ENUM_NS(EventType)
|
Q_ENUM_NS(EventType)
|
||||||
mtx::events::EventType fromRoomEventType(qml_mtx_events::EventType);
|
mtx::events::EventType fromRoomEventType(qml_mtx_events::EventType);
|
||||||
|
qml_mtx_events::EventType
|
||||||
|
toRoomEventType(mtx::events::EventType e);
|
||||||
|
|
||||||
enum EventState
|
enum EventState
|
||||||
{
|
{
|
||||||
|
|
93
src/ui/HiddenEvents.cpp
Normal file
93
src/ui/HiddenEvents.cpp
Normal file
|
@ -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)));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
46
src/ui/HiddenEvents.h
Normal file
46
src/ui/HiddenEvents.h
Normal file
|
@ -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();
|
||||||
|
};
|
|
@ -13,7 +13,6 @@
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <mtx/events/event_type.hpp>
|
#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 <mtxclient/http/client.hpp>
|
||||||
|
@ -228,8 +227,6 @@ RoomSettings::RoomSettings(QString roomid, QObject *parent)
|
||||||
accessRules_ = 4;
|
accessRules_ = 4;
|
||||||
}
|
}
|
||||||
emit accessJoinRulesChanged();
|
emit accessJoinRulesChanged();
|
||||||
|
|
||||||
readHiddenEventsSettings(roomid_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
|
@ -641,50 +638,3 @@ RoomSettings::updateAvatar()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
RoomSettings::saveHiddenEventsSettings(const QSet<QString> &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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
RoomSettings::readHiddenEventsSettings(const QString &roomId)
|
|
||||||
{
|
|
||||||
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)) {
|
|
||||||
for (const auto event : tmp->content.hidden_event_types) {
|
|
||||||
hiddenEvents_.insert(mtx::events::to_string(event).data());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -111,9 +111,6 @@ public:
|
||||||
Q_INVOKABLE void openEditModal();
|
Q_INVOKABLE void openEditModal();
|
||||||
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 void
|
|
||||||
saveHiddenEventsSettings(const QSet<QString> &events, const QString &roomId = {});
|
|
||||||
Q_INVOKABLE bool eventHidden(QString event) const;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void loadingChanged();
|
void loadingChanged();
|
||||||
|
@ -134,7 +131,6 @@ private:
|
||||||
void updateAccessRules(const std::string &room_id,
|
void updateAccessRules(const std::string &room_id,
|
||||||
const mtx::events::state::JoinRules &,
|
const mtx::events::state::JoinRules &,
|
||||||
const mtx::events::state::GuestAccess &);
|
const mtx::events::state::GuestAccess &);
|
||||||
void readHiddenEventsSettings(const QString &roomId = {});
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString roomid_;
|
QString roomid_;
|
||||||
|
@ -143,5 +139,4 @@ private:
|
||||||
RoomInfo info_;
|
RoomInfo info_;
|
||||||
int notifications_ = 0;
|
int notifications_ = 0;
|
||||||
int accessRules_ = 0;
|
int accessRules_ = 0;
|
||||||
QSet<QString> hiddenEvents_;
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue