diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.cpp index 0873426e5..8905c33c1 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/event_filter.h" #include "chat_helpers/tabbed_panel.h" #include "chat_helpers/tabbed_selector.h" +#include "core/ui_integration.h" #include "data/data_channel.h" #include "data/data_chat.h" #include "data/data_document.h" @@ -351,8 +352,8 @@ object_ptr AddReactionsSelector( const auto customEmojiPaused = [controller = args.controller] { return controller->isGifPausedAtLeastFor(PauseReason::Layer); }; - raw->setCustomEmojiFactory([=](QStringView data, Fn update) - -> std::unique_ptr { + auto factory = [=](QStringView data, Fn update) + -> std::unique_ptr { const auto id = Data::ParseCustomEmojiData(data); auto result = owner->customEmojiManager().create( data, @@ -364,7 +365,13 @@ object_ptr AddReactionsSelector( } using namespace Ui::Text; return std::make_unique(std::move(result)); - }, std::move(customEmojiPaused)); + }; + raw->setCustomTextContext([=](Fn repaint) { + return std::any(Core::MarkedTextContext{ + .session = session, + .customEmojiRepaint = std::move(repaint), + }); + }, customEmojiPaused, customEmojiPaused, std::move(factory)); const auto callback = args.callback; const auto isCustom = [=](DocumentId id) { diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index d36d2c465..465830fd1 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/shortcuts.h" #include "core/application.h" #include "core/core_settings.h" +#include "core/ui_integration.h" #include "ui/text/text_utilities.h" #include "ui/toast/toast.h" #include "ui/wrap/vertical_layout.h" @@ -322,15 +323,24 @@ TextWithTags PrepareEditText(not_null item) { bool EditTextChanged( not_null item, - const TextWithTags &updated) { + TextWithTags updated) { const auto original = PrepareEditText(item); + auto originalWithEntities = TextWithEntities{ + std::move(original.text), + TextUtilities::ConvertTextTagsToEntities(original.tags) + }; + auto updatedWithEntities = TextWithEntities{ + std::move(updated.text), + TextUtilities::ConvertTextTagsToEntities(updated.tags) + }; + TextUtilities::PrepareForSending(originalWithEntities, 0); + TextUtilities::PrepareForSending(updatedWithEntities, 0); + // Tags can be different for the same entities, because for // animated emoji each tag contains a different random number. // So we compare entities instead of tags. - return (original.text != updated.text) - || (TextUtilities::ConvertTextTagsToEntities(original.tags) - != TextUtilities::ConvertTextTagsToEntities(updated.tags)); + return originalWithEntities != updatedWithEntities; } FnsetTagMimeProcessor( FieldTagMimeProcessor(session, allowPremiumEmoji)); - const auto paused = [customEmojiPaused] { + field->setCustomTextContext([=](Fn repaint) { + return std::any(Core::MarkedTextContext{ + .session = session, + .customEmojiRepaint = std::move(repaint), + }); + }, [customEmojiPaused] { return On(PowerSaving::kEmojiChat) || customEmojiPaused(); - }; - field->setCustomEmojiFactory( - session->data().customEmojiManager().factory(), - std::move(customEmojiPaused)); + }, [customEmojiPaused] { + return On(PowerSaving::kChatSpoiler) || customEmojiPaused(); + }); field->setInstantReplaces(Ui::InstantReplaces::Default()); field->setInstantReplacesEnabled( Core::App().settings().replaceEmojiValue()); diff --git a/Telegram/SourceFiles/chat_helpers/message_field.h b/Telegram/SourceFiles/chat_helpers/message_field.h index 7efdb7d18..041b54d66 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.h +++ b/Telegram/SourceFiles/chat_helpers/message_field.h @@ -42,7 +42,7 @@ class Show; [[nodiscard]] TextWithTags PrepareEditText(not_null item); [[nodiscard]] bool EditTextChanged( not_null item, - const TextWithTags &updated); + TextWithTags updated); Fn UiIntegration::createCustomEmoji( - const QString &data, + QStringView data, const std::any &context) { const auto my = std::any_cast(&context); if (!my || !my->session) { diff --git a/Telegram/SourceFiles/core/ui_integration.h b/Telegram/SourceFiles/core/ui_integration.h index 36ee45777..a745f0fce 100644 --- a/Telegram/SourceFiles/core/ui_integration.h +++ b/Telegram/SourceFiles/core/ui_integration.h @@ -58,7 +58,7 @@ public: const Ui::Emoji::One *defaultEmojiVariant( const Ui::Emoji::One *emoji) override; std::unique_ptr createCustomEmoji( - const QString &data, + QStringView data, const std::any &context) override; Fn createSpoilerRepaint(const std::any &context) override; bool allowClickHandlerActivation( diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 20caa93a8..29bce3f8f 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 20caa93a8d2b5b279f36eb19d9200be071420ba3 +Subproject commit 29bce3f8ff693e0386617dfd550a225d0ff11c5d