2021-02-16 02:36:10 +03:00
|
|
|
#include "Manager.h"
|
|
|
|
|
2021-02-20 22:00:13 +03:00
|
|
|
#include <QRegularExpression>
|
2021-02-16 02:36:10 +03:00
|
|
|
#include <QTextDocumentFragment>
|
|
|
|
|
2021-03-17 21:17:57 +03:00
|
|
|
#include "Cache.h"
|
2021-02-20 21:16:43 +03:00
|
|
|
#include "EventAccessors.h"
|
2021-02-16 02:36:10 +03:00
|
|
|
#include "Utils.h"
|
|
|
|
|
2021-03-17 21:17:57 +03:00
|
|
|
#include <mtx/responses/notifications.hpp>
|
|
|
|
|
2021-02-16 02:36:10 +03:00
|
|
|
QString
|
2021-03-17 21:17:57 +03:00
|
|
|
NotificationsManager::formatNotification(const mtx::responses::Notification ¬ification)
|
2021-02-16 02:36:10 +03:00
|
|
|
{
|
2021-03-17 21:17:57 +03:00
|
|
|
const auto sender =
|
|
|
|
cache::displayName(QString::fromStdString(notification.room_id),
|
|
|
|
QString::fromStdString(mtx::accessors::sender(notification.event)));
|
|
|
|
|
2021-02-20 22:00:13 +03:00
|
|
|
return QTextDocumentFragment::fromHtml(
|
2021-03-17 21:17:57 +03:00
|
|
|
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 ¬ification,
|
|
|
|
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);
|
2021-02-16 02:36:10 +03:00
|
|
|
}
|