Add toggle to disable decrypting notifications

This commit is contained in:
Nicolas Werner 2022-10-13 17:37:28 +02:00
parent 37009906bb
commit 8a4bb32b4a
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
5 changed files with 44 additions and 6 deletions

View file

@ -276,7 +276,8 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QObject *parent)
if (auto encryptedEvent = if (auto encryptedEvent =
std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
&event)) { &event);
encryptedEvent && userSettings_->decryptNotifications()) {
MegolmSessionIndex index(room_id, encryptedEvent->content); MegolmSessionIndex index(room_id, encryptedEvent->content);
auto result = olm::decryptEvent(index, *encryptedEvent); auto result = olm::decryptEvent(index, *encryptedEvent);

View file

@ -88,6 +88,8 @@ UserSettings::load(std::optional<QString> profile)
openImageExternal_ = settings.value(QStringLiteral("user/open_image_external"), false).toBool(); openImageExternal_ = settings.value(QStringLiteral("user/open_image_external"), false).toBool();
openVideoExternal_ = settings.value(QStringLiteral("user/open_video_external"), false).toBool(); openVideoExternal_ = settings.value(QStringLiteral("user/open_video_external"), false).toBool();
decryptSidebar_ = settings.value(QStringLiteral("user/decrypt_sidebar"), true).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(); spaceNotifications_ = settings.value(QStringLiteral("user/space_notifications"), true).toBool();
privacyScreen_ = settings.value(QStringLiteral("user/privacy_screen"), false).toBool(); privacyScreen_ = settings.value(QStringLiteral("user/privacy_screen"), false).toBool();
privacyScreenTimeout_ = privacyScreenTimeout_ =
@ -425,6 +427,16 @@ UserSettings::setDecryptSidebar(bool state)
save(); save();
} }
void
UserSettings::setDecryptNotifications(bool state)
{
if (state == decryptNotifications_)
return;
decryptNotifications_ = state;
emit decryptNotificationsChanged(state);
save();
}
void void
UserSettings::setSpaceNotifications(bool state) UserSettings::setSpaceNotifications(bool state)
{ {
@ -796,6 +808,7 @@ UserSettings::save()
settings.setValue(QStringLiteral("avatar_circles"), avatarCircles_); settings.setValue(QStringLiteral("avatar_circles"), avatarCircles_);
settings.setValue(QStringLiteral("decrypt_sidebar"), decryptSidebar_); settings.setValue(QStringLiteral("decrypt_sidebar"), decryptSidebar_);
settings.setValue(QStringLiteral("decrypt_notificatons"), decryptNotifications_);
settings.setValue(QStringLiteral("space_notifications"), spaceNotifications_); settings.setValue(QStringLiteral("space_notifications"), spaceNotifications_);
settings.setValue(QStringLiteral("privacy_screen"), privacyScreen_); settings.setValue(QStringLiteral("privacy_screen"), privacyScreen_);
settings.setValue(QStringLiteral("privacy_screen_timeout"), privacyScreenTimeout_); 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"); return tr("Open videos with external program");
case DecryptSidebar: case DecryptSidebar:
return tr("Decrypt messages in sidebar"); return tr("Decrypt messages in sidebar");
case DecryptNotifications:
return tr("Decrypt notifications");
case SpaceNotifications: case SpaceNotifications:
return tr("Show message counts for communities and tags"); return tr("Show message counts for communities and tags");
case PrivacyScreen: case PrivacyScreen:
@ -1076,6 +1091,8 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
return i->openVideoExternal(); return i->openVideoExternal();
case DecryptSidebar: case DecryptSidebar:
return i->decryptSidebar(); return i->decryptSidebar();
case DecryptNotifications:
return i->decryptNotifications();
case SpaceNotifications: case SpaceNotifications:
return i->spaceNotifications(); return i->spaceNotifications();
case PrivacyScreen: case PrivacyScreen:
@ -1233,6 +1250,8 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
case DecryptSidebar: case DecryptSidebar:
return tr("Decrypt the messages shown in the sidebar.\nOnly affects messages in " return tr("Decrypt the messages shown in the sidebar.\nOnly affects messages in "
"encrypted chats."); "encrypted chats.");
case DecryptNotifications:
return tr("Decrypt messages shown in notifications for encrypted chats.");
case SpaceNotifications: case SpaceNotifications:
return tr("Choose where to show the total number of notifications contained within a " return tr("Choose where to show the total number of notifications contained within a "
"community or tag."); "community or tag.");
@ -1338,6 +1357,7 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
case OpenImageExternal: case OpenImageExternal:
case OpenVideoExternal: case OpenVideoExternal:
case DecryptSidebar: case DecryptSidebar:
case DecryptNotifications:
case PrivacyScreen: case PrivacyScreen:
case MobileMode: case MobileMode:
case UseStunServer: case UseStunServer:
@ -1653,7 +1673,13 @@ UserSettingsModel::setData(const QModelIndex &index, const QVariant &value, int
} else } else
return false; return false;
} }
return i->decryptSidebar(); case DecryptNotifications: {
if (value.userType() == QMetaType::Bool) {
i->setDecryptNotifications(value.toBool());
return true;
} else
return false;
}
case SpaceNotifications: { case SpaceNotifications: {
if (value.userType() == QMetaType::Bool) { if (value.userType() == QMetaType::Bool) {
i->setSpaceNotifications(value.toBool()); i->setSpaceNotifications(value.toBool());
@ -1973,6 +1999,9 @@ UserSettingsModel::UserSettingsModel(QObject *p)
connect(s.get(), &UserSettings::decryptSidebarChanged, this, [this]() { connect(s.get(), &UserSettings::decryptSidebarChanged, this, [this]() {
emit dataChanged(index(DecryptSidebar), index(DecryptSidebar), {Value}); 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] { connect(s.get(), &UserSettings::spaceNotificationsChanged, this, [this] {
emit dataChanged(index(SpaceNotifications), index(SpaceNotifications), {Value}); emit dataChanged(index(SpaceNotifications), index(SpaceNotifications), {Value});
}); });

View file

@ -58,6 +58,8 @@ class UserSettings final : public QObject
bool avatarCircles READ avatarCircles WRITE setAvatarCircles NOTIFY avatarCirclesChanged) bool avatarCircles READ avatarCircles WRITE setAvatarCircles NOTIFY avatarCirclesChanged)
Q_PROPERTY( Q_PROPERTY(
bool decryptSidebar READ decryptSidebar WRITE setDecryptSidebar NOTIFY decryptSidebarChanged) 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 Q_PROPERTY(bool spaceNotifications READ spaceNotifications WRITE setSpaceNotifications NOTIFY
spaceNotificationsChanged) spaceNotificationsChanged)
Q_PROPERTY( Q_PROPERTY(
@ -164,6 +166,7 @@ public:
void setAlertOnNotification(bool state); void setAlertOnNotification(bool state);
void setAvatarCircles(bool state); void setAvatarCircles(bool state);
void setDecryptSidebar(bool state); void setDecryptSidebar(bool state);
void setDecryptNotifications(bool state);
void setSpaceNotifications(bool state); void setSpaceNotifications(bool state);
void setPrivacyScreen(bool state); void setPrivacyScreen(bool state);
void setPrivacyScreenTimeout(int state); void setPrivacyScreenTimeout(int state);
@ -206,6 +209,7 @@ public:
bool groupView() const { return groupView_; } bool groupView() const { return groupView_; }
bool avatarCircles() const { return avatarCircles_; } bool avatarCircles() const { return avatarCircles_; }
bool decryptSidebar() const { return decryptSidebar_; } bool decryptSidebar() const { return decryptSidebar_; }
bool decryptNotifications() const { return decryptNotifications_; }
bool spaceNotifications() const { return spaceNotifications_; } bool spaceNotifications() const { return spaceNotifications_; }
bool privacyScreen() const { return privacyScreen_; } bool privacyScreen() const { return privacyScreen_; }
int privacyScreenTimeout() const { return privacyScreenTimeout_; } int privacyScreenTimeout() const { return privacyScreenTimeout_; }
@ -284,6 +288,7 @@ signals:
void alertOnNotificationChanged(bool state); void alertOnNotificationChanged(bool state);
void avatarCirclesChanged(bool state); void avatarCirclesChanged(bool state);
void decryptSidebarChanged(bool state); void decryptSidebarChanged(bool state);
void decryptNotificationsChanged(bool state);
void spaceNotificationsChanged(bool state); void spaceNotificationsChanged(bool state);
void privacyScreenChanged(bool state); void privacyScreenChanged(bool state);
void privacyScreenTimeoutChanged(int state); void privacyScreenTimeoutChanged(int state);
@ -347,6 +352,7 @@ private:
bool hasAlertOnNotification_; bool hasAlertOnNotification_;
bool avatarCircles_; bool avatarCircles_;
bool decryptSidebar_; bool decryptSidebar_;
bool decryptNotifications_;
bool spaceNotifications_; bool spaceNotifications_;
bool privacyScreen_; bool privacyScreen_;
int privacyScreenTimeout_; int privacyScreenTimeout_;
@ -442,6 +448,7 @@ class UserSettingsModel final : public QAbstractListModel
NotificationsSection, NotificationsSection,
DesktopNotifications, DesktopNotifications,
AlertOnNotification, AlertOnNotification,
DecryptNotifications,
VoipSection, VoipSection,
UseStunServer, UseStunServer,

View file

@ -36,18 +36,18 @@ NotificationsManager::getMessageTemplate(const mtx::responses::Notification &not
} }
void void
NotificationsManager::removeNotifications(const QString &roomId, NotificationsManager::removeNotifications(const QString &roomId_,
const std::vector<QString> &eventIds) const std::vector<QString> &eventIds)
{ {
std::string room_id = roomId.toStdString(); std::string room_id = roomId_.toStdString();
std::uint64_t markerPos = 0; std::uint64_t markerPos = 0;
for (const auto &e : eventIds) { for (const auto &e : eventIds) {
markerPos = std::max(markerPos, cache::getEventIndex(room_id, e.toStdString()).value_or(0)); markerPos = std::max(markerPos, cache::getEventIndex(room_id, e.toStdString()).value_or(0));
} }
for (const auto &[roomId, eventId] : this->notificationIds) { for (const auto &[roomId, eventId] : qAsConst(this->notificationIds)) {
if (roomId != roomId) if (roomId != roomId_)
continue; continue;
auto idx = cache::getEventIndex(room_id, eventId.toStdString()); auto idx = cache::getEventIndex(room_id, eventId.toStdString());
if (!idx || markerPos >= idx) { if (!idx || markerPos >= idx) {

View file

@ -6,6 +6,7 @@
#pragma once #pragma once
#include <QImage> #include <QImage>
#include <QMap>
#include <QObject> #include <QObject>
#include <QString> #include <QString>