From 3907a103fcc617e76b2206a183d3470162b0fc35 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 15 May 2025 15:34:23 +0400 Subject: [PATCH] Fix possible notification click problem. Fixes #29293. --- .../platform/win/notifications_manager_win.cpp | 4 +++- .../SourceFiles/window/notifications_manager.cpp | 14 ++++++++------ .../SourceFiles/window/notifications_manager.h | 7 ++++++- .../window/notifications_manager_default.cpp | 4 +++- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp index 48e187cbfc..9a4f028af4 100644 --- a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp +++ b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp @@ -656,7 +656,9 @@ void Manager::Private::handleActivation(const ToastActivation &activation) { } else if (action == "mark") { manager->notificationReplied(id, TextWithTags()); } else { - manager->notificationActivated(id, text); + manager->notificationActivated(id, { + .draft = std::move(text), + }); } } diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index a69ff7bd4c..3f312386bb 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -1105,7 +1105,7 @@ QString Manager::accountNameSeparator() { void Manager::notificationActivated( NotificationId id, - const TextWithTags &reply) { + ActivateOptions &&options) { onBeforeNotificationActivated(id); if (const auto session = system()->findSession(id.contextId.sessionId)) { const auto history = session->data().history( @@ -1114,7 +1114,7 @@ void Manager::notificationActivated( history->peer, id.msgId); const auto topic = item ? item->topic() : nullptr; - if (!reply.text.isEmpty()) { + if (!options.draft.text.isEmpty()) { const auto topicRootId = topic ? topic->rootId() : id.contextId.topicRootId; @@ -1123,21 +1123,23 @@ void Manager::notificationActivated( && id.msgId != topicRootId) ? FullMsgId(history->peer->id, id.msgId) : FullMsgId(); + const auto length = int(options.draft.text.size()); auto draft = std::make_unique( - reply, + std::move(options.draft), FullReplyTo{ .messageId = replyToId, .topicRootId = topicRootId, }, MessageCursor{ - int(reply.text.size()), - int(reply.text.size()), + length, + length, Ui::kQFixedMax, }, Data::WebPageDraft()); history->setLocalDraft(std::move(draft)); } - const auto openSeparated = base::IsCtrlPressed(); + const auto openSeparated = options.allowNewWindow + && base::IsCtrlPressed(); const auto window = openNotificationMessage( history, id.msgId, diff --git a/Telegram/SourceFiles/window/notifications_manager.h b/Telegram/SourceFiles/window/notifications_manager.h index 4786c5ca64..9caa1dd264 100644 --- a/Telegram/SourceFiles/window/notifications_manager.h +++ b/Telegram/SourceFiles/window/notifications_manager.h @@ -91,6 +91,11 @@ extern base::options::toggle OptionGNotification; class Manager; +struct ActivateOptions { + TextWithTags draft; + bool allowNewWindow = false; +}; + class System final { public: System(); @@ -283,7 +288,7 @@ public: void notificationActivated( NotificationId id, - const TextWithTags &draft = {}); + ActivateOptions &&options = {}); void notificationReplied(NotificationId id, const TextWithTags &reply); struct DisplayOptions { diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index 8a8ccea366..44bf48131b 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -1202,7 +1202,9 @@ void Notification::mousePressEvent(QMouseEvent *e) { unlinkHistoryInManager(); } else { e->ignore(); - manager()->notificationActivated(myId()); + manager()->notificationActivated(myId(), { + .allowNewWindow = true, + }); } }