summary refs log tree commit diff
path: root/src/notifications
diff options
context:
space:
mode:
authorLoren Burkholder <computersemiexpert@outlook.com>2021-02-26 15:33:27 -0500
committerNicolas Werner <nicolas.werner@hotmail.de>2021-03-17 19:18:06 +0100
commit2192e8bea85e78435830fcb9c8a98c50637c86f8 (patch)
treef41eeaeb2bc32652d1fb07e15e88ff6380b6eb8d /src/notifications
parentRemove unnecessary header (diff)
downloadnheko-2192e8bea85e78435830fcb9c8a98c50637c86f8.tar.xz
Better handle encrypted notifications
Diffstat (limited to 'src/notifications')
-rw-r--r--src/notifications/ManagerLinux.cpp8
-rw-r--r--src/notifications/ManagerMac.cpp33
-rw-r--r--src/notifications/ManagerWin.cpp33
3 files changed, 56 insertions, 18 deletions
diff --git a/src/notifications/ManagerLinux.cpp b/src/notifications/ManagerLinux.cpp

index ae6fdbee..56fc8221 100644 --- a/src/notifications/ManagerLinux.cpp +++ b/src/notifications/ManagerLinux.cpp
@@ -11,6 +11,7 @@ #include <QTextDocumentFragment> #include <functional> +#include <variant> #include <mtx/responses/notifications.hpp> @@ -194,6 +195,13 @@ NotificationsManager::formatNotification(const mtx::responses::Notification &not const auto sender = cache::displayName(QString::fromStdString(notification.room_id), QString::fromStdString(mtx::accessors::sender(notification.event))); + + // TODO: decrypt this message if the decryption setting is on in the UserSettings + if (auto msg = std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( + &notification.event); + msg != nullptr) + return tr("%1 sent an encrypted message").arg(sender); + const auto messageLeadIn = ((mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote) ? "* " + sender + " " diff --git a/src/notifications/ManagerMac.cpp b/src/notifications/ManagerMac.cpp
index 12d8ab6f..973afdc4 100644 --- a/src/notifications/ManagerMac.cpp +++ b/src/notifications/ManagerMac.cpp
@@ -9,6 +9,8 @@ #include <mtx/responses/notifications.hpp> +#include <variant> + QString NotificationsManager::formatNotification(const mtx::responses::Notification &notification) { @@ -37,22 +39,25 @@ NotificationsManager::postNotification(const mtx::responses::Notification &notif cache::displayName(QString::fromStdString(notification.room_id), QString::fromStdString(mtx::accessors::sender(notification.event))); - const QString messageInfo = - QString("%1 %2 a message") - .arg(sender) - .arg((utils::isReply(notification.event) - ? tr("replied to", - "Used to denote that this message is a reply to another " - "message. Displayed as 'foo replied to a message'.") - : tr("sent", - "Used to denote that this message is a normal message. Displayed as 'foo " - "sent a message'."))); - - QString text = formatNotification(notification); - QImage *image = nullptr; if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image) image = new QImage{cacheImage(notification.event)}; - objCxxPostNotification(room_name, messageInfo, text, image); + const auto isEncrypted = + std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( + &notification.event) != nullptr; + const auto isReply = utils::isReply(notification.event); + + if (isEncrypted) { + // TODO: decrypt this message if the decryption setting is on in the UserSettings + const QString messageInfo = (isReply ? tr("%1 replied with an encrypted message") + : tr("%1 sent an encrypted message")) + .arg(sender); + objCxxPostNotification(room_name, messageInfo, "", image); + } else { + const QString messageInfo = + (isReply ? tr("%1 replied to a message") : tr("%1 sent a message")).arg(sender); + objCxxPostNotification( + room_name, messageInfo, formatNotification(notification), image); + } } diff --git a/src/notifications/ManagerWin.cpp b/src/notifications/ManagerWin.cpp
index b17c6e3b..5b134c0b 100644 --- a/src/notifications/ManagerWin.cpp +++ b/src/notifications/ManagerWin.cpp
@@ -9,6 +9,8 @@ #include <QStandardPaths> #include <QTextDocumentFragment> +#include <variant> + #include "Cache.h" #include "EventAccessors.h" #include "Utils.h" @@ -52,7 +54,21 @@ NotificationsManager::postNotification(const mtx::responses::Notification &notif const auto sender = cache::displayName(QString::fromStdString(notification.room_id), QString::fromStdString(mtx::accessors::sender(notification.event))); - const auto text = formatNotification(notification); + + const auto isEncrypted = + std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( + &notification.event) != nullptr; + const auto isReply = utils::isReply(notification.event); + + if (isEncrypted) { + // TODO: decrypt this message if the decryption setting is on in the UserSettings + const QString text = (isReply ? tr("%1 replied with an encrypted message") + : tr("%1 sent an encrypted message")) + .arg(sender); + systemPostNotification(room_name, sender, text, icon); + } else { + systemPostNotification(room_name, sender, formatNotification(notification), icon); + } systemPostNotification(room_name, sender, text, icon); } @@ -98,11 +114,20 @@ NotificationsManager::formatNotification(const mtx::responses::Notification &not cache::displayName(QString::fromStdString(notification.room_id), QString::fromStdString(mtx::accessors::sender(notification.event))); + const auto messageLeadIn = + ((mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote) + ? "* " + sender + " " + : sender + + (utils::isReply(notification.event) + ? tr(" replied", + "Used to denote that this message is a reply to another " + "message. Displayed as 'foo replied: message'.") + : "") + + ": "); + return QTextDocumentFragment::fromHtml( mtx::accessors::formattedBodyWithFallback(notification.event) .replace(QRegularExpression("(<mx-reply>.+\\<\\/mx-reply\\>)"), "")) .toPlainText() - .prepend((mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote) - ? "* " + sender + " " - : ""); + .prepend(messageLeadIn); }