From 19e43cfd1dfc53b9aec640d7b37e637d6ea689f8 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 30 Jan 2023 18:47:03 +0400 Subject: [PATCH] Show "Translate" in three-dot if bar was hidden. --- .../view/history_view_translate_bar.cpp | 24 +++++++++++++------ .../SourceFiles/window/window_peer_menu.cpp | 19 +++++++++++++++ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp b/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp index 9741443cc..f11e389fe 100644 --- a/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp +++ b/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp @@ -83,20 +83,30 @@ void TranslateBar::setup(not_null history) { _wrap.geometryValue( ) | rpl::start_with_next([=](QRect rect) { updateShadowGeometry(rect); - updateControlsGeometry(rect); + updateControlsGeometry(rect); }, _wrap.lifetime()); const auto button = static_cast(_wrap.entity()); - button->setClickedCallback([=] { - const auto to = history->translatedTo() - ? LanguageId() - : Core::App().settings().translateTo(); - history->translateTo(to); + const auto translateTo = [=](LanguageId id) { + history->translateTo(id); if (const auto migrated = history->migrateFrom()) { - migrated->translateTo(to); + migrated->translateTo(id); } + }; + button->setClickedCallback([=] { + translateTo(history->translatedTo() + ? LanguageId() + : Core::App().settings().translateTo()); }); + Core::App().settings().translateToValue( + ) | rpl::filter([=](LanguageId should) { + const auto now = history->translatedTo(); + return now && (now != should); + }) | rpl::start_with_next([=](LanguageId should) { + translateTo(should); + }, _wrap.lifetime()); + const auto label = Ui::CreateChild( button, st::historyTranslateLabel); diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 9e715296c..56ad3f55d 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -270,6 +270,7 @@ private: void addViewDiscussion(); void addToggleTopicClosed(); void addExportChat(); + void addTranslate(); void addReport(); void addNewContact(); void addShareContact(); @@ -776,6 +777,23 @@ void Filler::addExportChat() { &st::menuIconExport); } +void Filler::addTranslate() { + if (_peer->translationFlag() != PeerData::TranslationFlag::Disabled + || !_peer->session().premium() + || !Core::App().settings().translateChatEnabled()) { + return; + } + const auto history = _peer->owner().historyLoaded(_peer); + if (!history + || !history->translateOfferedFrom() + || history->translatedTo()) { + return; + } + _addAction(tr::lng_context_translate(tr::now), [=] { + history->peer->saveTranslationDisabled(false); + }, &st::menuIconTranslate); +} + void Filler::addReport() { const auto chat = _peer->asChat(); const auto channel = _peer->asChannel(); @@ -1174,6 +1192,7 @@ void Filler::fillHistoryActions() { addThemeEdit(); addViewDiscussion(); addExportChat(); + addTranslate(); addReport(); addClearHistory(); addDeleteChat();