Get event text in event parser function

This commit is contained in:
Loren Burkholder 2021-02-20 13:16:43 -05:00 committed by Nicolas Werner
parent b57b76d948
commit df998ef671
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
5 changed files with 15 additions and 9 deletions

View file

@ -27,7 +27,7 @@ NotificationsManager::postNotification(const mtx::responses::Notification &notif
((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);
}

View file

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

View file

@ -11,6 +11,7 @@
#include <functional>
#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("<em>", "<i>")
.replace("</em>", "</i>")
.replace("<strong>", "<b>")
.replace("</strong>", "</b>");
return QTextDocumentFragment::fromHtml(text).toPlainText();
return QTextDocumentFragment::fromHtml(mtx::accessors::formattedBodyWithFallback(e))
.toPlainText();
}
/**

View file

@ -2,10 +2,11 @@
#include <QTextDocumentFragment>
#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();
}

View file

@ -7,6 +7,7 @@
#include <QTextDocumentFragment>
#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();
}