Fix possible notification click problem.

Fixes #29293.
This commit is contained in:
John Preston 2025-05-15 15:34:23 +04:00
parent efb566bcc7
commit 3907a103fc
4 changed files with 20 additions and 9 deletions

View file

@ -656,7 +656,9 @@ void Manager::Private::handleActivation(const ToastActivation &activation) {
} else if (action == "mark") { } else if (action == "mark") {
manager->notificationReplied(id, TextWithTags()); manager->notificationReplied(id, TextWithTags());
} else { } else {
manager->notificationActivated(id, text); manager->notificationActivated(id, {
.draft = std::move(text),
});
} }
} }

View file

@ -1105,7 +1105,7 @@ QString Manager::accountNameSeparator() {
void Manager::notificationActivated( void Manager::notificationActivated(
NotificationId id, NotificationId id,
const TextWithTags &reply) { ActivateOptions &&options) {
onBeforeNotificationActivated(id); onBeforeNotificationActivated(id);
if (const auto session = system()->findSession(id.contextId.sessionId)) { if (const auto session = system()->findSession(id.contextId.sessionId)) {
const auto history = session->data().history( const auto history = session->data().history(
@ -1114,7 +1114,7 @@ void Manager::notificationActivated(
history->peer, history->peer,
id.msgId); id.msgId);
const auto topic = item ? item->topic() : nullptr; const auto topic = item ? item->topic() : nullptr;
if (!reply.text.isEmpty()) { if (!options.draft.text.isEmpty()) {
const auto topicRootId = topic const auto topicRootId = topic
? topic->rootId() ? topic->rootId()
: id.contextId.topicRootId; : id.contextId.topicRootId;
@ -1123,21 +1123,23 @@ void Manager::notificationActivated(
&& id.msgId != topicRootId) && id.msgId != topicRootId)
? FullMsgId(history->peer->id, id.msgId) ? FullMsgId(history->peer->id, id.msgId)
: FullMsgId(); : FullMsgId();
const auto length = int(options.draft.text.size());
auto draft = std::make_unique<Data::Draft>( auto draft = std::make_unique<Data::Draft>(
reply, std::move(options.draft),
FullReplyTo{ FullReplyTo{
.messageId = replyToId, .messageId = replyToId,
.topicRootId = topicRootId, .topicRootId = topicRootId,
}, },
MessageCursor{ MessageCursor{
int(reply.text.size()), length,
int(reply.text.size()), length,
Ui::kQFixedMax, Ui::kQFixedMax,
}, },
Data::WebPageDraft()); Data::WebPageDraft());
history->setLocalDraft(std::move(draft)); history->setLocalDraft(std::move(draft));
} }
const auto openSeparated = base::IsCtrlPressed(); const auto openSeparated = options.allowNewWindow
&& base::IsCtrlPressed();
const auto window = openNotificationMessage( const auto window = openNotificationMessage(
history, history,
id.msgId, id.msgId,

View file

@ -91,6 +91,11 @@ extern base::options::toggle OptionGNotification;
class Manager; class Manager;
struct ActivateOptions {
TextWithTags draft;
bool allowNewWindow = false;
};
class System final { class System final {
public: public:
System(); System();
@ -283,7 +288,7 @@ public:
void notificationActivated( void notificationActivated(
NotificationId id, NotificationId id,
const TextWithTags &draft = {}); ActivateOptions &&options = {});
void notificationReplied(NotificationId id, const TextWithTags &reply); void notificationReplied(NotificationId id, const TextWithTags &reply);
struct DisplayOptions { struct DisplayOptions {

View file

@ -1202,7 +1202,9 @@ void Notification::mousePressEvent(QMouseEvent *e) {
unlinkHistoryInManager(); unlinkHistoryInManager();
} else { } else {
e->ignore(); e->ignore();
manager()->notificationActivated(myId()); manager()->notificationActivated(myId(), {
.allowNewWindow = true,
});
} }
} }