diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp index 0c5cbd18f..d209001c9 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp @@ -405,7 +405,7 @@ public: const QString &title, const QString &subtitle, const QString &msg, - bool hideReplyButton); + Window::Notifications::Manager::DisplayOptions options); NotificationData(const NotificationData &other) = delete; NotificationData &operator=(const NotificationData &other) = delete; @@ -453,7 +453,7 @@ bool NotificationData::init( const QString &title, const QString &subtitle, const QString &msg, - bool hideReplyButton) { + Window::Notifications::Manager::DisplayOptions options) { try { _dbusConnection = Gio::DBus::Connection::get_sync( Gio::DBus::BusType::BUS_TYPE_SESSION); @@ -524,13 +524,13 @@ bool NotificationData::init( _actions.push_back("default"); _actions.push_back({}); - if (!hideReplyButton) { + if (!options.hideMarkAsRead) { _actions.push_back("mail-mark-read"); _actions.push_back( tr::lng_context_mark_read(tr::now).toStdString()); } - if (capabilities.contains("inline-reply") && !hideReplyButton) { + if (capabilities.contains("inline-reply") && !options.hideReplyButton) { _actions.push_back("inline-reply"); _actions.push_back( tr::lng_notification_reply(tr::now).toStdString()); @@ -826,8 +826,7 @@ public: const QString &title, const QString &subtitle, const QString &msg, - bool hideNameAndPhoto, - bool hideReplyButton); + DisplayOptions options); void clearAll(); void clearFromHistory(not_null history); void clearFromSession(not_null session); @@ -883,8 +882,7 @@ void Manager::Private::showNotification( const QString &title, const QString &subtitle, const QString &msg, - bool hideNameAndPhoto, - bool hideReplyButton) { + DisplayOptions options) { if (!Supported()) { return; } @@ -901,7 +899,7 @@ void Manager::Private::showNotification( title, subtitle, msg, - hideReplyButton); + options); if (!inited) { return; } @@ -1020,8 +1018,7 @@ void Manager::doShowNativeNotification( const QString &title, const QString &subtitle, const QString &msg, - bool hideNameAndPhoto, - bool hideReplyButton) { + DisplayOptions options) { _private->showNotification( peer, userpicView, @@ -1029,8 +1026,7 @@ void Manager::doShowNativeNotification( title, subtitle, msg, - hideNameAndPhoto, - hideReplyButton); + options); } void Manager::doClearAllFast() { diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h index c3ff1c0a8..2689e4f82 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h @@ -26,8 +26,7 @@ protected: const QString &title, const QString &subtitle, const QString &msg, - bool hideNameAndPhoto, - bool hideReplyButton) override; + DisplayOptions options) override; void doClearAllFast() override; void doClearFromHistory(not_null history) override; void doClearFromSession(not_null session) override; diff --git a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.h b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.h index a5f8de982..a743f1794 100644 --- a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.h +++ b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.h @@ -26,8 +26,7 @@ protected: const QString &title, const QString &subtitle, const QString &msg, - bool hideNameAndPhoto, - bool hideReplyButton) override; + DisplayOptions options) override; void doClearAllFast() override; void doClearFromHistory(not_null history) override; void doClearFromSession(not_null session) override; diff --git a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm index cb892dd06..5e1e6fbf0 100644 --- a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm +++ b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm @@ -184,8 +184,7 @@ public: const QString &title, const QString &subtitle, const QString &msg, - bool hideNameAndPhoto, - bool hideReplyButton); + DisplayOptions options); void clearAll(); void clearFromHistory(not_null history); void clearFromSession(not_null session); @@ -250,8 +249,7 @@ void Manager::Private::showNotification( const QString &title, const QString &subtitle, const QString &msg, - bool hideNameAndPhoto, - bool hideReplyButton) { + DisplayOptions options) { @autoreleasepool { NSUserNotification *notification = [[[NSUserNotification alloc] init] autorelease]; @@ -279,7 +277,8 @@ void Manager::Private::showNotification( [notification setTitle:Q2NSString(title)]; [notification setSubtitle:Q2NSString(subtitle)]; [notification setInformativeText:Q2NSString(msg)]; - if (!hideNameAndPhoto && [notification respondsToSelector:@selector(setContentImage:)]) { + if (!options.hideNameAndPhoto + && [notification respondsToSelector:@selector(setContentImage:)]) { auto userpic = peer->isSelf() ? Ui::EmptyUserpic::GenerateSavedMessages(st::notifyMacPhotoSize) : peer->isRepliesChat() @@ -289,7 +288,8 @@ void Manager::Private::showNotification( [notification setContentImage:img]; } - if (!hideReplyButton && [notification respondsToSelector:@selector(setHasReplyButton:)]) { + if (!options.hideReplyButton + && [notification respondsToSelector:@selector(setHasReplyButton:)]) { [notification setHasReplyButton:YES]; } @@ -419,8 +419,7 @@ void Manager::doShowNativeNotification( const QString &title, const QString &subtitle, const QString &msg, - bool hideNameAndPhoto, - bool hideReplyButton) { + DisplayOptions options) { _private->showNotification( peer, userpicView, @@ -428,8 +427,7 @@ void Manager::doShowNativeNotification( title, subtitle, msg, - hideNameAndPhoto, - hideReplyButton); + options); } void Manager::doClearAllFast() { diff --git a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp index 0dc53ba87..422fd023d 100644 --- a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp +++ b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp @@ -51,19 +51,11 @@ namespace Notifications { #ifndef __MINGW32__ namespace { -[[nodiscard]] std::wstring NotificationTemplate(QString id) { +[[nodiscard]] std::wstring NotificationTemplate( + QString id, + Window::Notifications::Manager::DisplayOptions options) { const auto wid = id.replace('&', "&").toStdWString(); - return LR"( - - - - - - - - - - + const auto fastReply = LR"( +)"; + const auto markAsRead = LR"( - - )"; -} - -[[nodiscard]] std::wstring NotificationTemplateSmall(QString id) { - const auto wid = id.replace('&', "&").toStdWString(); + const auto actions = (options.hideReplyButton ? L"" : fastReply) + + (options.hideMarkAsRead ? L"" : markAsRead); return LR"( @@ -93,6 +82,9 @@ namespace { +)" + (actions.empty() + ? L"" + : (L"" + actions + L"")) + LR"( )"; @@ -160,11 +152,13 @@ void SetImageSrc(const XmlDocument &toastXml, const std::wstring &path) { // Throws. void SetReplyIconSrc(const XmlDocument &toastXml, const std::wstring &path) { const auto nodeList = toastXml.GetElementsByTagName(L"action"); - const auto attributes = nodeList.Item(0).Attributes(); - return SetNodeValueString( - toastXml, - attributes.GetNamedItem(L"imageUri"), - L"file:///" + path); + const auto length = int(nodeList.Length()); + for (auto i = 0; i != length; ++i) { + const auto attributes = nodeList.Item(i).Attributes(); + if (const auto uri = attributes.GetNamedItem(L"imageUri")) { + return SetNodeValueString(toastXml, uri, L"file:///" + path); + } + } } // Throws. @@ -192,11 +186,16 @@ void SetMarkAsReadText( const XmlDocument &toastXml, const std::wstring &text) { const auto nodeList = toastXml.GetElementsByTagName(L"action"); - const auto attributes = nodeList.Item(1).Attributes(); - return SetNodeValueString( - toastXml, - attributes.GetNamedItem(L"content"), - text); + const auto length = int(nodeList.Length()); + for (auto i = 0; i != length; ++i) { + const auto attributes = nodeList.Item(i).Attributes(); + if (!attributes.GetNamedItem(L"imageUri")) { + return SetNodeValueString( + toastXml, + attributes.GetNamedItem(L"content"), + text); + } + } } auto Checked = false; @@ -416,8 +415,7 @@ public: const QString &title, const QString &subtitle, const QString &msg, - bool hideNameAndPhoto, - bool hideReplyButton); + DisplayOptions options); void clearAll(); void clearFromHistory(not_null history); void clearFromSession(not_null session); @@ -439,8 +437,7 @@ private: const QString &title, const QString &subtitle, const QString &msg, - bool hideNameAndPhoto, - bool hideReplyButton); + DisplayOptions options); [[nodiscard]] std::wstring ensureSendButtonIcon(); Window::Notifications::CachedUserpics _cachedUserpics; @@ -591,8 +588,7 @@ bool Manager::Private::showNotification( const QString &title, const QString &subtitle, const QString &msg, - bool hideNameAndPhoto, - bool hideReplyButton) { + DisplayOptions options) { if (!_notifier) { return false; } @@ -605,8 +601,7 @@ bool Manager::Private::showNotification( title, subtitle, msg, - hideNameAndPhoto, - hideReplyButton); + options); }).value_or(false); } @@ -626,8 +621,7 @@ bool Manager::Private::showNotificationInTryCatch( const QString &title, const QString &subtitle, const QString &msg, - bool hideNameAndPhoto, - bool hideReplyButton) { + DisplayOptions options) { const auto withSubtitle = !subtitle.isEmpty(); auto toastXml = XmlDocument(); @@ -646,9 +640,7 @@ bool Manager::Private::showNotificationInTryCatch( const auto modern = Platform::IsWindows10OrGreater(); if (modern) { - toastXml.LoadXml(hideReplyButton - ? NotificationTemplateSmall(idString) - : NotificationTemplate(idString)); + toastXml.LoadXml(NotificationTemplate(idString, options)); } else { toastXml = ToastNotificationManager::GetTemplateContent( (withSubtitle @@ -658,7 +650,7 @@ bool Manager::Private::showNotificationInTryCatch( SetAction(toastXml, idString); } - const auto userpicKey = hideNameAndPhoto + const auto userpicKey = options.hideNameAndPhoto ? InMemoryKey() : peer->userpicUniqueKey(userpicView); const auto userpicPath = _cachedUserpics.get( @@ -667,11 +659,13 @@ bool Manager::Private::showNotificationInTryCatch( userpicView); const auto userpicPathWide = QDir::toNativeSeparators( userpicPath).toStdWString(); - if (modern && !hideReplyButton) { + if (modern && !options.hideReplyButton) { SetReplyIconSrc(toastXml, ensureSendButtonIcon()); SetReplyPlaceholder( toastXml, tr::lng_message_ph(tr::now).toStdWString()); + } + if (modern && !options.hideMarkAsRead) { SetMarkAsReadText( toastXml, tr::lng_context_mark_read(tr::now).toStdWString()); @@ -814,8 +808,7 @@ void Manager::doShowNativeNotification( const QString &title, const QString &subtitle, const QString &msg, - bool hideNameAndPhoto, - bool hideReplyButton) { + DisplayOptions options) { _private->showNotification( peer, userpicView, @@ -823,8 +816,7 @@ void Manager::doShowNativeNotification( title, subtitle, msg, - hideNameAndPhoto, - hideReplyButton); + options); } void Manager::doClearAllFast() { diff --git a/Telegram/SourceFiles/platform/win/notifications_manager_win.h b/Telegram/SourceFiles/platform/win/notifications_manager_win.h index f9d5de0b6..9833cb8dc 100644 --- a/Telegram/SourceFiles/platform/win/notifications_manager_win.h +++ b/Telegram/SourceFiles/platform/win/notifications_manager_win.h @@ -34,8 +34,7 @@ protected: const QString &title, const QString &subtitle, const QString &msg, - bool hideNameAndPhoto, - bool hideReplyButton) override; + DisplayOptions options) override; void doClearAllFast() override; void doClearFromHistory(not_null history) override; void doClearFromSession(not_null session) override; diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index 9d8a652ed..97b01272e 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -593,11 +593,13 @@ Manager::DisplayOptions Manager::getNotificationOptions( || (view > Core::Settings::NotifyView::ShowName); result.hideMessageText = hideEverything || (view > Core::Settings::NotifyView::ShowPreview); - result.hideReplyButton = result.hideMessageText + result.hideMarkAsRead = result.hideMessageText || !item || ((item->out() || item->history()->peer->isSelf()) - && item->isFromScheduled()) + && item->isFromScheduled()); + result.hideReplyButton = result.hideMarkAsRead || !item->history()->peer->canWrite() + || item->history()->peer->isBroadcast() || (item->history()->peer->slowmodeSecondsLeft() > 0); return result; } @@ -755,8 +757,7 @@ void NativeManager::doShowNotification( scheduled ? WrapFromScheduled(fullTitle) : fullTitle, subtitle, text, - options.hideNameAndPhoto, - options.hideReplyButton); + options); } bool NativeManager::forceHideDetails() const { diff --git a/Telegram/SourceFiles/window/notifications_manager.h b/Telegram/SourceFiles/window/notifications_manager.h index 408eeb8af..e867aad4c 100644 --- a/Telegram/SourceFiles/window/notifications_manager.h +++ b/Telegram/SourceFiles/window/notifications_manager.h @@ -199,6 +199,7 @@ public: struct DisplayOptions { bool hideNameAndPhoto = false; bool hideMessageText = false; + bool hideMarkAsRead = false; bool hideReplyButton = false; }; [[nodiscard]] DisplayOptions getNotificationOptions( @@ -289,8 +290,7 @@ protected: const QString &title, const QString &subtitle, const QString &msg, - bool hideNameAndPhoto, - bool hideReplyButton) = 0; + DisplayOptions options) = 0; }; @@ -310,8 +310,7 @@ protected: const QString &title, const QString &subtitle, const QString &msg, - bool hideNameAndPhoto, - bool hideReplyButton) override { + DisplayOptions options) override { } void doClearAllFast() override { }