From 299c486a2bd1aff872fcf0b2e76300b569920fc5 Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Fri, 12 Feb 2021 11:28:41 -0500 Subject: [PATCH] Display notifications for emote messages properly --- src/ChatPage.cpp | 9 ++++++++- src/notifications/Manager.h | 3 ++- src/notifications/ManagerLinux.cpp | 18 ++++++++++++------ src/notifications/ManagerMac.mm | 8 ++++++-- src/notifications/ManagerWin.cpp | 11 +++++++++-- 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 6d67e6f2..656ddab0 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -691,13 +691,20 @@ ChatPage::sendNotifications(const mtx::responses::Notifications &res) this, [this, room_id, event_id, item, user_id, info]( QPixmap image) { + bool isEmote = false; + auto ev = cache::client()->getEvent( + room_id.toStdString(), event_id); + if (ev && mtx::accessors::msg_type(ev->data) == + mtx::events::MessageType::Emote) + isEmote = true; notificationsManager.postNotification( room_id, QString::fromStdString(event_id), QString::fromStdString(info.name), cache::displayName(room_id, user_id), utils::event_body(item.event), - image.toImage()); + image.toImage(), + isEmote); }); } } diff --git a/src/notifications/Manager.h b/src/notifications/Manager.h index 2b869efc..46f398d7 100644 --- a/src/notifications/Manager.h +++ b/src/notifications/Manager.h @@ -32,7 +32,8 @@ public: const QString &roomName, const QString &senderName, const QString &text, - const QImage &icon); + const QImage &icon, + const bool &isEmoteMsg = false); signals: void notificationClicked(const QString roomId, const QString eventId); diff --git a/src/notifications/ManagerLinux.cpp b/src/notifications/ManagerLinux.cpp index 8f7261e6..7dbf663d 100644 --- a/src/notifications/ManagerLinux.cpp +++ b/src/notifications/ManagerLinux.cpp @@ -50,17 +50,23 @@ NotificationsManager::postNotification(const QString &roomid, const QString &roomname, const QString &sender, const QString &text, - const QImage &icon) + const QImage &icon, + const bool &isEmoteMessage) { QVariantMap hints; hints["image-data"] = icon; hints["sound-name"] = "message-new-instant"; QList argumentList; - argumentList << "nheko"; // app_name - argumentList << (uint)0; // replace_id - argumentList << ""; // app_icon - argumentList << roomname; // summary - argumentList << sender + ": " + text; // body + argumentList << "nheko"; // app_name + argumentList << (uint)0; // replace_id + argumentList << ""; // app_icon + argumentList << roomname; // summary + + // body + if (isEmoteMessage) + argumentList << "* " + sender + " " + text; + else + argumentList << sender + ": " + text; // The list of actions has always the action name and then a localized version of that // action. Currently we just use an empty string for that. // TODO(Nico): Look into what to actually put there. diff --git a/src/notifications/ManagerMac.mm b/src/notifications/ManagerMac.mm index c09e894c..e21cc904 100644 --- a/src/notifications/ManagerMac.mm +++ b/src/notifications/ManagerMac.mm @@ -19,7 +19,8 @@ NotificationsManager::postNotification( const QString &roomName, const QString &senderName, const QString &text, - const QImage &icon) + const QImage &icon, + const bool &isEmoteMessage) { Q_UNUSED(roomId); Q_UNUSED(eventId); @@ -29,7 +30,10 @@ NotificationsManager::postNotification( notif.title = roomName.toNSString(); notif.subtitle = QString("%1 sent a message").arg(senderName).toNSString(); - notif.informativeText = text.toNSString(); + if (isEmoteMessage) + notif.informativeText = QString("* ").append(senderName).append(" ").append(text).toNSString(); + else + notif.informativeText = text.toNSString(); notif.soundName = NSUserNotificationDefaultSoundName; [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: notif]; diff --git a/src/notifications/ManagerWin.cpp b/src/notifications/ManagerWin.cpp index cc61c645..43e6517b 100644 --- a/src/notifications/ManagerWin.cpp +++ b/src/notifications/ManagerWin.cpp @@ -37,7 +37,8 @@ NotificationsManager::postNotification(const QString &room_id, const QString &room_name, const QString &sender, const QString &text, - const QImage &icon) + const QImage &icon, + const bool &isEmoteMessage) { Q_UNUSED(room_id) Q_UNUSED(event_id) @@ -53,7 +54,13 @@ NotificationsManager::postNotification(const QString &room_id, else templ.setTextField(QString("%1").arg(sender).toStdWString(), WinToastTemplate::FirstLine); - templ.setTextField(QString("%1").arg(text).toStdWString(), WinToastTemplate::SecondLine); + if (isEmoteMessage) + templ.setTextField( + QString("* ").append(sender).append(" ").append(text).toStdWString(), + WinToastTemplate::SecondLine); + else + templ.setTextField(QString("%1").arg(text).toStdWString(), + WinToastTemplate::SecondLine); // TODO: implement room or user avatar // templ.setImagePath(L"C:/example.png");