From 7ac4c6e479e0582a950c7e32663d6b2021b81444 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Fri, 6 Mar 2020 09:55:22 +0400 Subject: [PATCH] Add mark as read feature to linux native notifications --- .../linux/notifications_manager_linux.cpp | 38 +++++++++++-------- .../linux/notifications_manager_linux.h | 2 +- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp index 0a50d2c2ca..8a34da6fe6 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp @@ -169,13 +169,9 @@ NotificationData::NotificationData( if (capabilities.contains(qsl("actions"))) { _actions << qsl("default") << QString(); - _dbusConnection.connect( - kService.utf16(), - kObjectPath.utf16(), - kInterface.utf16(), - qsl("ActionInvoked"), - this, - SLOT(notificationClicked(uint,QString))); + _actions + << qsl("mail-mark-read") + << tr::lng_context_mark_read(tr::now); if (capabilities.contains(qsl("inline-reply")) && !hideReplyButton) { _actions @@ -195,6 +191,14 @@ NotificationData::NotificationData( << qsl("mail-reply-sender") << tr::lng_notification_reply(tr::now); } + + _dbusConnection.connect( + kService.utf16(), + kObjectPath.utf16(), + kInterface.utf16(), + qsl("ActionInvoked"), + this, + SLOT(actionInvoked(uint,QString))); } if (capabilities.contains(qsl("action-icons"))) { @@ -313,19 +317,23 @@ void NotificationData::notificationClosed(uint id) { } } -void NotificationData::notificationClicked(uint id, const QString &actionId) { +void NotificationData::actionInvoked(uint id, const QString &actionName) { if (id != _notificationId) { return; } - if (actionId != qsl("default") && actionId != qsl("mail-reply-sender")) { - return; + if (actionName == qsl("default") + || actionName == qsl("mail-reply-sender")) { + const auto manager = _manager; + crl::on_main(manager, [=] { + manager->notificationActivated(_peerId, _msgId); + }); + } else if (actionName == qsl("mail-mark-read")) { + const auto manager = _manager; + crl::on_main(manager, [=] { + manager->notificationReplied(_peerId, _msgId, {}); + }); } - - const auto manager = _manager; - crl::on_main(manager, [=] { - manager->notificationActivated(_peerId, _msgId); - }); } void NotificationData::notificationReplied(uint id, const QString &text) { diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h index d22a02f117..ba6bcc88f1 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h @@ -68,7 +68,7 @@ private: private slots: void notificationClosed(uint id); - void notificationClicked(uint id, const QString &actionId); + void actionInvoked(uint id, const QString &actionName); void notificationReplied(uint id, const QString &text); };