summary refs log tree commit diff
path: root/src/notifications/ManagerMac.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-03-17 19:17:57 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2021-03-17 19:17:57 +0100
commitf578272a0d645bcfae5d70f6e4aa1dc4649511f1 (patch)
tree938cd7acff3b28bdc9a49a352be2998ab079d753 /src/notifications/ManagerMac.cpp
parentAdd regex to remove replies in notifications (diff)
downloadnheko-f578272a0d645bcfae5d70f6e4aa1dc4649511f1.tar.xz
Rewrite notification posting logic
This does away with the nice abstraction layers in order to easily get the best-looking notifications for each platform.
Diffstat (limited to 'src/notifications/ManagerMac.cpp')
-rw-r--r--src/notifications/ManagerMac.cpp50
1 files changed, 46 insertions, 4 deletions
diff --git a/src/notifications/ManagerMac.cpp b/src/notifications/ManagerMac.cpp

index c9678638..12d8ab6f 100644 --- a/src/notifications/ManagerMac.cpp +++ b/src/notifications/ManagerMac.cpp
@@ -3,14 +3,56 @@ #include <QRegularExpression> #include <QTextDocumentFragment> +#include "Cache.h" #include "EventAccessors.h" #include "Utils.h" +#include <mtx/responses/notifications.hpp> + QString -NotificationsManager::formatNotification(const mtx::events::collections::TimelineEvents &e) +NotificationsManager::formatNotification(const mtx::responses::Notification &notification) { + const auto sender = + cache::displayName(QString::fromStdString(notification.room_id), + QString::fromStdString(mtx::accessors::sender(notification.event))); + return QTextDocumentFragment::fromHtml( - mtx::accessors::formattedBodyWithFallback(e).replace( - QRegularExpression("(<mx-reply>.+\\<\\/mx-reply\\>)"), "")) - .toPlainText(); + mtx::accessors::formattedBodyWithFallback(notification.event) + .replace(QRegularExpression("(<mx-reply>.+\\<\\/mx-reply\\>)"), "")) + .toPlainText() + .prepend((mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote) + ? "* " + sender + " " + : ""); +} + +void +NotificationsManager::postNotification(const mtx::responses::Notification &notification, + const QImage &icon) +{ + Q_UNUSED(icon) + + const auto room_name = + QString::fromStdString(cache::singleRoomInfo(notification.room_id).name); + const auto sender = + 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); }