From 95830077690adbf8c5f5518467420926cf713be9 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 24 Apr 2025 14:36:31 +0400 Subject: [PATCH] Apply auto-translation from French? for test. --- Telegram/SourceFiles/data/data_peer.cpp | 7 +++++++ Telegram/SourceFiles/data/data_peer.h | 1 + .../SourceFiles/history/history_widget.cpp | 4 ++++ .../view/history_view_translate_bar.cpp | 1 + .../view/history_view_translate_tracker.cpp | 20 ++++++++++++++++--- 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index 592fc1edfb..c2c614577c 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -734,6 +734,13 @@ bool PeerData::canExportChatHistory() const { return false; } +bool PeerData::autoTranslation() const { + if (const auto channel = asChannel()) { + return channel->autoTranslation(); + } + return false; +} + bool PeerData::setAbout(const QString &newAbout) { if (_about == newAbout) { return false; diff --git a/Telegram/SourceFiles/data/data_peer.h b/Telegram/SourceFiles/data/data_peer.h index c3f48eb1b6..b0563c42d5 100644 --- a/Telegram/SourceFiles/data/data_peer.h +++ b/Telegram/SourceFiles/data/data_peer.h @@ -396,6 +396,7 @@ public: [[nodiscard]] bool canManageGifts() const; [[nodiscard]] bool canTransferGifts() const; [[nodiscard]] bool canExportChatHistory() const; + [[nodiscard]] bool autoTranslation() const; // Returns true if about text was changed. bool setAbout(const QString &newAbout); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 4d34fd0b86..cef6365d4c 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -7557,6 +7557,10 @@ void HistoryWidget::checkLastPinnedClickedIdReset( void HistoryWidget::setupTranslateBar() { Expects(_history != nullptr); + if (_history->peer->autoTranslation()) { + _history->translateTo(Core::App().settings().translateTo()); + } + _translateBar = std::make_unique( this, controller(), diff --git a/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp b/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp index 88db9ee2d6..c658692d33 100644 --- a/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp +++ b/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp @@ -372,6 +372,7 @@ void TranslateBar::setup(not_null history) { const auto&, const auto&) { using Flag = PeerData::TranslationFlag; + //const auto autotranslation = history->peer->autoTranslation(); return (history->peer->translationFlag() != Flag::Enabled) ? rpl::single(QString()) : history->translatedTo() diff --git a/Telegram/SourceFiles/history/view/history_view_translate_tracker.cpp b/Telegram/SourceFiles/history/view/history_view_translate_tracker.cpp index cc7652f62e..df45d6ca75 100644 --- a/Telegram/SourceFiles/history/view/history_view_translate_tracker.cpp +++ b/Telegram/SourceFiles/history/view/history_view_translate_tracker.cpp @@ -12,6 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "core/core_settings.h" #include "data/data_changes.h" +#include "data/data_channel.h" +#include "data/data_flags.h" #include "data/data_peer_values.h" // Data::AmPremiumValue. #include "data/data_session.h" #include "history/history.h" @@ -57,10 +59,22 @@ void TranslateTracker::setup() { Core::App().settings().translateChatEnabledValue(), _1 && _2); - _trackingLanguage.value( - ) | rpl::start_with_next([=](bool tracking) { + const auto channel = peer->asChannel(); + auto autoTranslationValue = (channel + ? channel->flagsValue() + : rpl::single(Data::Flags::Change({}, {})) + ) | rpl::map([=](Data::Flags::Change data) { + return (data.value & ChannelDataFlag::AutoTranslation); + }) | rpl::distinct_until_changed(); + rpl::combine( + _trackingLanguage.value(), + std::move(autoTranslationValue) + ) | rpl::start_with_next([=](bool tracking, bool autotranslation) { _trackingLifetime.destroy(); - if (tracking) { + if (autotranslation) { + _history->translateOfferFrom({ QLocale::French }); + AssertIsDebug(); + } else if (tracking) { recognizeCollected(); trackSkipLanguages(); } else {