Move notification parsing into postNotification
1 files changed, 15 insertions, 14 deletions
diff --git a/src/notifications/ManagerMac.mm b/src/notifications/ManagerMac.mm
index e21cc904..e50bee89 100644
--- a/src/notifications/ManagerMac.mm
+++ b/src/notifications/ManagerMac.mm
@@ -3,6 +3,12 @@
#include <Foundation/Foundation.h>
#include <QtMac>
+#include "Cache.h"
+#include "EventAccessors.h"
+#include "MatrixClient.h"
+#include "Utils.h"
+#include <mtx/responses.hpp>
+
@interface NSUserNotification (CFIPrivate)
- (void)set_identityImage:(NSImage *)image;
@end
@@ -13,25 +19,20 @@ NotificationsManager::NotificationsManager(QObject *parent): QObject(parent)
}
void
-NotificationsManager::postNotification(
- const QString &roomId,
- const QString &eventId,
- const QString &roomName,
- const QString &senderName,
- const QString &text,
- const QImage &icon,
- const bool &isEmoteMessage)
+NotificationsManager::postNotification(const mtx::responses::Notification ¬ification,
+ const QImage &icon)
{
- Q_UNUSED(roomId);
- Q_UNUSED(eventId);
Q_UNUSED(icon);
+ 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);
+
NSUserNotification * notif = [[NSUserNotification alloc] init];
- notif.title = roomName.toNSString();
- notif.subtitle = QString("%1 sent a message").arg(senderName).toNSString();
- if (isEmoteMessage)
- notif.informativeText = QString("* ").append(senderName).append(" ").append(text).toNSString();
+ notif.title = QString::fromStdString(cache::singleRoomInfo(notification.room_id).name).toNSString();
+ notif.subtitle = QString("%1 sent a message").arg(sender).toNSString();
+ if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote)
+ notif.informativeText = QString("* ").append(sender).append(" ").append(text).toNSString();
else
notif.informativeText = text.toNSString();
notif.soundName = NSUserNotificationDefaultSoundName;
|