Hidden events: Some cleanup

pull/891/head
tastytea 3 years ago committed by Nicolas Werner
parent 49b313e3b8
commit 72cfb06208
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
  1. 2
      resources/qml/dialogs/HiddenEventsDialog.qml
  2. 69
      src/ui/RoomSettings.cpp
  3. 4
      src/ui/RoomSettings.h

@ -45,7 +45,7 @@ ApplicationWindow {
return qsTr("These events will be be <b>shown</b> in %1:").arg(roomSettings.roomName);
}
else {
return qsTr("These events will be be <b>shown</b>:");
return qsTr("These events will be be <b>shown</b> in all rooms:");
}
}
font.pixelSize: Math.floor(fontMetrics.font.pixelSize * 1.2)

@ -12,7 +12,6 @@
#include <QMimeDatabase>
#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>
@ -230,7 +229,6 @@ RoomSettings::RoomSettings(QString roomid, QObject *parent)
}
emit accessJoinRulesChanged();
// Get room's hidden events and store it in member variable.
if (auto hiddenEvents = cache::client()->getAccountData(
mtx::events::EventType::NhekoHiddenEvents, roomid_.toStdString())) {
if (auto tmp = std::get_if<mtx::events::EphemeralEvent<
@ -310,12 +308,6 @@ RoomSettings::accessJoinRules()
return accessRules_;
}
bool
RoomSettings::eventHidden(const QString event) const
{
return hiddenEvents_.contains(event);
}
void
RoomSettings::enableEncryption()
{
@ -426,34 +418,6 @@ RoomSettings::openEditModal()
});
}
void
RoomSettings::saveHiddenEventsSettings(const QSet<QString> &events, const QString &roomId)
{
mtx::events::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(
mtx::events::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);
}
});
}
}
void
RoomSettings::changeNotifications(int currentIndex)
{
@ -685,3 +649,36 @@ 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);
}

@ -109,10 +109,10 @@ public:
Q_INVOKABLE void enableEncryption();
Q_INVOKABLE void updateAvatar();
Q_INVOKABLE void openEditModal();
Q_INVOKABLE void
saveHiddenEventsSettings(const QSet<QString> &events, const QString &roomId = {});
Q_INVOKABLE void changeAccessRules(int index);
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:

Loading…
Cancel
Save