Add toggle to disable decrypting notifications

pull/1215/head
Nicolas Werner 2 years ago
parent 37009906bb
commit 8a4bb32b4a
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
  1. 3
      src/ChatPage.cpp
  2. 31
      src/UserSettingsPage.cpp
  3. 7
      src/UserSettingsPage.h
  4. 8
      src/notifications/Manager.cpp
  5. 1
      src/notifications/Manager.h

@ -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);

@ -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_ =
@ -425,6 +427,16 @@ UserSettings::setDecryptSidebar(bool state)
save();
}
void
UserSettings::setDecryptNotifications(bool state)
{
if (state == decryptNotifications_)
return;
decryptNotifications_ = state;
emit decryptNotificationsChanged(state);
save();
}
void
UserSettings::setSpaceNotifications(bool state)
{
@ -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});
});

@ -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,

@ -36,18 +36,18 @@ NotificationsManager::getMessageTemplate(const mtx::responses::Notification &not
}
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) {

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

Loading…
Cancel
Save