Support animated emoji in share box comment.

This commit is contained in:
John Preston 2022-07-01 17:36:58 +04:00
parent 806c5ddf29
commit 7a10d3d82c
6 changed files with 48 additions and 42 deletions

View file

@ -220,28 +220,16 @@ void ShareBox::prepareCommentField() {
connect(field, &Ui::InputField::submitted, [=] { connect(field, &Ui::InputField::submitted, [=] {
submit({}); submit({});
}); });
if (_show->valid()) {
field->setInstantReplaces(Ui::InstantReplaces::Default()); InitMessageFieldHandlers(
field->setInstantReplacesEnabled( _descriptor.session,
Core::App().settings().replaceEmojiValue()); _show,
field->setMarkdownReplacesEnabled(rpl::single(true)); field,
if (_descriptor.initEditLink) { nullptr,
_descriptor.initEditLink(field); _descriptor.stLabel);
} else if (_show->valid()) {
field->setEditLinkCallback(
DefaultEditLinkCallback(
_show,
_descriptor.session,
field,
_descriptor.stLabel));
} }
field->setSubmitSettings(Core::App().settings().sendSubmitWay()); 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); Ui::SendPendingMoveResizeEvents(_comment);
if (_bottomWidget) { if (_bottomWidget) {
Ui::SendPendingMoveResizeEvents(_bottomWidget); Ui::SendPendingMoveResizeEvents(_bottomWidget);

View file

@ -81,8 +81,6 @@ public:
CopyCallback copyCallback; CopyCallback copyCallback;
SubmitCallback submitCallback; SubmitCallback submitCallback;
FilterCallback filterCallback; FilterCallback filterCallback;
Fn<void(not_null<Ui::InputField*>)> initSpellchecker;
Fn<void(not_null<Ui::InputField*>)> initEditLink;
object_ptr<Ui::RpWidget> bottomWidget = { nullptr }; object_ptr<Ui::RpWidget> bottomWidget = { nullptr };
rpl::producer<QString> copyLinkText; rpl::producer<QString> copyLinkText;
const style::MultiSelect *stMultiSelect = nullptr; const style::MultiSelect *stMultiSelect = nullptr;

View file

@ -53,23 +53,22 @@ constexpr auto kParseLinksTimeout = crl::time(1000);
// ignore tags for different users. // ignore tags for different users.
class FieldTagMimeProcessor final { class FieldTagMimeProcessor final {
public: public:
explicit FieldTagMimeProcessor( explicit FieldTagMimeProcessor(not_null<Main::Session*> _session);
not_null<Window::SessionController*> controller);
QString operator()(QStringView mimeTag); QString operator()(QStringView mimeTag);
private: private:
const not_null<Window::SessionController*> _controller; const not_null<Main::Session*> _session;
}; };
FieldTagMimeProcessor::FieldTagMimeProcessor( FieldTagMimeProcessor::FieldTagMimeProcessor(
not_null<Window::SessionController*> controller) not_null<Main::Session*> session)
: _controller(controller) { : _session(session) {
} }
QString FieldTagMimeProcessor::operator()(QStringView mimeTag) { QString FieldTagMimeProcessor::operator()(QStringView mimeTag) {
const auto id = _controller->session().userId().bare; const auto id = _session->userId().bare;
auto all = TextUtilities::SplitTags(mimeTag); auto all = TextUtilities::SplitTags(mimeTag);
for (auto i = all.begin(); i != all.end();) { for (auto i = all.begin(); i != all.end();) {
const auto tag = *i; const auto tag = *i;
@ -287,31 +286,36 @@ Fn<bool(
} }
void InitMessageFieldHandlers( void InitMessageFieldHandlers(
not_null<Window::SessionController*> controller, not_null<Main::Session*> session,
std::shared_ptr<Ui::Show> show,
not_null<Ui::InputField*> field, not_null<Ui::InputField*> field,
Window::GifPauseReason pauseReasonLevel) { Fn<bool()> customEmojiPaused,
const auto show = std::make_shared<Window::Show>(controller); const style::InputField *fieldStyle) {
const auto session = &controller->session(); field->setTagMimeProcessor(FieldTagMimeProcessor(session));
field->setTagMimeProcessor(FieldTagMimeProcessor(controller));
field->setCustomEmojiFactory([=](QStringView data, Fn<void()> update) { field->setCustomEmojiFactory([=](QStringView data, Fn<void()> update) {
return controller->session().data().customEmojiManager().create( return session->data().customEmojiManager().create(
data, data,
std::move(update)); std::move(update));
}, [=] { }, std::move(customEmojiPaused));
return controller->isGifPausedAtLeastFor(pauseReasonLevel);
});
field->setInstantReplaces(Ui::InstantReplaces::Default()); field->setInstantReplaces(Ui::InstantReplaces::Default());
field->setInstantReplacesEnabled( field->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue()); Core::App().settings().replaceEmojiValue());
field->setMarkdownReplacesEnabled(rpl::single(true)); field->setMarkdownReplacesEnabled(rpl::single(true));
field->setEditLinkCallback( field->setEditLinkCallback(
DefaultEditLinkCallback(show, session, field)); DefaultEditLinkCallback(show, session, field, fieldStyle));
InitSpellchecker( InitSpellchecker(show, session, field, fieldStyle != nullptr);
}
void InitMessageFieldHandlers(
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field,
Window::GifPauseReason pauseReasonLevel) {
InitMessageFieldHandlers(
&controller->session(),
std::make_shared<Window::Show>(controller), std::make_shared<Window::Show>(controller),
session, field,
field); [=] { return controller->isGifPausedAtLeastFor(pauseReasonLevel); });
} }
void InitMessageFieldGeometry(not_null<Ui::InputField*> field) { void InitMessageFieldGeometry(not_null<Ui::InputField*> field) {

View file

@ -44,6 +44,12 @@ Fn<bool(
not_null<Main::Session*> session, not_null<Main::Session*> session,
not_null<Ui::InputField*> field, not_null<Ui::InputField*> field,
const style::InputField *fieldStyle = nullptr); const style::InputField *fieldStyle = nullptr);
void InitMessageFieldHandlers(
not_null<Main::Session*> session,
std::shared_ptr<Ui::Show> show,
not_null<Ui::InputField*> field,
Fn<bool()> customEmojiPaused,
const style::InputField *fieldStyle = nullptr);
void InitMessageFieldHandlers( void InitMessageFieldHandlers(
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field, not_null<Ui::InputField*> field,

View file

@ -19,6 +19,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/emoji_config.h" #include "ui/emoji_config.h"
#include "ui/empty_userpic.h" #include "ui/empty_userpic.h"
#include "ui/ui_utility.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 "dialogs/ui/dialogs_layout.h"
#include "window/window_controller.h" #include "window/window_controller.h"
#include "storage/file_download.h" #include "storage/file_download.h"
@ -974,6 +976,14 @@ void Notification::showReplyField() {
_replyArea->setInstantReplacesEnabled( _replyArea->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue()); Core::App().settings().replaceEmojiValue());
_replyArea->setMarkdownReplacesEnabled(rpl::single(true)); _replyArea->setMarkdownReplacesEnabled(rpl::single(true));
const auto session = &_item->history()->session();
_replyArea->setCustomEmojiFactory([=](
QStringView data,
Fn<void()> update) {
return session->data().customEmojiManager().create(
data,
std::move(update));
});
// Catch mouse press event to activate the window. // Catch mouse press event to activate the window.
QCoreApplication::instance()->installEventFilter(this); QCoreApplication::instance()->installEventFilter(this);

@ -1 +1 @@
Subproject commit 0b829240fd3ade757aa4e957c17d84a81ef1c3ff Subproject commit 464c6a61711fa7b66d45829bde582d36e23f0b1a