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, 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);
});
}
}

View file

@ -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);

View file

@ -50,7 +50,8 @@ 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;
@ -60,7 +61,12 @@ NotificationsManager::postNotification(const QString &roomid,
argumentList << (uint)0; // replace_id
argumentList << ""; // app_icon
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
// action. Currently we just use an empty string for that.
// TODO(Nico): Look into what to actually put there.

View file

@ -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,6 +30,9 @@ NotificationsManager::postNotification(
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();
else
notif.informativeText = text.toNSString();
notif.soundName = NSUserNotificationDefaultSoundName;

View file

@ -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");