2021-02-16 02:36:10 +03:00
|
|
|
#include "notifications/Manager.h"
|
|
|
|
|
|
|
|
#include "Cache.h"
|
|
|
|
#include "EventAccessors.h"
|
|
|
|
#include "Utils.h"
|
|
|
|
#include <mtx/responses/notifications.hpp>
|
|
|
|
|
|
|
|
void
|
|
|
|
NotificationsManager::postNotification(const mtx::responses::Notification ¬ification,
|
|
|
|
const QImage &icon)
|
|
|
|
{
|
|
|
|
const auto room_id = QString::fromStdString(notification.room_id);
|
|
|
|
const auto event_id = QString::fromStdString(mtx::accessors::event_id(notification.event));
|
|
|
|
const auto room_name =
|
|
|
|
QString::fromStdString(cache::singleRoomInfo(notification.room_id).name);
|
|
|
|
const auto sender = cache::displayName(
|
|
|
|
room_id, QString::fromStdString(mtx::accessors::sender(notification.event)));
|
|
|
|
|
2021-02-20 21:10:14 +03:00
|
|
|
const QString reply = (utils::isReply(notification.event)
|
|
|
|
? ""
|
|
|
|
: tr(" replied",
|
|
|
|
"Used to denote that this message is a reply to another "
|
|
|
|
"message. Displayed as 'foo replied: message'."));
|
|
|
|
|
|
|
|
// the "replied" is only added if this message is not an emote message
|
2021-02-20 20:06:43 +03:00
|
|
|
QString text =
|
|
|
|
((mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote)
|
|
|
|
? "* " + sender + " "
|
2021-02-20 21:10:14 +03:00
|
|
|
: sender + reply + ": ") +
|
2021-02-20 20:06:43 +03:00
|
|
|
formatNotification(mtx::accessors::formattedBodyWithFallback(notification.event));
|
2021-02-16 02:36:10 +03:00
|
|
|
|
|
|
|
systemPostNotification(room_id, event_id, room_name, sender, text, icon);
|
|
|
|
}
|