Support custom emoji in custom notification replies.

This commit is contained in:
John Preston 2022-07-01 21:46:04 +04:00
parent 8c8cbbbc83
commit ee8d8171f7
4 changed files with 30 additions and 27 deletions

View file

@ -301,10 +301,11 @@ void InitMessageFieldHandlers(
field->setInstantReplacesEnabled( field->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue()); Core::App().settings().replaceEmojiValue());
field->setMarkdownReplacesEnabled(rpl::single(true)); field->setMarkdownReplacesEnabled(rpl::single(true));
field->setEditLinkCallback( if (show) {
DefaultEditLinkCallback(show, session, field, fieldStyle)); field->setEditLinkCallback(
DefaultEditLinkCallback(show, session, field, fieldStyle));
InitSpellchecker(show, session, field, fieldStyle != nullptr); InitSpellchecker(show, session, field, fieldStyle != nullptr);
}
} }
void InitMessageFieldHandlers( void InitMessageFieldHandlers(

View file

@ -76,7 +76,7 @@ TextParseOptions TextNameOptions = {
}; };
TextParseOptions TextDialogOptions = { TextParseOptions TextDialogOptions = {
TextParsePlainLinks, // flags TextParsePlainLinks | TextParseMarkdown, // flags
0, // maxw is style-dependent 0, // maxw is style-dependent
1, // maxh 1, // maxh
Qt::LayoutDirectionAuto, // lang-dependent Qt::LayoutDirectionAuto, // lang-dependent

View file

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "platform/platform_specific.h" #include "platform/platform_specific.h"
#include "core/application.h" #include "core/application.h"
#include "core/ui_integration.h" #include "core/ui_integration.h"
#include "chat_helpers/message_field.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/widgets/input_fields.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) { void Notification::paintEvent(QPaintEvent *e) {
repaintText();
Painter p(this); Painter p(this);
p.setClipRect(e->rect()); p.setClipRect(e->rect());
p.drawImage(0, 0, _cache); p.drawImage(0, 0, _cache);
@ -756,16 +759,21 @@ void Notification::customEmojiCallback() {
return; return;
} }
_textRepaintScheduled = true; _textRepaintScheduled = true;
InvokeQueued(this, [=] { crl::on_main(this, [=] { repaintText(); });
_textRepaintScheduled = false; }
if (_cache.isNull()) {
return; void Notification::repaintText() {
} if (!_textRepaintScheduled) {
Painter p(&_cache); return;
p.fillRect(_textRect, st::notificationBg); }
paintText(p); _textRepaintScheduled = false;
update(); if (_cache.isNull()) {
}); return;
}
Painter p(&_cache);
p.fillRect(_textRect, st::notificationBg);
paintText(p);
update();
} }
void Notification::paintText(Painter &p) { void Notification::paintText(Painter &p) {
@ -1013,18 +1021,11 @@ void Notification::showReplyField() {
_replyArea->setFocus(); _replyArea->setFocus();
_replyArea->setMaxLength(MaxMessageSize); _replyArea->setMaxLength(MaxMessageSize);
_replyArea->setSubmitSettings(Ui::InputField::SubmitSettings::Both); _replyArea->setSubmitSettings(Ui::InputField::SubmitSettings::Both);
_replyArea->setInstantReplaces(Ui::InstantReplaces::Default()); InitMessageFieldHandlers(
_replyArea->setInstantReplacesEnabled( &_item->history()->session(),
Core::App().settings().replaceEmojiValue()); nullptr,
_replyArea->setMarkdownReplacesEnabled(rpl::single(true)); _replyArea.data(),
const auto session = &_item->history()->session(); nullptr);
_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);

View file

@ -261,6 +261,7 @@ private:
void changeHeight(int newHeight); void changeHeight(int newHeight);
void updateGeometry(int x, int y, int width, int height) override; void updateGeometry(int x, int y, int width, int height) override;
void actionsOpacityCallback(); void actionsOpacityCallback();
void repaintText();
void paintText(Painter &p); void paintText(Painter &p);
void customEmojiCallback(); void customEmojiCallback();