summary refs log tree commit diff
path: root/src/notifications/Manager.cpp
blob: 6550445d70487c1004feb0ca3f8d30120fb3a6e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#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 &notification,
                                       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)));

        QString text =
          ((mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote)
             ? "* " + sender + " "
             : sender + ": ") +
          formatNotification(mtx::accessors::formattedBodyWithFallback(notification.event));

        systemPostNotification(room_id, event_id, room_name, sender, text, icon);
}