From ee8d8171f7814fab7c54109430f744b3dd28f286 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 1 Jul 2022 21:46:04 +0400 Subject: [PATCH] Support custom emoji in custom notification replies. --- .../chat_helpers/message_field.cpp | 9 ++-- Telegram/SourceFiles/ui/text/text_options.cpp | 2 +- .../window/notifications_manager_default.cpp | 45 ++++++++++--------- .../window/notifications_manager_default.h | 1 + 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 1baa42b6e0..71307e2c05 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -301,10 +301,11 @@ void InitMessageFieldHandlers( field->setInstantReplacesEnabled( Core::App().settings().replaceEmojiValue()); field->setMarkdownReplacesEnabled(rpl::single(true)); - field->setEditLinkCallback( - DefaultEditLinkCallback(show, session, field, fieldStyle)); - - InitSpellchecker(show, session, field, fieldStyle != nullptr); + if (show) { + field->setEditLinkCallback( + DefaultEditLinkCallback(show, session, field, fieldStyle)); + InitSpellchecker(show, session, field, fieldStyle != nullptr); + } } void InitMessageFieldHandlers( diff --git a/Telegram/SourceFiles/ui/text/text_options.cpp b/Telegram/SourceFiles/ui/text/text_options.cpp index b2aa2fb500..382314370a 100644 --- a/Telegram/SourceFiles/ui/text/text_options.cpp +++ b/Telegram/SourceFiles/ui/text/text_options.cpp @@ -76,7 +76,7 @@ TextParseOptions TextNameOptions = { }; TextParseOptions TextDialogOptions = { - TextParsePlainLinks, // flags + TextParsePlainLinks | TextParseMarkdown, // flags 0, // maxw is style-dependent 1, // maxh Qt::LayoutDirectionAuto, // lang-dependent diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index 365506f147..a9bbc58631 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_specific.h" #include "core/application.h" #include "core/ui_integration.h" +#include "chat_helpers/message_field.h" #include "lang/lang_keys.h" #include "ui/widgets/buttons.h" #include "ui/widgets/input_fields.h" @@ -731,6 +732,8 @@ void Notification::updateGeometry(int x, int y, int width, int height) { } void Notification::paintEvent(QPaintEvent *e) { + repaintText(); + Painter p(this); p.setClipRect(e->rect()); p.drawImage(0, 0, _cache); @@ -756,16 +759,21 @@ void Notification::customEmojiCallback() { return; } _textRepaintScheduled = true; - InvokeQueued(this, [=] { - _textRepaintScheduled = false; - if (_cache.isNull()) { - return; - } - Painter p(&_cache); - p.fillRect(_textRect, st::notificationBg); - paintText(p); - update(); - }); + crl::on_main(this, [=] { repaintText(); }); +} + +void Notification::repaintText() { + if (!_textRepaintScheduled) { + return; + } + _textRepaintScheduled = false; + if (_cache.isNull()) { + return; + } + Painter p(&_cache); + p.fillRect(_textRect, st::notificationBg); + paintText(p); + update(); } void Notification::paintText(Painter &p) { @@ -1013,18 +1021,11 @@ void Notification::showReplyField() { _replyArea->setFocus(); _replyArea->setMaxLength(MaxMessageSize); _replyArea->setSubmitSettings(Ui::InputField::SubmitSettings::Both); - _replyArea->setInstantReplaces(Ui::InstantReplaces::Default()); - _replyArea->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); - _replyArea->setMarkdownReplacesEnabled(rpl::single(true)); - const auto session = &_item->history()->session(); - _replyArea->setCustomEmojiFactory([=]( - QStringView data, - Fn update) { - return session->data().customEmojiManager().create( - data, - std::move(update)); - }); + InitMessageFieldHandlers( + &_item->history()->session(), + nullptr, + _replyArea.data(), + nullptr); // Catch mouse press event to activate the window. QCoreApplication::instance()->installEventFilter(this); diff --git a/Telegram/SourceFiles/window/notifications_manager_default.h b/Telegram/SourceFiles/window/notifications_manager_default.h index 28a09b7704..b0f710ff58 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.h +++ b/Telegram/SourceFiles/window/notifications_manager_default.h @@ -261,6 +261,7 @@ private: void changeHeight(int newHeight); void updateGeometry(int x, int y, int width, int height) override; void actionsOpacityCallback(); + void repaintText(); void paintText(Painter &p); void customEmojiCallback();