diff --git a/Telegram/SourceFiles/boxes/translate_box.cpp b/Telegram/SourceFiles/boxes/translate_box.cpp index edca9a8ff..de64a704e 100644 --- a/Telegram/SourceFiles/boxes/translate_box.cpp +++ b/Telegram/SourceFiles/boxes/translate_box.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "boxes/translate_box.h" +#include "api/api_text_entities.h" // Api::EntitiesToMTP / EntitiesFromMTP. #include "core/application.h" #include "core/core_settings.h" #include "core/ui_integration.h" @@ -22,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/boxes/choose_language_box.h" #include "ui/effects/loading_element.h" #include "ui/layers/generic_box.h" +#include "ui/text/text_utilities.h" #include "ui/toasts/common_toasts.h" #include "ui/painter.h" #include "ui/widgets/buttons.h" @@ -111,12 +113,6 @@ void TranslateBox( const auto state = box->lifetime().make_state(&peer->session()); state->to = ChooseTranslateTo(peer->owner().history(peer)); - text.entities = ranges::views::all( - text.entities - ) | ranges::views::filter([](const EntityInText &e) { - return e.type() != EntityType::Spoiler; - }) | ranges::to(); - if (!IsServerMsgId(msgId)) { msgId = 0; } @@ -212,8 +208,14 @@ void TranslateBox( return id.locale().textDirection() == Qt::RightToLeft; })))); - const auto showText = [=](const QString &text) { - translated->entity()->setText(text); + const auto showText = [=](TextWithEntities text) { + const auto label = translated->entity(); + label->setMarkedText( + text, + Core::MarkedTextContext{ + .session = &peer->session(), + .customEmojiRepaint = [=] { label->update(); }, + }); translated->show(anim::type::instant); loading->hide(anim::type::instant); }; @@ -231,16 +233,28 @@ void TranslateBox( ? MTPVector() : MTP_vector(1, MTP_textWithEntities( MTP_string(text.text), - MTP_vector()))), + Api::EntitiesToMTP( + &peer->session(), + text.entities, + Api::ConvertOption::SkipLocal)))), MTP_string(to.twoLetterCode()) )).done([=](const MTPmessages_TranslatedText &result) { const auto &data = result.data(); const auto &list = data.vresult().v; - showText(list.isEmpty() - ? tr::lng_translate_box_error(tr::now) - : qs(list.front().data().vtext())); + if (list.isEmpty()) { + showText( + Ui::Text::Italic(tr::lng_translate_box_error(tr::now))); + } else { + showText(TextWithEntities{ + .text = qs(list.front().data().vtext()), + .entities = Api::EntitiesFromMTP( + &peer->session(), + list.front().data().ventities().v), + }); + } }).fail([=](const MTP::Error &error) { - showText(tr::lng_translate_box_error(tr::now)); + showText( + Ui::Text::Italic(tr::lng_translate_box_error(tr::now))); }).send(); }; state->to.value() | rpl::start_with_next(send, box->lifetime()); diff --git a/Telegram/lib_ui b/Telegram/lib_ui index e053e0460..1b9b17396 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit e053e04607653c8a304c72ff901a8e628dd94dbf +Subproject commit 1b9b1739649ddf942937a6b9a1a22933070e5ecc