From 2192e8bea85e78435830fcb9c8a98c50637c86f8 Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Fri, 26 Feb 2021 15:33:27 -0500 Subject: Better handle encrypted notifications --- src/notifications/ManagerMac.cpp | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'src/notifications/ManagerMac.cpp') 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 +#include + QString NotificationsManager::formatNotification(const mtx::responses::Notification ¬ification) { @@ -37,22 +39,25 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if 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>( + ¬ification.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); + } } -- cgit 1.5.1