From df998ef67194bdd633df163eef53ec628fc8e090 Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Sat, 20 Feb 2021 13:16:43 -0500 Subject: [PATCH] Get event text in event parser function --- src/notifications/Manager.cpp | 2 +- src/notifications/Manager.h | 2 +- src/notifications/ManagerLinux.cpp | 9 ++++++--- src/notifications/ManagerMac.cpp | 5 +++-- src/notifications/ManagerWin.cpp | 6 ++++-- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/notifications/Manager.cpp b/src/notifications/Manager.cpp index eee695a5..e1f59cb1 100644 --- a/src/notifications/Manager.cpp +++ b/src/notifications/Manager.cpp @@ -27,7 +27,7 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if ((mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote) ? "* " + sender + " " : sender + reply + ": ") + - formatNotification(mtx::accessors::formattedBodyWithFallback(notification.event)); + formatNotification(notification.event); systemPostNotification(room_id, event_id, room_name, sender, text, icon); } diff --git a/src/notifications/Manager.h b/src/notifications/Manager.h index 372e4998..449a609f 100644 --- a/src/notifications/Manager.h +++ b/src/notifications/Manager.h @@ -50,7 +50,7 @@ private: const QString &text, const QImage &icon); - QString formatNotification(const QString &text); + QString formatNotification(const mtx::events::collections::TimelineEvents &e); #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_HAIKU) public: diff --git a/src/notifications/ManagerLinux.cpp b/src/notifications/ManagerLinux.cpp index ab4a6d93..202f2a9d 100644 --- a/src/notifications/ManagerLinux.cpp +++ b/src/notifications/ManagerLinux.cpp @@ -11,6 +11,7 @@ #include +#include "EventAccessors.h" #include "Utils.h" NotificationsManager::NotificationsManager(QObject *parent) @@ -161,7 +162,7 @@ NotificationsManager::notificationClosed(uint id, uint reason) * specified at https://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/Markup/ */ QString -NotificationsManager::formatNotification(const QString &text) +NotificationsManager::formatNotification(const mtx::events::collections::TimelineEvents &e) { static const auto hasMarkup = std::invoke([this]() -> bool { for (auto x : dbus.call("GetCapabilities").arguments()) @@ -169,14 +170,16 @@ NotificationsManager::formatNotification(const QString &text) return true; return false; }); + if (hasMarkup) - return QString(text) + return mtx::accessors::formattedBodyWithFallback(e) .replace("", "") .replace("", "") .replace("", "") .replace("", ""); - return QTextDocumentFragment::fromHtml(text).toPlainText(); + return QTextDocumentFragment::fromHtml(mtx::accessors::formattedBodyWithFallback(e)) + .toPlainText(); } /** diff --git a/src/notifications/ManagerMac.cpp b/src/notifications/ManagerMac.cpp index c75d2283..a74df2c7 100644 --- a/src/notifications/ManagerMac.cpp +++ b/src/notifications/ManagerMac.cpp @@ -2,10 +2,11 @@ #include +#include "EventAccessors.h" #include "Utils.h" QString -NotificationsManager::formatNotification(const QString &text) +NotificationsManager::formatNotification(const mtx::events::collections::TimelineEvents &e) { - return QTextDocumentFragment::fromHtml(text).toPlainText(); + return QTextDocumentFragment::fromHtml(mtx::accessors::formattedBodyWithFallback(e)).toPlainText(); } diff --git a/src/notifications/ManagerWin.cpp b/src/notifications/ManagerWin.cpp index 3ab85a5f..47b4c178 100644 --- a/src/notifications/ManagerWin.cpp +++ b/src/notifications/ManagerWin.cpp @@ -7,6 +7,7 @@ #include +#include "EventAccessors.h" #include "Utils.h" using namespace WinToastLib; @@ -77,7 +78,8 @@ NotificationsManager::removeNotification(const QString &, const QString &) {} QString -NotificationsManager::formatNotification(const QString &text) +NotificationsManager::formatNotification(const mtx::events::collections::TimelineEvents &e) { - return QTextDocumentFragment::fromHtml(text).toPlainText(); + return QTextDocumentFragment::fromHtml(mtx::accessors::formattedBodyWithFallback(e)).toPlainText(); } +