From c8aa7672e9655fd962533f768d7d83e2d092f686 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 4 Oct 2016 16:36:50 +0300 Subject: [PATCH] Notifications by libnotify support improved. --- .../platform/linux/linux_libnotify.cpp | 56 +++---- .../platform/linux/linux_libnotify.h | 56 +++---- .../SourceFiles/platform/linux/linux_libs.h | 8 +- .../linux/notifications_manager_linux.cpp | 153 ++++++++++++------ .../linux/notifications_manager_linux.h | 2 + .../window/notifications_manager.cpp | 1 - 6 files changed, 165 insertions(+), 111 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/linux_libnotify.cpp b/Telegram/SourceFiles/platform/linux/linux_libnotify.cpp index 13cadc086..23ba37b4e 100644 --- a/Telegram/SourceFiles/platform/linux/linux_libnotify.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_libnotify.cpp @@ -48,28 +48,28 @@ bool loadLibrary(QLibrary &lib, const char *name, int version) { f_notify_init notify_init = nullptr; f_notify_uninit notify_uninit = nullptr; f_notify_is_initted notify_is_initted = nullptr; -f_notify_get_app_name notify_get_app_name = nullptr; -f_notify_set_app_name notify_set_app_name = nullptr; +//f_notify_get_app_name notify_get_app_name = nullptr; +//f_notify_set_app_name notify_set_app_name = nullptr; f_notify_get_server_caps notify_get_server_caps = nullptr; f_notify_get_server_info notify_get_server_info = nullptr; f_notify_notification_new notify_notification_new = nullptr; -f_notify_notification_update notify_notification_update = nullptr; +//f_notify_notification_update notify_notification_update = nullptr; f_notify_notification_show notify_notification_show = nullptr; -f_notify_notification_set_app_name notify_notification_set_app_name = nullptr; +//f_notify_notification_set_app_name notify_notification_set_app_name = nullptr; f_notify_notification_set_timeout notify_notification_set_timeout = nullptr; -f_notify_notification_set_category notify_notification_set_category = nullptr; -f_notify_notification_set_urgency notify_notification_set_urgency = nullptr; -f_notify_notification_set_icon_from_pixbuf notify_notification_set_icon_from_pixbuf = nullptr; +//f_notify_notification_set_category notify_notification_set_category = nullptr; +//f_notify_notification_set_urgency notify_notification_set_urgency = nullptr; +//f_notify_notification_set_icon_from_pixbuf notify_notification_set_icon_from_pixbuf = nullptr; f_notify_notification_set_image_from_pixbuf notify_notification_set_image_from_pixbuf = nullptr; -f_notify_notification_set_hint notify_notification_set_hint = nullptr; -f_notify_notification_set_hint_int32 notify_notification_set_hint_int32 = nullptr; -f_notify_notification_set_hint_uint32 notify_notification_set_hint_uint32 = nullptr; -f_notify_notification_set_hint_double notify_notification_set_hint_double = nullptr; +//f_notify_notification_set_hint notify_notification_set_hint = nullptr; +//f_notify_notification_set_hint_int32 notify_notification_set_hint_int32 = nullptr; +//f_notify_notification_set_hint_uint32 notify_notification_set_hint_uint32 = nullptr; +//f_notify_notification_set_hint_double notify_notification_set_hint_double = nullptr; f_notify_notification_set_hint_string notify_notification_set_hint_string = nullptr; -f_notify_notification_set_hint_byte notify_notification_set_hint_byte = nullptr; -f_notify_notification_set_hint_byte_array notify_notification_set_hint_byte_array = nullptr; -f_notify_notification_clear_hints notify_notification_clear_hints = nullptr; +//f_notify_notification_set_hint_byte notify_notification_set_hint_byte = nullptr; +//f_notify_notification_set_hint_byte_array notify_notification_set_hint_byte_array = nullptr; +//f_notify_notification_clear_hints notify_notification_clear_hints = nullptr; f_notify_notification_add_action notify_notification_add_action = nullptr; f_notify_notification_clear_actions notify_notification_clear_actions = nullptr; f_notify_notification_close notify_notification_close = nullptr; @@ -90,28 +90,28 @@ void startLibNotify() { load(lib_notify, "notify_init", notify_init); load(lib_notify, "notify_uninit", notify_uninit); load(lib_notify, "notify_is_initted", notify_is_initted); - load(lib_notify, "notify_get_app_name", notify_get_app_name); - load(lib_notify, "notify_set_app_name", notify_set_app_name); +// load(lib_notify, "notify_get_app_name", notify_get_app_name); +// load(lib_notify, "notify_set_app_name", notify_set_app_name); load(lib_notify, "notify_get_server_caps", notify_get_server_caps); load(lib_notify, "notify_get_server_info", notify_get_server_info); load(lib_notify, "notify_notification_new", notify_notification_new); - load(lib_notify, "notify_notification_update", notify_notification_update); +// load(lib_notify, "notify_notification_update", notify_notification_update); load(lib_notify, "notify_notification_show", notify_notification_show); - load(lib_notify, "notify_notification_set_app_name", notify_notification_set_app_name); +// load(lib_notify, "notify_notification_set_app_name", notify_notification_set_app_name); load(lib_notify, "notify_notification_set_timeout", notify_notification_set_timeout); - load(lib_notify, "notify_notification_set_category", notify_notification_set_category); - load(lib_notify, "notify_notification_set_urgency", notify_notification_set_urgency); - load(lib_notify, "notify_notification_set_icon_from_pixbuf", notify_notification_set_icon_from_pixbuf); +// load(lib_notify, "notify_notification_set_category", notify_notification_set_category); +// load(lib_notify, "notify_notification_set_urgency", notify_notification_set_urgency); +// load(lib_notify, "notify_notification_set_icon_from_pixbuf", notify_notification_set_icon_from_pixbuf); load(lib_notify, "notify_notification_set_image_from_pixbuf", notify_notification_set_image_from_pixbuf); - load(lib_notify, "notify_notification_set_hint", notify_notification_set_hint); - load(lib_notify, "notify_notification_set_hint_int32", notify_notification_set_hint_int32); - load(lib_notify, "notify_notification_set_hint_uint32", notify_notification_set_hint_uint32); - load(lib_notify, "notify_notification_set_hint_double", notify_notification_set_hint_double); +// load(lib_notify, "notify_notification_set_hint", notify_notification_set_hint); +// load(lib_notify, "notify_notification_set_hint_int32", notify_notification_set_hint_int32); +// load(lib_notify, "notify_notification_set_hint_uint32", notify_notification_set_hint_uint32); +// load(lib_notify, "notify_notification_set_hint_double", notify_notification_set_hint_double); load(lib_notify, "notify_notification_set_hint_string", notify_notification_set_hint_string); - load(lib_notify, "notify_notification_set_hint_byte", notify_notification_set_hint_byte); - load(lib_notify, "notify_notification_set_hint_byte_array", notify_notification_set_hint_byte_array); - load(lib_notify, "notify_notification_clear_hints", notify_notification_clear_hints); +// load(lib_notify, "notify_notification_set_hint_byte", notify_notification_set_hint_byte); +// load(lib_notify, "notify_notification_set_hint_byte_array", notify_notification_set_hint_byte_array); +// load(lib_notify, "notify_notification_clear_hints", notify_notification_clear_hints); load(lib_notify, "notify_notification_add_action", notify_notification_add_action); load(lib_notify, "notify_notification_clear_actions", notify_notification_clear_actions); load(lib_notify, "notify_notification_close", notify_notification_close); diff --git a/Telegram/SourceFiles/platform/linux/linux_libnotify.h b/Telegram/SourceFiles/platform/linux/linux_libnotify.h index e59431ffe..9cde80d7c 100644 --- a/Telegram/SourceFiles/platform/linux/linux_libnotify.h +++ b/Telegram/SourceFiles/platform/linux/linux_libnotify.h @@ -52,11 +52,11 @@ extern f_notify_uninit notify_uninit; using f_notify_is_initted = gboolean (*)(void); extern f_notify_is_initted notify_is_initted; -using f_notify_get_app_name = const char* (*)(void); -extern f_notify_get_app_name notify_get_app_name; +//using f_notify_get_app_name = const char* (*)(void); +//extern f_notify_get_app_name notify_get_app_name; -using f_notify_set_app_name = void (*)(const char *app_name); -extern f_notify_set_app_name notify_set_app_name; +//using f_notify_set_app_name = void (*)(const char *app_name); +//extern f_notify_set_app_name notify_set_app_name; using f_notify_get_server_caps = GList* (*)(void); extern f_notify_get_server_caps notify_get_server_caps; @@ -67,53 +67,53 @@ extern f_notify_get_server_info notify_get_server_info; using f_notify_notification_new = NotifyNotification* (*)(const char *summary, const char *body, const char *icon); extern f_notify_notification_new notify_notification_new; -using f_notify_notification_update = gboolean (*)(NotifyNotification *notification, const char *summary, const char *body, const char *icon); -extern f_notify_notification_update notify_notification_update; +//using f_notify_notification_update = gboolean (*)(NotifyNotification *notification, const char *summary, const char *body, const char *icon); +//extern f_notify_notification_update notify_notification_update; using f_notify_notification_show = gboolean (*)(NotifyNotification *notification, GError **error); extern f_notify_notification_show notify_notification_show; -using f_notify_notification_set_app_name = void (*)(NotifyNotification *notification, const char *app_name); -extern f_notify_notification_set_app_name notify_notification_set_app_name; +//using f_notify_notification_set_app_name = void (*)(NotifyNotification *notification, const char *app_name); +//extern f_notify_notification_set_app_name notify_notification_set_app_name; using f_notify_notification_set_timeout = void (*)(NotifyNotification *notification, gint timeout); extern f_notify_notification_set_timeout notify_notification_set_timeout; -using f_notify_notification_set_category = void (*)(NotifyNotification *notification, const char *category); -extern f_notify_notification_set_category notify_notification_set_category; +//using f_notify_notification_set_category = void (*)(NotifyNotification *notification, const char *category); +//extern f_notify_notification_set_category notify_notification_set_category; -using f_notify_notification_set_urgency = void (*)(NotifyNotification *notification, NotifyUrgency urgency); -extern f_notify_notification_set_urgency notify_notification_set_urgency; +//using f_notify_notification_set_urgency = void (*)(NotifyNotification *notification, NotifyUrgency urgency); +//extern f_notify_notification_set_urgency notify_notification_set_urgency; -using f_notify_notification_set_icon_from_pixbuf = void (*)(NotifyNotification *notification, GdkPixbuf *icon); -extern f_notify_notification_set_icon_from_pixbuf notify_notification_set_icon_from_pixbuf; +//using f_notify_notification_set_icon_from_pixbuf = void (*)(NotifyNotification *notification, GdkPixbuf *icon); +//extern f_notify_notification_set_icon_from_pixbuf notify_notification_set_icon_from_pixbuf; using f_notify_notification_set_image_from_pixbuf = void (*)(NotifyNotification *notification, GdkPixbuf *pixbuf); extern f_notify_notification_set_image_from_pixbuf notify_notification_set_image_from_pixbuf; -using f_notify_notification_set_hint = void (*)(NotifyNotification *notification, const char *key, GVariant *value); -extern f_notify_notification_set_hint notify_notification_set_hint; +//using f_notify_notification_set_hint = void (*)(NotifyNotification *notification, const char *key, GVariant *value); +//extern f_notify_notification_set_hint notify_notification_set_hint; -using f_notify_notification_set_hint_int32 = void (*)(NotifyNotification *notification, const char *key, gint value); -extern f_notify_notification_set_hint_int32 notify_notification_set_hint_int32; +//using f_notify_notification_set_hint_int32 = void (*)(NotifyNotification *notification, const char *key, gint value); +//extern f_notify_notification_set_hint_int32 notify_notification_set_hint_int32; -using f_notify_notification_set_hint_uint32 = void (*)(NotifyNotification *notification, const char *key, guint value); -extern f_notify_notification_set_hint_uint32 notify_notification_set_hint_uint32; +//using f_notify_notification_set_hint_uint32 = void (*)(NotifyNotification *notification, const char *key, guint value); +//extern f_notify_notification_set_hint_uint32 notify_notification_set_hint_uint32; -using f_notify_notification_set_hint_double = void (*)(NotifyNotification *notification, const char *key, gdouble value); -extern f_notify_notification_set_hint_double notify_notification_set_hint_double; +//using f_notify_notification_set_hint_double = void (*)(NotifyNotification *notification, const char *key, gdouble value); +//extern f_notify_notification_set_hint_double notify_notification_set_hint_double; using f_notify_notification_set_hint_string = void (*)(NotifyNotification *notification, const char *key, const char *value); extern f_notify_notification_set_hint_string notify_notification_set_hint_string; -using f_notify_notification_set_hint_byte = void (*)(NotifyNotification *notification, const char *key, guchar value); -extern f_notify_notification_set_hint_byte notify_notification_set_hint_byte; +//using f_notify_notification_set_hint_byte = void (*)(NotifyNotification *notification, const char *key, guchar value); +//extern f_notify_notification_set_hint_byte notify_notification_set_hint_byte; -using f_notify_notification_set_hint_byte_array = void (*)(NotifyNotification *notification, const char *key, const guchar *value, gsize len); -extern f_notify_notification_set_hint_byte_array notify_notification_set_hint_byte_array; +//using f_notify_notification_set_hint_byte_array = void (*)(NotifyNotification *notification, const char *key, const guchar *value, gsize len); +//extern f_notify_notification_set_hint_byte_array notify_notification_set_hint_byte_array; -using f_notify_notification_clear_hints = void (*)(NotifyNotification *notification); -extern f_notify_notification_clear_hints notify_notification_clear_hints; +//using f_notify_notification_clear_hints = void (*)(NotifyNotification *notification); +//extern f_notify_notification_clear_hints notify_notification_clear_hints; using f_notify_notification_add_action = void (*)(NotifyNotification *notification, const char *action, const char *label, NotifyActionCallback callback, gpointer user_data, GFreeFunc free_func); extern f_notify_notification_add_action notify_notification_add_action; diff --git a/Telegram/SourceFiles/platform/linux/linux_libs.h b/Telegram/SourceFiles/platform/linux/linux_libs.h index a413dabe1..3b542a407 100644 --- a/Telegram/SourceFiles/platform/linux/linux_libs.h +++ b/Telegram/SourceFiles/platform/linux/linux_libs.h @@ -247,12 +247,12 @@ extern f_gtk_dialog_run gtk_dialog_run; typedef gulong (*f_g_signal_connect_data)(gpointer instance, const gchar *detailed_signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags); extern f_g_signal_connect_data g_signal_connect_data; -inline gulong g_signal_connect_helper(gpointer instance, const gchar *detailed_signal, GCallback c_handler, gpointer data) { - return g_signal_connect_data(instance, detailed_signal, c_handler, data, NULL, (GConnectFlags)0); +inline gulong g_signal_connect_helper(gpointer instance, const gchar *detailed_signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data = nullptr) { + return g_signal_connect_data(instance, detailed_signal, c_handler, data, destroy_data, (GConnectFlags)0); } -inline gulong g_signal_connect_swapped_helper(gpointer instance, const gchar *detailed_signal, GCallback c_handler, gpointer data) { - return g_signal_connect_data(instance, detailed_signal, c_handler, data, NULL, G_CONNECT_SWAPPED); +inline gulong g_signal_connect_swapped_helper(gpointer instance, const gchar *detailed_signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data = nullptr) { + return g_signal_connect_data(instance, detailed_signal, c_handler, data, destroy_data, G_CONNECT_SWAPPED); } typedef void (*f_g_signal_handler_disconnect)(gpointer instance, gulong handler_id); diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp index 961482bd4..3e0fd4fce 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp @@ -41,7 +41,7 @@ bool LibNotifyLoaded() { && (Libs::notify_get_server_caps != nullptr) && (Libs::notify_get_server_info != nullptr) && (Libs::notify_notification_new != nullptr) - && (Libs::notify_notification_update != nullptr) +// && (Libs::notify_notification_update != nullptr) && (Libs::notify_notification_show != nullptr) // && (Libs::notify_notification_set_app_name != nullptr) && (Libs::notify_notification_set_timeout != nullptr) @@ -80,12 +80,10 @@ QString escapeNotificationHtml(QString text) { class NotificationData { public: - NotificationData(const QString &title, const QString &body, PeerId peerId, MsgId msgId) - : _data(Libs::notify_notification_new(title.toUtf8().constData(), body.toUtf8().constData(), nullptr)) - , _peerId(peerId) - , _msgId(msgId) { + NotificationData(const QString &title, const QString &body, const QStringList &capabilities, PeerId peerId, MsgId msgId) + : _data(Libs::notify_notification_new(title.toUtf8().constData(), body.toUtf8().constData(), nullptr)) { if (valid()) { - init(); + init(capabilities, peerId, msgId); } } bool valid() const { @@ -131,51 +129,80 @@ public: ~NotificationData() { if (valid()) { - if (_handlerId > 0) { - Libs::g_signal_handler_disconnect(Libs::g_object_cast(_data), _handlerId); - } - Libs::notify_notification_clear_actions(_data); +// if (_handlerId > 0) { +// Libs::g_signal_handler_disconnect(Libs::g_object_cast(_data), _handlerId); +// } +// Libs::notify_notification_clear_actions(_data); Libs::g_object_unref(Libs::g_object_cast(_data)); } } private: - void init() { - _handlerId = Libs::g_signal_connect_helper(Libs::g_object_cast(_data), "closed", G_CALLBACK(NotificationData::notificationClosed), this); + void init(const QStringList &capabilities, PeerId peerId, MsgId msgId) { + if (capabilities.contains(qsl("append"))) { + Libs::notify_notification_set_hint_string(_data, "append", "true"); + } else if (capabilities.contains(qsl("x-canonical-append"))) { + Libs::notify_notification_set_hint_string(_data, "x-canonical-append", "true"); + } + + auto signalReceiver = Libs::g_object_cast(_data); + auto signalHandler = G_CALLBACK(NotificationData::notificationClosed); + auto signalName = "closed"; + auto signalDataFreeMethod = &NotificationData::notificationDataFreeClosure; + auto signalData = new NotificationDataStruct(peerId, msgId); + _handlerId = Libs::g_signal_connect_helper(signalReceiver, signalName, signalHandler, signalData, signalDataFreeMethod); + Libs::notify_notification_set_timeout(_data, Libs::NOTIFY_EXPIRES_DEFAULT); if (auto manager = ManagerInstance.data()) { if (manager->hasActionsSupport()) { - Libs::notify_notification_add_action(_data, "default", lang(lng_context_reply_msg).toUtf8().constData(), NotificationData::notificationClicked, this, nullptr); + auto label = lang(lng_context_reply_msg).toUtf8(); + auto actionReceiver = _data; + auto actionHandler = &NotificationData::notificationClicked; + auto actionLabel = label.constData(); + auto actionName = "default"; + auto actionDataFreeMethod = &NotificationData::notificationDataFree; + auto actionData = new NotificationDataStruct(peerId, msgId); + Libs::notify_notification_add_action(actionReceiver, actionName, actionLabel, actionHandler, actionData, actionDataFreeMethod); } } } - void onClose() { - if (auto manager = ManagerInstance.data()) { - manager->clearNotification(_peerId, _msgId); - } - } - void onClick() { - if (auto manager = ManagerInstance.data()) { - manager->notificationActivated(_peerId, _msgId); - } - } void logError(GError *error) { LOG(("LibNotify Error: domain %1, code %2, message '%3'").arg(error->domain).arg(error->code).arg(QString::fromUtf8(error->message))); Libs::g_error_free(error); } + struct NotificationDataStruct { + NotificationDataStruct(PeerId peerId, MsgId msgId) : peerId(peerId), msgId(msgId) { + } + + PeerId peerId = 0; + MsgId msgId = 0; + }; + static void notificationDataFree(gpointer data) { + auto notificationData = static_cast(data); + delete notificationData; + } + static void notificationDataFreeClosure(gpointer data, GClosure *closure) { + auto notificationData = static_cast(data); + delete notificationData; + } static void notificationClosed(Libs::NotifyNotification *notification, gpointer data) { - static_cast(data)->onClose(); + auto closedReason = Libs::notify_notification_get_closed_reason(notification); + auto notificationData = static_cast(data); + if (auto manager = ManagerInstance.data()) { + manager->clearNotification(notificationData->peerId, notificationData->msgId); + } } static void notificationClicked(Libs::NotifyNotification *notification, char *action, gpointer data) { - static_cast(data)->onClick(); + auto notificationData = static_cast(data); + if (auto manager = ManagerInstance.data()) { + manager->notificationActivated(notificationData->peerId, notificationData->msgId); + } } Libs::NotifyNotification *_data = nullptr; - PeerId _peerId = 0; - MsgId _msgId = 0; gulong _handlerId = 0; }; @@ -188,6 +215,12 @@ void start() { if (LibNotifyLoaded()) { if (Libs::notify_is_initted() || Libs::notify_init("Telegram Desktop")) { ManagerInstance.makeIfNull(); + if (!ManagerInstance->init()) { + ManagerInstance.clear(); + LOG(("LibNotify Error: manager failed to init!")); + } + } else { + LOG(("LibNotify Error: failed to init!")); } } } @@ -212,7 +245,7 @@ void finish() { class Manager::Impl { public: - Impl(); + bool init(); void showNotification(PeerData *peer, MsgId msgId, const QString &title, const QString &subtitle, bool showUserpic, const QString &msg, bool showReplyButton); void clearAll(); @@ -237,6 +270,9 @@ private: bool showUserpic = false; }; + QString _serverName; + QStringList _capabilities; + using QueuedNotifications = QList; QueuedNotifications _queuedNotifications; @@ -245,24 +281,27 @@ private: Window::Notifications::CachedUserpics _cachedUserpics; bool _actionsSupported = false; - bool _poorSupported = true; + bool _markupSupported = false; + bool _poorSupported = false; }; -void FreeCapability(void *ptr, void *data) { - Libs::g_free(ptr); -} - -Manager::Impl::Impl() { +bool Manager::Impl::init() { if (auto capabilities = Libs::notify_get_server_caps()) { for (auto capability = capabilities; capability; capability = capability->next) { - if (QString::fromUtf8(static_cast(capability->data)) == qstr("actions")) { - _actionsSupported = true; - break; - } - } - Libs::g_list_free_full(capabilities, g_free); - Libs::g_list_free(capabilities); + auto capabilityText = QString::fromUtf8(static_cast(capability->data)); + _capabilities.push_back(capabilityText); + } + Libs::g_list_free_full(capabilities, g_free); + + LOG(("LibNotify capabilities: %1").arg(_capabilities.join(qstr(", ")))); + if (_capabilities.contains(qsl("actions"))) { + _actionsSupported = true; + } else if (_capabilities.contains(qsl("body-markup"))) { + _markupSupported = true; + } + } else { + LOG(("LibNotify Error: could not get capabilities!")); } // Unity and other Notify OSD users handle desktop notifications @@ -270,22 +309,32 @@ Manager::Impl::Impl() { gchar *name = nullptr; if (Libs::notify_get_server_info(&name, nullptr, nullptr, nullptr)) { if (name) { - auto serverName = QString::fromUtf8(static_cast(name)); - LOG(("Notifications Server: %1").arg(serverName)); - if (serverName == qstr("notify-osd")) { + _serverName = QString::fromUtf8(static_cast(name)); + Libs::g_free(name); + + LOG(("Notifications Server: %1").arg(_serverName)); + if (_serverName == qstr("notify-osd")) { +// _poorSupported = true; _actionsSupported = false; } - Libs::g_free(name); + } else { + LOG(("LibNotify Error: successfully got empty server name!")); } + } else { + LOG(("LibNotify Error: could not get server name!")); } - if (!_actionsSupported) { - _poorSupported = true; - } + + return !_serverName.isEmpty(); } void Manager::Impl::showNotification(PeerData *peer, MsgId msgId, const QString &title, const QString &subtitle, bool showUserpic, const QString &msg, bool showReplyButton) { auto titleText = escapeNotificationHtml(title); - auto bodyText = subtitle.isEmpty() ? escapeNotificationHtml(msg) : ("" + escapeNotificationHtml(subtitle) + "\n" + escapeNotificationHtml(msg)); + auto subtitleText = escapeNotificationHtml(subtitle); + auto msgText = escapeNotificationHtml(msg); + if (_markupSupported && !subtitleText.isEmpty()) { + subtitleText = qstr("") + subtitleText + qstr(""); + } + auto bodyText = subtitleText.isEmpty() ? msgText : (subtitleText + '\n' + msgText); QueuedNotification notification; notification.peer = peer; @@ -323,7 +372,7 @@ void Manager::Impl::showNextNotification() { auto peerId = data.peer->id; auto msgId = data.msgId; - auto notification = MakeShared(data.title, data.body, peerId, msgId); + auto notification = MakeShared(data.title, data.body, _capabilities, peerId, msgId); if (!notification->valid()) { return; } @@ -408,6 +457,10 @@ void Manager::Impl::clearNotification(PeerId peerId, MsgId msgId) { Manager::Manager() : _impl(std_::make_unique()) { } +bool Manager::init() { + return _impl->init(); +} + void Manager::clearNotification(PeerId peerId, MsgId msgId) { _impl->clearNotification(peerId, msgId); } diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h index 38672584a..8b52c6328 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h @@ -39,6 +39,8 @@ class Manager : public Window::Notifications::NativeManager { public: Manager(); + bool init(); + void clearNotification(PeerId peerId, MsgId msgId); bool hasPoorSupport() const; bool hasActionsSupport() const; diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index f0c7ed0fb..e72a81336 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -51,7 +51,6 @@ void Manager::notificationActivated(PeerId peerId, MsgId msgId) { onBeforeNotificationActivated(peerId, msgId); if (auto window = App::wnd()) { auto history = App::history(peerId); - window->showFromTray(); if (App::passcoded()) { window->setInnerFocus();