summary refs log tree commit diff
path: root/src/notifications/Manager.cpp
diff options
context:
space:
mode:
authorLoren Burkholder <computersemiexpert@outlook.com>2021-02-15 18:36:10 -0500
committerNicolas Werner <nicolas.werner@hotmail.de>2021-03-17 19:17:13 +0100
commit648844089c1786f1439ea026d1f3f5d0b757a414 (patch)
treef0d0ea22de30ba1dccc266bbda3e4c7335ed1fba /src/notifications/Manager.cpp
parentmake lint (diff)
downloadnheko-648844089c1786f1439ea026d1f3f5d0b757a414.tar.xz
Move data parsing into a dedicated function
Actually posting the notification is now the responsibility of a private function
Diffstat (limited to 'src/notifications/Manager.cpp')
-rw-r--r--src/notifications/Manager.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/notifications/Manager.cpp b/src/notifications/Manager.cpp
new file mode 100644

index 00000000..03ce345f --- /dev/null +++ b/src/notifications/Manager.cpp
@@ -0,0 +1,27 @@ +#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; + if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote) + text = + "* " + sender + " " + formatNotification(utils::event_body(notification.event)); + else + text = sender + ":" + formatNotification(utils::event_body(notification.event)); + + systemPostNotification(room_id, event_id, room_name, sender, text, icon); +}