diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-10-13 17:37:28 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-10-13 18:19:46 +0200 |
commit | 8a4bb32b4a53399d20495bb987ea8bda29427d2a (patch) | |
tree | 17006938d1ab2cf59eefa0de974e3a2b53ac76a1 /src | |
parent | Evaluate push rules locally (diff) | |
download | nheko-8a4bb32b4a53399d20495bb987ea8bda29427d2a.tar.xz |
Add toggle to disable decrypting notifications
Diffstat (limited to 'src')
-rw-r--r-- | src/ChatPage.cpp | 3 | ||||
-rw-r--r-- | src/UserSettingsPage.cpp | 31 | ||||
-rw-r--r-- | src/UserSettingsPage.h | 7 | ||||
-rw-r--r-- | src/notifications/Manager.cpp | 8 | ||||
-rw-r--r-- | src/notifications/Manager.h | 1 |
5 files changed, 44 insertions, 6 deletions
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 1f38d763..3736ec6b 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -276,7 +276,8 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QObject *parent) if (auto encryptedEvent = std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( - &event)) { + &event); + encryptedEvent && userSettings_->decryptNotifications()) { MegolmSessionIndex index(room_id, encryptedEvent->content); auto result = olm::decryptEvent(index, *encryptedEvent); diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 6569b4a0..b91b5a29 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -88,6 +88,8 @@ UserSettings::load(std::optional<QString> profile) openImageExternal_ = settings.value(QStringLiteral("user/open_image_external"), false).toBool(); openVideoExternal_ = settings.value(QStringLiteral("user/open_video_external"), false).toBool(); decryptSidebar_ = settings.value(QStringLiteral("user/decrypt_sidebar"), true).toBool(); + decryptNotifications_ = + settings.value(QStringLiteral("user/decrypt_notifications"), true).toBool(); spaceNotifications_ = settings.value(QStringLiteral("user/space_notifications"), true).toBool(); privacyScreen_ = settings.value(QStringLiteral("user/privacy_screen"), false).toBool(); privacyScreenTimeout_ = @@ -426,6 +428,16 @@ UserSettings::setDecryptSidebar(bool state) } void +UserSettings::setDecryptNotifications(bool state) +{ + if (state == decryptNotifications_) + return; + decryptNotifications_ = state; + emit decryptNotificationsChanged(state); + save(); +} + +void UserSettings::setSpaceNotifications(bool state) { if (state == spaceNotifications_) @@ -796,6 +808,7 @@ UserSettings::save() settings.setValue(QStringLiteral("avatar_circles"), avatarCircles_); settings.setValue(QStringLiteral("decrypt_sidebar"), decryptSidebar_); + settings.setValue(QStringLiteral("decrypt_notificatons"), decryptNotifications_); settings.setValue(QStringLiteral("space_notifications"), spaceNotifications_); settings.setValue(QStringLiteral("privacy_screen"), privacyScreen_); settings.setValue(QStringLiteral("privacy_screen_timeout"), privacyScreenTimeout_); @@ -944,6 +957,8 @@ UserSettingsModel::data(const QModelIndex &index, int role) const return tr("Open videos with external program"); case DecryptSidebar: return tr("Decrypt messages in sidebar"); + case DecryptNotifications: + return tr("Decrypt notifications"); case SpaceNotifications: return tr("Show message counts for communities and tags"); case PrivacyScreen: @@ -1076,6 +1091,8 @@ UserSettingsModel::data(const QModelIndex &index, int role) const return i->openVideoExternal(); case DecryptSidebar: return i->decryptSidebar(); + case DecryptNotifications: + return i->decryptNotifications(); case SpaceNotifications: return i->spaceNotifications(); case PrivacyScreen: @@ -1233,6 +1250,8 @@ UserSettingsModel::data(const QModelIndex &index, int role) const case DecryptSidebar: return tr("Decrypt the messages shown in the sidebar.\nOnly affects messages in " "encrypted chats."); + case DecryptNotifications: + return tr("Decrypt messages shown in notifications for encrypted chats."); case SpaceNotifications: return tr("Choose where to show the total number of notifications contained within a " "community or tag."); @@ -1338,6 +1357,7 @@ UserSettingsModel::data(const QModelIndex &index, int role) const case OpenImageExternal: case OpenVideoExternal: case DecryptSidebar: + case DecryptNotifications: case PrivacyScreen: case MobileMode: case UseStunServer: @@ -1653,7 +1673,13 @@ UserSettingsModel::setData(const QModelIndex &index, const QVariant &value, int } else return false; } - return i->decryptSidebar(); + case DecryptNotifications: { + if (value.userType() == QMetaType::Bool) { + i->setDecryptNotifications(value.toBool()); + return true; + } else + return false; + } case SpaceNotifications: { if (value.userType() == QMetaType::Bool) { i->setSpaceNotifications(value.toBool()); @@ -1973,6 +1999,9 @@ UserSettingsModel::UserSettingsModel(QObject *p) connect(s.get(), &UserSettings::decryptSidebarChanged, this, [this]() { emit dataChanged(index(DecryptSidebar), index(DecryptSidebar), {Value}); }); + connect(s.get(), &UserSettings::decryptNotificationsChanged, this, [this]() { + emit dataChanged(index(DecryptNotifications), index(DecryptNotifications), {Value}); + }); connect(s.get(), &UserSettings::spaceNotificationsChanged, this, [this] { emit dataChanged(index(SpaceNotifications), index(SpaceNotifications), {Value}); }); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index 45464173..5371bfab 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -58,6 +58,8 @@ class UserSettings final : public QObject bool avatarCircles READ avatarCircles WRITE setAvatarCircles NOTIFY avatarCirclesChanged) Q_PROPERTY( bool decryptSidebar READ decryptSidebar WRITE setDecryptSidebar NOTIFY decryptSidebarChanged) + Q_PROPERTY(bool decryptNotifications READ decryptNotifications WRITE setDecryptNotifications + NOTIFY decryptNotificationsChanged) Q_PROPERTY(bool spaceNotifications READ spaceNotifications WRITE setSpaceNotifications NOTIFY spaceNotificationsChanged) Q_PROPERTY( @@ -164,6 +166,7 @@ public: void setAlertOnNotification(bool state); void setAvatarCircles(bool state); void setDecryptSidebar(bool state); + void setDecryptNotifications(bool state); void setSpaceNotifications(bool state); void setPrivacyScreen(bool state); void setPrivacyScreenTimeout(int state); @@ -206,6 +209,7 @@ public: bool groupView() const { return groupView_; } bool avatarCircles() const { return avatarCircles_; } bool decryptSidebar() const { return decryptSidebar_; } + bool decryptNotifications() const { return decryptNotifications_; } bool spaceNotifications() const { return spaceNotifications_; } bool privacyScreen() const { return privacyScreen_; } int privacyScreenTimeout() const { return privacyScreenTimeout_; } @@ -284,6 +288,7 @@ signals: void alertOnNotificationChanged(bool state); void avatarCirclesChanged(bool state); void decryptSidebarChanged(bool state); + void decryptNotificationsChanged(bool state); void spaceNotificationsChanged(bool state); void privacyScreenChanged(bool state); void privacyScreenTimeoutChanged(int state); @@ -347,6 +352,7 @@ private: bool hasAlertOnNotification_; bool avatarCircles_; bool decryptSidebar_; + bool decryptNotifications_; bool spaceNotifications_; bool privacyScreen_; int privacyScreenTimeout_; @@ -442,6 +448,7 @@ class UserSettingsModel final : public QAbstractListModel NotificationsSection, DesktopNotifications, AlertOnNotification, + DecryptNotifications, VoipSection, UseStunServer, diff --git a/src/notifications/Manager.cpp b/src/notifications/Manager.cpp index 6033cc6d..ba550530 100644 --- a/src/notifications/Manager.cpp +++ b/src/notifications/Manager.cpp @@ -36,18 +36,18 @@ NotificationsManager::getMessageTemplate(const mtx::responses::Notification ¬ } void -NotificationsManager::removeNotifications(const QString &roomId, +NotificationsManager::removeNotifications(const QString &roomId_, const std::vector<QString> &eventIds) { - std::string room_id = roomId.toStdString(); + std::string room_id = roomId_.toStdString(); std::uint64_t markerPos = 0; for (const auto &e : eventIds) { markerPos = std::max(markerPos, cache::getEventIndex(room_id, e.toStdString()).value_or(0)); } - for (const auto &[roomId, eventId] : this->notificationIds) { - if (roomId != roomId) + for (const auto &[roomId, eventId] : qAsConst(this->notificationIds)) { + if (roomId != roomId_) continue; auto idx = cache::getEventIndex(room_id, eventId.toStdString()); if (!idx || markerPos >= idx) { diff --git a/src/notifications/Manager.h b/src/notifications/Manager.h index 05f06dcf..8a5f1725 100644 --- a/src/notifications/Manager.h +++ b/src/notifications/Manager.h @@ -6,6 +6,7 @@ #pragma once #include <QImage> +#include <QMap> #include <QObject> #include <QString> |