Hidden events: Make save-function reusable for global account data

This commit is contained in:
tastytea 2022-01-13 00:39:26 +01:00 committed by Nicolas Werner
parent f7ca41bc49
commit 49b313e3b8
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
3 changed files with 19 additions and 10 deletions

View file

@ -121,7 +121,7 @@ ApplicationWindow {
if (!toggleSticker.checked) {
events.push("m.sticker");
}
roomSettings.saveHiddenEventsSettings(events);
roomSettings.saveHiddenEventsSettings(events, roomSettings.roomId);
hiddenEventsDialog.close();
}

View file

@ -427,9 +427,8 @@ RoomSettings::openEditModal()
}
void
RoomSettings::saveHiddenEventsSettings(const QSet<QString> events)
RoomSettings::saveHiddenEventsSettings(const QSet<QString> &events, const QString &roomId)
{
// 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};
@ -438,12 +437,21 @@ RoomSettings::saveHiddenEventsSettings(const QSet<QString> events)
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);
}
});
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

View file

@ -109,7 +109,8 @@ public:
Q_INVOKABLE void enableEncryption();
Q_INVOKABLE void updateAvatar();
Q_INVOKABLE void openEditModal();
Q_INVOKABLE void saveHiddenEventsSettings(QSet<QString> events);
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 bool eventHidden(QString event) const;