mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Merge pull request #471 from LorenDB/emoteNotif
Display notifications for emote messages properly
This commit is contained in:
commit
ca237f36b9
5 changed files with 71 additions and 49 deletions
|
@ -668,8 +668,6 @@ ChatPage::sendNotifications(const mtx::responses::Notifications &res)
|
||||||
|
|
||||||
if (!cache::isNotificationSent(event_id)) {
|
if (!cache::isNotificationSent(event_id)) {
|
||||||
const auto room_id = QString::fromStdString(item.room_id);
|
const auto room_id = QString::fromStdString(item.room_id);
|
||||||
const auto user_id =
|
|
||||||
QString::fromStdString(mtx::accessors::sender(item.event));
|
|
||||||
|
|
||||||
// We should only sent one notification per event.
|
// We should only sent one notification per event.
|
||||||
cache::markSentNotification(event_id);
|
cache::markSentNotification(event_id);
|
||||||
|
@ -689,15 +687,9 @@ ChatPage::sendNotifications(const mtx::responses::Notifications &res)
|
||||||
QString::fromStdString(info.avatar_url),
|
QString::fromStdString(info.avatar_url),
|
||||||
96,
|
96,
|
||||||
this,
|
this,
|
||||||
[this, room_id, event_id, item, user_id, info](
|
[this, item](QPixmap image) {
|
||||||
QPixmap image) {
|
|
||||||
notificationsManager.postNotification(
|
notificationsManager.postNotification(
|
||||||
room_id,
|
item, image.toImage());
|
||||||
QString::fromStdString(event_id),
|
|
||||||
QString::fromStdString(info.name),
|
|
||||||
cache::displayName(room_id, user_id),
|
|
||||||
utils::event_body(item.event),
|
|
||||||
image.toImage());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
#include <mtx/responses/notifications.hpp>
|
||||||
|
|
||||||
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_HAIKU)
|
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_HAIKU)
|
||||||
#include <QtDBus/QDBusArgument>
|
#include <QtDBus/QDBusArgument>
|
||||||
#include <QtDBus/QDBusInterface>
|
#include <QtDBus/QDBusInterface>
|
||||||
|
@ -27,12 +29,7 @@ class NotificationsManager : public QObject
|
||||||
public:
|
public:
|
||||||
NotificationsManager(QObject *parent = nullptr);
|
NotificationsManager(QObject *parent = nullptr);
|
||||||
|
|
||||||
void postNotification(const QString &roomId,
|
void postNotification(const mtx::responses::Notification ¬ification, const QImage &icon);
|
||||||
const QString &eventId,
|
|
||||||
const QString &roomName,
|
|
||||||
const QString &senderName,
|
|
||||||
const QString &text,
|
|
||||||
const QImage &icon);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void notificationClicked(const QString roomId, const QString eventId);
|
void notificationClicked(const QString roomId, const QString eventId);
|
||||||
|
|
|
@ -8,6 +8,12 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
|
||||||
|
#include "Cache.h"
|
||||||
|
#include "EventAccessors.h"
|
||||||
|
#include "MatrixClient.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
#include <mtx/responses/notifications.hpp>
|
||||||
|
|
||||||
NotificationsManager::NotificationsManager(QObject *parent)
|
NotificationsManager::NotificationsManager(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, dbus("org.freedesktop.Notifications",
|
, dbus("org.freedesktop.Notifications",
|
||||||
|
@ -45,22 +51,31 @@ NotificationsManager::NotificationsManager(QObject *parent)
|
||||||
* Licensed under the GNU General Public License, version 3
|
* Licensed under the GNU General Public License, version 3
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
NotificationsManager::postNotification(const QString &roomid,
|
NotificationsManager::postNotification(const mtx::responses::Notification ¬ification,
|
||||||
const QString &eventid,
|
|
||||||
const QString &roomname,
|
|
||||||
const QString &sender,
|
|
||||||
const QString &text,
|
|
||||||
const QImage &icon)
|
const QImage &icon)
|
||||||
{
|
{
|
||||||
|
const auto room_id = QString::fromStdString(notification.room_id);
|
||||||
|
const auto event_id = QString::fromStdString(mtx::accessors::event_id(notification.event));
|
||||||
|
const auto sender = cache::displayName(
|
||||||
|
room_id, QString::fromStdString(mtx::accessors::sender(notification.event)));
|
||||||
|
const auto text = utils::event_body(notification.event);
|
||||||
|
|
||||||
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 << QString::fromStdString(
|
||||||
argumentList << sender + ": " + text; // body
|
cache::singleRoomInfo(notification.room_id).name); // summary
|
||||||
|
|
||||||
|
// body
|
||||||
|
if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote)
|
||||||
|
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.
|
||||||
|
@ -76,12 +91,12 @@ NotificationsManager::postNotification(const QString &roomid,
|
||||||
QDBusPendingCall call = notifyApp.asyncCallWithArgumentList("Notify", argumentList);
|
QDBusPendingCall call = notifyApp.asyncCallWithArgumentList("Notify", argumentList);
|
||||||
auto watcher = new QDBusPendingCallWatcher{call, this};
|
auto watcher = new QDBusPendingCallWatcher{call, this};
|
||||||
connect(
|
connect(
|
||||||
watcher, &QDBusPendingCallWatcher::finished, this, [watcher, this, roomid, eventid]() {
|
watcher, &QDBusPendingCallWatcher::finished, this, [watcher, this, room_id, event_id]() {
|
||||||
if (watcher->reply().type() == QDBusMessage::ErrorMessage)
|
if (watcher->reply().type() == QDBusMessage::ErrorMessage)
|
||||||
qDebug() << "D-Bus Error:" << watcher->reply().errorMessage();
|
qDebug() << "D-Bus Error:" << watcher->reply().errorMessage();
|
||||||
else
|
else
|
||||||
notificationIds[watcher->reply().arguments().first().toUInt()] =
|
notificationIds[watcher->reply().arguments().first().toUInt()] =
|
||||||
roomEventId{roomid, eventid};
|
roomEventId{room_id, event_id};
|
||||||
watcher->deleteLater();
|
watcher->deleteLater();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,12 @@
|
||||||
#include <Foundation/Foundation.h>
|
#include <Foundation/Foundation.h>
|
||||||
#include <QtMac>
|
#include <QtMac>
|
||||||
|
|
||||||
|
#include "Cache.h"
|
||||||
|
#include "EventAccessors.h"
|
||||||
|
#include "MatrixClient.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
#include <mtx/responses/notifications.hpp>
|
||||||
|
|
||||||
@interface NSUserNotification (CFIPrivate)
|
@interface NSUserNotification (CFIPrivate)
|
||||||
- (void)set_identityImage:(NSImage *)image;
|
- (void)set_identityImage:(NSImage *)image;
|
||||||
@end
|
@end
|
||||||
|
@ -13,23 +19,22 @@ NotificationsManager::NotificationsManager(QObject *parent): QObject(parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NotificationsManager::postNotification(
|
NotificationsManager::postNotification(const mtx::responses::Notification ¬ification,
|
||||||
const QString &roomId,
|
const QImage &icon)
|
||||||
const QString &eventId,
|
|
||||||
const QString &roomName,
|
|
||||||
const QString &senderName,
|
|
||||||
const QString &text,
|
|
||||||
const QImage &icon)
|
|
||||||
{
|
{
|
||||||
Q_UNUSED(roomId);
|
|
||||||
Q_UNUSED(eventId);
|
|
||||||
Q_UNUSED(icon);
|
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];
|
NSUserNotification * notif = [[NSUserNotification alloc] init];
|
||||||
|
|
||||||
notif.title = roomName.toNSString();
|
notif.title = QString::fromStdString(cache::singleRoomInfo(notification.room_id).name).toNSString();
|
||||||
notif.subtitle = QString("%1 sent a message").arg(senderName).toNSString();
|
notif.subtitle = QString("%1 sent a message").arg(sender).toNSString();
|
||||||
notif.informativeText = text.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;
|
notif.soundName = NSUserNotificationDefaultSoundName;
|
||||||
|
|
||||||
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: notif];
|
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: notif];
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
#include "notifications/Manager.h"
|
#include "notifications/Manager.h"
|
||||||
#include "wintoastlib.h"
|
#include "wintoastlib.h"
|
||||||
|
|
||||||
|
#include "Cache.h"
|
||||||
|
#include "EventAccessors.h"
|
||||||
|
#include "MatrixClient.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
#include <mtx/responses/notifications.hpp>
|
||||||
|
|
||||||
using namespace WinToastLib;
|
using namespace WinToastLib;
|
||||||
|
|
||||||
class CustomHandler : public IWinToastHandler
|
class CustomHandler : public IWinToastHandler
|
||||||
|
@ -23,7 +29,7 @@ init()
|
||||||
WinToast::instance()->setAppName(L"Nheko");
|
WinToast::instance()->setAppName(L"Nheko");
|
||||||
WinToast::instance()->setAppUserModelId(WinToast::configureAUMI(L"nheko", L"nheko"));
|
WinToast::instance()->setAppUserModelId(WinToast::configureAUMI(L"nheko", L"nheko"));
|
||||||
if (!WinToast::instance()->initialize())
|
if (!WinToast::instance()->initialize())
|
||||||
std::wcout << "Your system in not compatible with toast notifications\n";
|
std::wcout << "Your system is not compatible with toast notifications\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,17 +38,18 @@ NotificationsManager::NotificationsManager(QObject *parent)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void
|
void
|
||||||
NotificationsManager::postNotification(const QString &room_id,
|
NotificationsManager::postNotification(const mtx::responses::Notification ¬ification,
|
||||||
const QString &event_id,
|
|
||||||
const QString &room_name,
|
|
||||||
const QString &sender,
|
|
||||||
const QString &text,
|
|
||||||
const QImage &icon)
|
const QImage &icon)
|
||||||
{
|
{
|
||||||
Q_UNUSED(room_id)
|
|
||||||
Q_UNUSED(event_id)
|
|
||||||
Q_UNUSED(icon)
|
Q_UNUSED(icon)
|
||||||
|
|
||||||
|
const auto room_name =
|
||||||
|
QString::fromStdString(cache::singleRoomInfo(notification.room_id).name);
|
||||||
|
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);
|
||||||
|
|
||||||
if (!isInitialized)
|
if (!isInitialized)
|
||||||
init();
|
init();
|
||||||
|
|
||||||
|
@ -53,7 +60,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 (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote)
|
||||||
|
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");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue