mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Format markdown as HTML in notifications
This commit is contained in:
parent
cc3d32c65e
commit
029ae18a07
3 changed files with 12 additions and 6 deletions
|
@ -13,6 +13,7 @@
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include <mtx/responses/notifications.hpp>
|
#include <mtx/responses/notifications.hpp>
|
||||||
|
#include <cmark.h>
|
||||||
|
|
||||||
NotificationsManager::NotificationsManager(QObject *parent)
|
NotificationsManager::NotificationsManager(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
|
@ -58,6 +59,7 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if
|
||||||
const auto sender = cache::displayName(
|
const auto sender = cache::displayName(
|
||||||
room_id, QString::fromStdString(mtx::accessors::sender(notification.event)));
|
room_id, QString::fromStdString(mtx::accessors::sender(notification.event)));
|
||||||
const auto text = utils::event_body(notification.event);
|
const auto text = utils::event_body(notification.event);
|
||||||
|
const auto formattedText = cmark_markdown_to_html(text.toStdString().c_str(), text.length(), CMARK_OPT_UNSAFE);
|
||||||
|
|
||||||
QVariantMap hints;
|
QVariantMap hints;
|
||||||
hints["image-data"] = icon;
|
hints["image-data"] = icon;
|
||||||
|
@ -71,9 +73,9 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if
|
||||||
|
|
||||||
// body
|
// body
|
||||||
if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote)
|
if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote)
|
||||||
argumentList << "* " + sender + " " + text;
|
argumentList << "* " + sender + " " + formattedText;
|
||||||
else
|
else
|
||||||
argumentList << sender + ": " + text;
|
argumentList << sender + ": " + formattedText;
|
||||||
|
|
||||||
// The list of actions has always the action name and then a localized version of that
|
// The list of actions has always the action name and then a localized version of that
|
||||||
// action. Currently we just use an empty string for that.
|
// action. Currently we just use an empty string for that.
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include <mtx/responses/notifications.hpp>
|
#include <mtx/responses/notifications.hpp>
|
||||||
|
#include <cmark.h>
|
||||||
|
|
||||||
@interface NSUserNotification (CFIPrivate)
|
@interface NSUserNotification (CFIPrivate)
|
||||||
- (void)set_identityImage:(NSImage *)image;
|
- (void)set_identityImage:(NSImage *)image;
|
||||||
|
@ -26,15 +27,16 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if
|
||||||
|
|
||||||
const auto sender = cache::displayName(QString::fromStdString(notification.room_id), QString::fromStdString(mtx::accessors::sender(notification.event)));
|
const auto sender = cache::displayName(QString::fromStdString(notification.room_id), QString::fromStdString(mtx::accessors::sender(notification.event)));
|
||||||
const auto text = utils::event_body(notification.event);
|
const auto text = utils::event_body(notification.event);
|
||||||
|
const auto formattedText = cmark_markdown_to_html(text.toStdString().c_str(), text.length(), CMARK_OPT_UNSAFE);
|
||||||
|
|
||||||
NSUserNotification * notif = [[NSUserNotification alloc] init];
|
NSUserNotification * notif = [[NSUserNotification alloc] init];
|
||||||
|
|
||||||
notif.title = QString::fromStdString(cache::singleRoomInfo(notification.room_id).name).toNSString();
|
notif.title = QString::fromStdString(cache::singleRoomInfo(notification.room_id).name).toNSString();
|
||||||
notif.subtitle = QString("%1 sent a message").arg(sender).toNSString();
|
notif.subtitle = QString("%1 sent a message").arg(sender).toNSString();
|
||||||
if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote)
|
if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote)
|
||||||
notif.informativeText = QString("* ").append(sender).append(" ").append(text).toNSString();
|
notif.informativeText = QString("* ").append(sender).append(" ").append(formattedText).toNSString();
|
||||||
else
|
else
|
||||||
notif.informativeText = text.toNSString();
|
notif.informativeText = formattedText.toNSString();
|
||||||
notif.soundName = NSUserNotificationDefaultSoundName;
|
notif.soundName = NSUserNotificationDefaultSoundName;
|
||||||
|
|
||||||
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: notif];
|
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: notif];
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include <mtx/responses/notifications.hpp>
|
#include <mtx/responses/notifications.hpp>
|
||||||
|
#include <cmark.h>
|
||||||
|
|
||||||
using namespace WinToastLib;
|
using namespace WinToastLib;
|
||||||
|
|
||||||
|
@ -53,6 +54,7 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if
|
||||||
cache::displayName(QString::fromStdString(notification.room_id),
|
cache::displayName(QString::fromStdString(notification.room_id),
|
||||||
QString::fromStdString(mtx::accessors::sender(notification.event)));
|
QString::fromStdString(mtx::accessors::sender(notification.event)));
|
||||||
const auto text = utils::event_body(notification.event);
|
const auto text = utils::event_body(notification.event);
|
||||||
|
const auto formattedText = cmark_markdown_to_html(text.toStdString().c_str(), text.length(), CMARK_OPT_UNSAFE);
|
||||||
|
|
||||||
if (!isInitialized)
|
if (!isInitialized)
|
||||||
init();
|
init();
|
||||||
|
@ -66,10 +68,10 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if
|
||||||
WinToastTemplate::FirstLine);
|
WinToastTemplate::FirstLine);
|
||||||
if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote)
|
if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote)
|
||||||
templ.setTextField(
|
templ.setTextField(
|
||||||
QString("* ").append(sender).append(" ").append(text).toStdWString(),
|
QString("* ").append(sender).append(" ").append(formattedText).toStdWString(),
|
||||||
WinToastTemplate::SecondLine);
|
WinToastTemplate::SecondLine);
|
||||||
else
|
else
|
||||||
templ.setTextField(QString("%1").arg(text).toStdWString(),
|
templ.setTextField(QString("%1").arg(formattedText).toStdWString(),
|
||||||
WinToastTemplate::SecondLine);
|
WinToastTemplate::SecondLine);
|
||||||
// TODO: implement room or user avatar
|
// TODO: implement room or user avatar
|
||||||
// templ.setImagePath(L"C:/example.png");
|
// templ.setImagePath(L"C:/example.png");
|
||||||
|
|
Loading…
Reference in a new issue