diff --git a/src/model/notificationdata.h b/src/model/notificationdata.h index f3dd87f6ea..0b6395b470 100644 --- a/src/model/notificationdata.h +++ b/src/model/notificationdata.h @@ -12,5 +12,6 @@ struct NotificationData { QString title; QString message; + QString category; QPixmap pixmap; }; diff --git a/src/model/notificationgenerator.cpp b/src/model/notificationgenerator.cpp index cc8ab76d27..de3c60e670 100644 --- a/src/model/notificationgenerator.cpp +++ b/src/model/notificationgenerator.cpp @@ -144,6 +144,26 @@ NotificationData NotificationGenerator::friendMessageNotification(const Friend* ret.title = generateTitle(friendNotifications, conferenceNotifications, f); ret.message = generateContent(friendNotifications, conferenceNotifications, message, f->getPublicKey()); + ret.category = "im.received"; + ret.pixmap = getSenderAvatar(profile, f->getPublicKey()); + + return ret; +} + +NotificationData NotificationGenerator::incomingCallNotification(const Friend* f) +{ + friendNotifications[f]++; + + NotificationData ret; + + if (notificationSettings.getNotifyHide()) { + ret.title = tr("Incoming call"); + return ret; + } + + ret.title = generateTitle(friendNotifications, conferenceNotifications, f); + ret.message = generateContent(friendNotifications, conferenceNotifications, "", f->getPublicKey()); + ret.category = "call.incoming"; ret.pixmap = getSenderAvatar(profile, f->getPublicKey()); return ret; @@ -195,6 +215,7 @@ NotificationData NotificationGenerator::fileTransferNotification(const Friend* f ret.message = filename + " (" + getHumanReadableSize(fileSize) + ")"; } + ret.category = "transfer"; ret.pixmap = getSenderAvatar(profile, f->getPublicKey()); return ret; @@ -211,6 +232,7 @@ NotificationData NotificationGenerator::conferenceInvitationNotification(const F ret.title = tr("%1 invites you to join a conference.").arg(from->getDisplayedName()); ret.message = ""; + ret.category = "im"; ret.pixmap = getSenderAvatar(profile, from->getPublicKey()); return ret; @@ -228,6 +250,7 @@ NotificationData NotificationGenerator::friendRequestNotification(const ToxPk& s ret.title = tr("Friend request received from %1").arg(sender.toString()); ret.message = message; + ret.category = "im"; return ret; } diff --git a/src/model/notificationgenerator.h b/src/model/notificationgenerator.h index 4769d21ce0..702e1423d3 100644 --- a/src/model/notificationgenerator.h +++ b/src/model/notificationgenerator.h @@ -33,6 +33,7 @@ class NotificationGenerator : public QObject NotificationGenerator& operator=(NotificationGenerator&&) = delete; NotificationData friendMessageNotification(const Friend* f, const QString& message); + NotificationData incomingCallNotification(const Friend* f); NotificationData conferenceMessageNotification(const Conference* c, const ToxPk& sender, const QString& message); NotificationData fileTransferNotification(const Friend* f, const QString& filename, diff --git a/src/platform/desktop_notifications/desktopnotify.cpp b/src/platform/desktop_notifications/desktopnotify.cpp index 3b0377c037..27e94b87ce 100644 --- a/src/platform/desktop_notifications/desktopnotify.cpp +++ b/src/platform/desktop_notifications/desktopnotify.cpp @@ -46,7 +46,7 @@ void DesktopNotify::notifyMessage(const NotificationData& notificationData) // Try system-backends first. if (d->settings.getNotifySystemBackend()) { if (d->dbus->showMessage(notificationData.title, notificationData.message, - notificationData.pixmap)) { + notificationData.category, notificationData.pixmap)) { return; } } diff --git a/src/platform/desktop_notifications/desktopnotifybackend.h b/src/platform/desktop_notifications/desktopnotifybackend.h index 623b1a4877..57f76e6240 100644 --- a/src/platform/desktop_notifications/desktopnotifybackend.h +++ b/src/platform/desktop_notifications/desktopnotifybackend.h @@ -15,8 +15,8 @@ class DesktopNotifyBackend : public QObject public: explicit DesktopNotifyBackend(QObject* parent); ~DesktopNotifyBackend() override; - - bool showMessage(const QString& title, const QString& message, const QPixmap& pixmap); + bool showMessage(const QString& title, const QString& message, const QString& category, + const QPixmap& pixmap); signals: void messageClicked(); diff --git a/src/platform/desktop_notifications/desktopnotifybackend_dbus.cpp b/src/platform/desktop_notifications/desktopnotifybackend_dbus.cpp index ae94dd1379..49db7087e4 100644 --- a/src/platform/desktop_notifications/desktopnotifybackend_dbus.cpp +++ b/src/platform/desktop_notifications/desktopnotifybackend_dbus.cpp @@ -324,13 +324,13 @@ DesktopNotifyBackend::DesktopNotifyBackend(QObject* parent) DesktopNotifyBackend::~DesktopNotifyBackend() = default; bool DesktopNotifyBackend::showMessage(const QString& title, const QString& message, - const QPixmap& pixmap) + const QString& category, const QPixmap& pixmap) { // Try Notify first. if (d->notifyInterface.isValid()) { QVariantMap hints{ {QStringLiteral("action-icons"), true}, - {QStringLiteral("category"), QStringLiteral("im.received")}, + {QStringLiteral("category"), category}, {QStringLiteral("sender-pid"), QVariant::fromValue(QCoreApplication::applicationPid())}, }; diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 7c94962866..be3c96c577 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -1564,10 +1564,16 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString& text, b widget->updateStatusLight(); ui->friendList->trackWidget(settings, style, widget); if (notifier != nullptr) { - auto notificationData = - filename.isEmpty() - ? notificationGenerator->friendMessageNotification(f, text) - : notificationGenerator->fileTransferNotification(f, filename, filesize); + NotificationData notificationData; + if (filename.isEmpty()) { + if (text.isEmpty()) { + notificationData = notificationGenerator->incomingCallNotification(f); + } else { + notificationData = notificationGenerator->friendMessageNotification(f, text); + } + } else { + notificationData = notificationGenerator->fileTransferNotification(f, filename, filesize); + } notifier->notifyMessage(notificationData); }