diff --git a/Telegram/SourceFiles/lang/translate_mtproto_provider.cpp b/Telegram/SourceFiles/lang/translate_mtproto_provider.cpp index 1c487411df..4525425ed8 100644 --- a/Telegram/SourceFiles/lang/translate_mtproto_provider.cpp +++ b/Telegram/SourceFiles/lang/translate_mtproto_provider.cpp @@ -9,8 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_text_entities.h" #include "data/data_peer.h" +#include "data/data_session.h" #include "main/main_session.h" #include "mtproto/sender.h" +#include "spellcheck/platform/platform_language.h" namespace Ui { namespace { @@ -18,7 +20,8 @@ namespace { class MTProtoTranslateProvider final : public TranslateProvider { public: explicit MTProtoTranslateProvider(not_null session) - : _api(&session->mtp()) { + : _session(session) + , _api(&session->mtp()) { } [[nodiscard]] bool supportsMessageId() const override { @@ -29,13 +32,18 @@ public: TranslateProviderRequest request, LanguageId to, Fn done) override { + const auto msgId = MsgId(request.msgId); + const auto peerId = PeerId(PeerIdHelper(request.peerId)); + const auto peer = msgId + ? _session->data().peerLoaded(peerId) + : nullptr; using Flag = MTPmessages_TranslateText::Flag; - const auto flags = request.msgId + const auto flags = msgId ? (Flag::f_peer | Flag::f_id) : !request.text.text.isEmpty() ? Flag::f_text : Flag(0); - if (!flags) { + if (!flags || (msgId && !peer)) { done(TranslateProviderResult{ .error = TranslateProviderError::Unknown, }); @@ -43,16 +51,16 @@ public: } _api.request(MTPmessages_TranslateText( MTP_flags(flags), - request.msgId ? request.peer->input() : MTP_inputPeerEmpty(), - (request.msgId - ? MTP_vector(1, MTP_int(request.msgId)) + msgId ? peer->input() : MTP_inputPeerEmpty(), + (msgId + ? MTP_vector(1, MTP_int(msgId.bare)) : MTPVector()), - (request.msgId + (msgId ? MTPVector() : MTP_vector(1, MTP_textWithEntities( MTP_string(request.text.text), Api::EntitiesToMTP( - &request.peer->session(), + _session, request.text.entities, Api::ConvertOption::SkipLocal)))), MTP_string(to.twoLetterCode()) @@ -65,7 +73,7 @@ public: } : TranslateProviderResult{ .text = Api::ParseTextWithEntities( - &request.peer->session(), + _session, list.front()), }); }).fail([=](const MTP::Error &) { @@ -76,6 +84,7 @@ public: } private: + const not_null _session; MTP::Sender _api; }; diff --git a/Telegram/SourceFiles/lang/translate_provider.cpp b/Telegram/SourceFiles/lang/translate_provider.cpp index 454c54aad9..5f4bba6b6f 100644 --- a/Telegram/SourceFiles/lang/translate_provider.cpp +++ b/Telegram/SourceFiles/lang/translate_provider.cpp @@ -51,16 +51,16 @@ TranslateProviderRequest PrepareTranslateProviderRequest( MsgId msgId, TextWithEntities text) { auto result = TranslateProviderRequest{ - .peer = peer, - .msgId = IsServerMsgId(msgId) ? msgId : MsgId(), + .peerId = int64(peer->id.value), + .msgId = IsServerMsgId(msgId) ? msgId.bare : 0, .text = std::move(text), }; if (provider->supportsMessageId()) { return result; } if (result.msgId) { - if (const auto item = peer->owner().message(peer, result.msgId)) { - result.text = item->originalText(); + if (const auto i = peer->owner().message(peer, MsgId(result.msgId))) { + result.text = i->originalText(); } result.msgId = 0; } diff --git a/Telegram/SourceFiles/lang/translate_provider.h b/Telegram/SourceFiles/lang/translate_provider.h index 2902207656..e420c260af 100644 --- a/Telegram/SourceFiles/lang/translate_provider.h +++ b/Telegram/SourceFiles/lang/translate_provider.h @@ -9,6 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include +class PeerData; +struct MsgId; + namespace Main { class Session; } // namespace Main diff --git a/Telegram/SourceFiles/platform/mac/translate_provider_mac.mm b/Telegram/SourceFiles/platform/mac/translate_provider_mac.mm index 7e9f7f779a..f686dc7771 100644 --- a/Telegram/SourceFiles/platform/mac/translate_provider_mac.mm +++ b/Telegram/SourceFiles/platform/mac/translate_provider_mac.mm @@ -8,12 +8,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/mac/translate_provider_mac.h" #include "base/weak_ptr.h" +#include "spellcheck/platform/platform_language.h" #include "translate_provider_mac_swift_bridge.h" -#include -#include -#include - namespace Platform { namespace { diff --git a/Telegram/lib_translate b/Telegram/lib_translate index ed5bbec209..e65fc00f72 160000 --- a/Telegram/lib_translate +++ b/Telegram/lib_translate @@ -1 +1 @@ -Subproject commit ed5bbec209451bd56237783e783fdadfb3c1fdd2 +Subproject commit e65fc00f723cec2bae1927ed8d45fd7067025e3a