mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Display notifications for emote messages properly
This commit is contained in:
parent
7ddcab3902
commit
299c486a2b
5 changed files with 37 additions and 12 deletions
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<QVariant> 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.
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
Loading…
Reference in a new issue