From 7a10d3d82ce1c42d3f07cb94963a1088c75221f5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 1 Jul 2022 17:36:58 +0400 Subject: [PATCH] Support animated emoji in share box comment. --- Telegram/SourceFiles/boxes/share_box.cpp | 26 +++-------- Telegram/SourceFiles/boxes/share_box.h | 2 - .../chat_helpers/message_field.cpp | 44 ++++++++++--------- .../SourceFiles/chat_helpers/message_field.h | 6 +++ .../window/notifications_manager_default.cpp | 10 +++++ Telegram/lib_ui | 2 +- 6 files changed, 48 insertions(+), 42 deletions(-) diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 7e6171c9c..c7652ae55 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -220,28 +220,16 @@ void ShareBox::prepareCommentField() { connect(field, &Ui::InputField::submitted, [=] { submit({}); }); - - field->setInstantReplaces(Ui::InstantReplaces::Default()); - field->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); - field->setMarkdownReplacesEnabled(rpl::single(true)); - if (_descriptor.initEditLink) { - _descriptor.initEditLink(field); - } else if (_show->valid()) { - field->setEditLinkCallback( - DefaultEditLinkCallback( - _show, - _descriptor.session, - field, - _descriptor.stLabel)); + if (_show->valid()) { + InitMessageFieldHandlers( + _descriptor.session, + _show, + field, + nullptr, + _descriptor.stLabel); } field->setSubmitSettings(Core::App().settings().sendSubmitWay()); - if (_descriptor.initSpellchecker) { - _descriptor.initSpellchecker(field); - } else if (_show->valid()) { - InitSpellchecker(_show, _descriptor.session, field, true); - } Ui::SendPendingMoveResizeEvents(_comment); if (_bottomWidget) { Ui::SendPendingMoveResizeEvents(_bottomWidget); diff --git a/Telegram/SourceFiles/boxes/share_box.h b/Telegram/SourceFiles/boxes/share_box.h index 053c5893d..e9ab80802 100644 --- a/Telegram/SourceFiles/boxes/share_box.h +++ b/Telegram/SourceFiles/boxes/share_box.h @@ -81,8 +81,6 @@ public: CopyCallback copyCallback; SubmitCallback submitCallback; FilterCallback filterCallback; - Fn)> initSpellchecker; - Fn)> initEditLink; object_ptr bottomWidget = { nullptr }; rpl::producer copyLinkText; const style::MultiSelect *stMultiSelect = nullptr; diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index c213f062f..1baa42b6e 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -53,23 +53,22 @@ constexpr auto kParseLinksTimeout = crl::time(1000); // ignore tags for different users. class FieldTagMimeProcessor final { public: - explicit FieldTagMimeProcessor( - not_null controller); + explicit FieldTagMimeProcessor(not_null _session); QString operator()(QStringView mimeTag); private: - const not_null _controller; + const not_null _session; }; FieldTagMimeProcessor::FieldTagMimeProcessor( - not_null controller) -: _controller(controller) { + not_null session) +: _session(session) { } QString FieldTagMimeProcessor::operator()(QStringView mimeTag) { - const auto id = _controller->session().userId().bare; + const auto id = _session->userId().bare; auto all = TextUtilities::SplitTags(mimeTag); for (auto i = all.begin(); i != all.end();) { const auto tag = *i; @@ -287,31 +286,36 @@ Fn controller, + not_null session, + std::shared_ptr show, not_null field, - Window::GifPauseReason pauseReasonLevel) { - const auto show = std::make_shared(controller); - const auto session = &controller->session(); - - field->setTagMimeProcessor(FieldTagMimeProcessor(controller)); + Fn customEmojiPaused, + const style::InputField *fieldStyle) { + field->setTagMimeProcessor(FieldTagMimeProcessor(session)); field->setCustomEmojiFactory([=](QStringView data, Fn update) { - return controller->session().data().customEmojiManager().create( + return session->data().customEmojiManager().create( data, std::move(update)); - }, [=] { - return controller->isGifPausedAtLeastFor(pauseReasonLevel); - }); + }, std::move(customEmojiPaused)); field->setInstantReplaces(Ui::InstantReplaces::Default()); field->setInstantReplacesEnabled( Core::App().settings().replaceEmojiValue()); field->setMarkdownReplacesEnabled(rpl::single(true)); field->setEditLinkCallback( - DefaultEditLinkCallback(show, session, field)); + DefaultEditLinkCallback(show, session, field, fieldStyle)); - InitSpellchecker( + InitSpellchecker(show, session, field, fieldStyle != nullptr); +} + +void InitMessageFieldHandlers( + not_null controller, + not_null field, + Window::GifPauseReason pauseReasonLevel) { + InitMessageFieldHandlers( + &controller->session(), std::make_shared(controller), - session, - field); + field, + [=] { return controller->isGifPausedAtLeastFor(pauseReasonLevel); }); } void InitMessageFieldGeometry(not_null field) { diff --git a/Telegram/SourceFiles/chat_helpers/message_field.h b/Telegram/SourceFiles/chat_helpers/message_field.h index ca4472750..a5236ed8a 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.h +++ b/Telegram/SourceFiles/chat_helpers/message_field.h @@ -44,6 +44,12 @@ Fn session, not_null field, const style::InputField *fieldStyle = nullptr); +void InitMessageFieldHandlers( + not_null session, + std::shared_ptr show, + not_null field, + Fn customEmojiPaused, + const style::InputField *fieldStyle = nullptr); void InitMessageFieldHandlers( not_null controller, not_null field, diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index cfbca3552..7bc9ffc89 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -19,6 +19,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/emoji_config.h" #include "ui/empty_userpic.h" #include "ui/ui_utility.h" +#include "data/data_session.h" +#include "data/stickers/data_custom_emoji.h" #include "dialogs/ui/dialogs_layout.h" #include "window/window_controller.h" #include "storage/file_download.h" @@ -974,6 +976,14 @@ void Notification::showReplyField() { _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)); + }); // Catch mouse press event to activate the window. QCoreApplication::instance()->installEventFilter(this); diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 0b829240f..464c6a617 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 0b829240fd3ade757aa4e957c17d84a81ef1c3ff +Subproject commit 464c6a61711fa7b66d45829bde582d36e23f0b1a