From 471831bcd6559937a30a5b4a81d3299b98083006 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 24 Apr 2024 19:57:17 +0400 Subject: [PATCH] Revert "Remove not really needed notification capability checks" This reverts commit abdfa4f785ca0094a1db3959deb3d922ffd3d1d5. --- .../linux/notifications_manager_linux.cpp | 112 ++++++++++-------- 1 file changed, 62 insertions(+), 50 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp index 6bde1d993..f80d88c77 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp @@ -300,21 +300,25 @@ bool NotificationData::init( _body = msg.toStdString(); } - _actions.push_back("default"); - _actions.push_back(tr::lng_open_link(tr::now).toStdString()); + if (HasCapability("actions")) { + _actions.push_back("default"); + _actions.push_back(tr::lng_open_link(tr::now).toStdString()); - if (!options.hideMarkAsRead) { - // icon name according to https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html - _actions.push_back("mail-mark-read"); - _actions.push_back(tr::lng_context_mark_read(tr::now).toStdString()); - } + if (!options.hideMarkAsRead) { + // icon name according to https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html + _actions.push_back("mail-mark-read"); + _actions.push_back( + tr::lng_context_mark_read(tr::now).toStdString()); + } - if (HasCapability("inline-reply") && !options.hideReplyButton) { - _actions.push_back("inline-reply"); - _actions.push_back(tr::lng_notification_reply(tr::now).toStdString()); + if (HasCapability("inline-reply") + && !options.hideReplyButton) { + _actions.push_back("inline-reply"); + _actions.push_back( + tr::lng_notification_reply(tr::now).toStdString()); - _notificationRepliedSignalId - = _interface.signal_notification_replied().connect([=]( + _notificationRepliedSignalId + = _interface.signal_notification_replied().connect([=]( XdgNotifications::Notifications, uint id, std::string text) { @@ -326,51 +330,59 @@ bool NotificationData::init( } }); }); + } + + _actionInvokedSignalId = _interface.signal_action_invoked().connect( + [=]( + XdgNotifications::Notifications, + uint id, + std::string actionName) { + Core::Sandbox::Instance().customEnterFromEventLoop([&] { + if (id == _notificationId) { + if (actionName == "default") { + _manager->notificationActivated(_id); + } else if (actionName == "mail-mark-read") { + _manager->notificationReplied(_id, {}); + } + } + }); + }); + + _activationTokenSignalId + = _interface.signal_activation_token().connect([=]( + XdgNotifications::Notifications, + uint id, + std::string token) { + if (id == _notificationId) { + GLib::setenv("XDG_ACTIVATION_TOKEN", token, true); + } + }); } - _actionInvokedSignalId = _interface.signal_action_invoked().connect([=]( - XdgNotifications::Notifications, - uint id, - std::string actionName) { - Core::Sandbox::Instance().customEnterFromEventLoop([&] { - if (id == _notificationId) { - if (actionName == "default") { - _manager->notificationActivated(_id); - } else if (actionName == "mail-mark-read") { - _manager->notificationReplied(_id, {}); - } - } - }); - }); - - _activationTokenSignalId = _interface.signal_activation_token().connect( - [=]( - XdgNotifications::Notifications, - uint id, - std::string token) { - if (id == _notificationId) { - GLib::setenv("XDG_ACTIVATION_TOKEN", token, true); - } - }); - - _hints.insert_value("action-icons", GLib::Variant::new_boolean(true)); + if (HasCapability("action-icons")) { + _hints.insert_value("action-icons", GLib::Variant::new_boolean(true)); + } // suppress system sound if telegram sound activated, // otherwise use system sound - if (Core::App().settings().soundNotify()) { - _hints.insert_value( - "suppress-sound", - GLib::Variant::new_boolean(true)); - } else { - // sound name according to http://0pointer.de/public/sound-naming-spec.html - _hints.insert_value( - "sound-name", - GLib::Variant::new_string("message-new-instant")); + if (HasCapability("sound")) { + if (Core::App().settings().soundNotify()) { + _hints.insert_value( + "suppress-sound", + GLib::Variant::new_boolean(true)); + } else { + // sound name according to http://0pointer.de/public/sound-naming-spec.html + _hints.insert_value( + "sound-name", + GLib::Variant::new_string("message-new-instant")); + } } - _hints.insert_value( - "x-canonical-append", - GLib::Variant::new_string("true")); + if (HasCapability("x-canonical-append")) { + _hints.insert_value( + "x-canonical-append", + GLib::Variant::new_string("true")); + } _hints.insert_value("category", GLib::Variant::new_string("im.received"));