Display notifications for emote messages properly

This commit is contained in:
Loren Burkholder 2021-02-12 11:28:41 -05:00
parent 7ddcab3902
commit 299c486a2b
5 changed files with 37 additions and 12 deletions

View File

@ -691,13 +691,20 @@ ChatPage::sendNotifications(const mtx::responses::Notifications &res)
this, this,
[this, room_id, event_id, item, user_id, info]( [this, room_id, event_id, item, user_id, info](
QPixmap image) { 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( notificationsManager.postNotification(
room_id, room_id,
QString::fromStdString(event_id), QString::fromStdString(event_id),
QString::fromStdString(info.name), QString::fromStdString(info.name),
cache::displayName(room_id, user_id), cache::displayName(room_id, user_id),
utils::event_body(item.event), utils::event_body(item.event),
image.toImage()); image.toImage(),
isEmote);
}); });
} }
} }

View File

@ -32,7 +32,8 @@ public:
const QString &roomName, const QString &roomName,
const QString &senderName, const QString &senderName,
const QString &text, const QString &text,
const QImage &icon); const QImage &icon,
const bool &isEmoteMsg = false);
signals: signals:
void notificationClicked(const QString roomId, const QString eventId); void notificationClicked(const QString roomId, const QString eventId);

View File

@ -50,17 +50,23 @@ NotificationsManager::postNotification(const QString &roomid,
const QString &roomname, const QString &roomname,
const QString &sender, const QString &sender,
const QString &text, const QString &text,
const QImage &icon) const QImage &icon,
const bool &isEmoteMessage)
{ {
QVariantMap hints; QVariantMap hints;
hints["image-data"] = icon; hints["image-data"] = icon;
hints["sound-name"] = "message-new-instant"; hints["sound-name"] = "message-new-instant";
QList<QVariant> argumentList; QList<QVariant> argumentList;
argumentList << "nheko"; // app_name argumentList << "nheko"; // app_name
argumentList << (uint)0; // replace_id argumentList << (uint)0; // replace_id
argumentList << ""; // app_icon argumentList << ""; // app_icon
argumentList << roomname; // summary argumentList << roomname; // summary
argumentList << sender + ": " + text; // body
// 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 // 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. // action. Currently we just use an empty string for that.
// TODO(Nico): Look into what to actually put there. // TODO(Nico): Look into what to actually put there.

View File

@ -19,7 +19,8 @@ NotificationsManager::postNotification(
const QString &roomName, const QString &roomName,
const QString &senderName, const QString &senderName,
const QString &text, const QString &text,
const QImage &icon) const QImage &icon,
const bool &isEmoteMessage)
{ {
Q_UNUSED(roomId); Q_UNUSED(roomId);
Q_UNUSED(eventId); Q_UNUSED(eventId);
@ -29,7 +30,10 @@ NotificationsManager::postNotification(
notif.title = roomName.toNSString(); notif.title = roomName.toNSString();
notif.subtitle = QString("%1 sent a message").arg(senderName).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; notif.soundName = NSUserNotificationDefaultSoundName;
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: notif]; [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: notif];

View File

@ -37,7 +37,8 @@ NotificationsManager::postNotification(const QString &room_id,
const QString &room_name, const QString &room_name,
const QString &sender, const QString &sender,
const QString &text, const QString &text,
const QImage &icon) const QImage &icon,
const bool &isEmoteMessage)
{ {
Q_UNUSED(room_id) Q_UNUSED(room_id)
Q_UNUSED(event_id) Q_UNUSED(event_id)
@ -53,7 +54,13 @@ NotificationsManager::postNotification(const QString &room_id,
else else
templ.setTextField(QString("%1").arg(sender).toStdWString(), templ.setTextField(QString("%1").arg(sender).toStdWString(),
WinToastTemplate::FirstLine); 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 // TODO: implement room or user avatar
// templ.setImagePath(L"C:/example.png"); // templ.setImagePath(L"C:/example.png");