Replace translateMessage with translateText.

This commit is contained in:
levlam 2022-01-29 23:43:57 +03:00
parent e1bd34cda8
commit 3739c5b92f
6 changed files with 18 additions and 36 deletions

View File

@ -4462,12 +4462,11 @@ getMessageEmbeddingCode chat_id:int53 message_id:int53 for_album:Bool = Text;
getMessageLinkInfo url:string = MessageLinkInfo;
//@description Translates a message text or caption to the given language. Returns a 404 error if the translation can't be performed
//@chat_id Identifier of the chat to which the message belongs
//@message_id Identifier of the message
//@description Translates a text to the given language. Returns a 404 error if the translation can't be performed
//@text Text to translate
//@from_language_code A two-letter ISO 639-1 language code of the language from which the message is translated. If empty, the language will be detected automatically
//@to_language_code A two-letter ISO 639-1 language code of the language to which the message is translated
translateMessage chat_id:int53 message_id:int53 from_language_code:string to_language_code:string = Text;
translateText text:string from_language_code:string to_language_code:string = Text;
//@description Returns list of message sender identifiers, which can be used to send messages in a chat @chat_id Chat identifier

View File

@ -18049,26 +18049,10 @@ void MessagesManager::on_get_message_viewers(DialogId dialog_id, vector<UserId>
promise.set_value(td_->contacts_manager_->get_users_object(-1, user_ids));
}
void MessagesManager::translate_message(FullMessageId full_message_id, const string &from_language_code,
const string &to_language_code,
Promise<td_api::object_ptr<td_api::text>> &&promise) {
auto dialog_id = full_message_id.get_dialog_id();
Dialog *d = get_dialog_force(dialog_id, "translate_message");
if (d == nullptr) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
auto m = get_message_force(d, full_message_id.get_message_id(), "translate_message");
if (m == nullptr) {
return promise.set_error(Status::Error(400, "Message not found"));
}
const FormattedText *text = get_message_content_text(m->content.get());
if (text == nullptr) {
return promise.set_error(Status::Error(400, "Message have no text"));
}
td_->create_handler<TranslateTextQuery>(std::move(promise))->send(text->text, from_language_code, to_language_code);
void MessagesManager::translate_text(const string &text, const string &from_language_code,
const string &to_language_code,
Promise<td_api::object_ptr<td_api::text>> &&promise) {
td_->create_handler<TranslateTextQuery>(std::move(promise))->send(text, from_language_code, to_language_code);
}
void MessagesManager::get_dialog_info_full(DialogId dialog_id, Promise<Unit> &&promise, const char *source) {

View File

@ -609,8 +609,8 @@ class MessagesManager final : public Actor {
void get_message_viewers(FullMessageId full_message_id, Promise<td_api::object_ptr<td_api::users>> &&promise);
void translate_message(FullMessageId full_message_id, const string &from_language_code,
const string &to_language_code, Promise<td_api::object_ptr<td_api::text>> &&promise);
void translate_text(const string &text, const string &from_language_code, const string &to_language_code,
Promise<td_api::object_ptr<td_api::text>> &&promise);
bool is_message_edited_recently(FullMessageId full_message_id, int32 seconds);

View File

@ -4741,13 +4741,14 @@ void Td::on_request(uint64 id, td_api::getMessageLinkInfo &request) {
CREATE_REQUEST(GetMessageLinkInfoRequest, std::move(request.url_));
}
void Td::on_request(uint64 id, td_api::translateMessage &request) {
void Td::on_request(uint64 id, td_api::translateText &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.text_);
CLEAN_INPUT_STRING(request.from_language_code_);
CLEAN_INPUT_STRING(request.to_language_code_);
CREATE_REQUEST_PROMISE();
messages_manager_->translate_message({DialogId(request.chat_id_), MessageId(request.message_id_)},
request.from_language_code_, request.to_language_code_, std::move(promise));
messages_manager_->translate_text(request.text_, request.from_language_code_, request.to_language_code_,
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getFile &request) {

View File

@ -533,7 +533,7 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::getMessageLinkInfo &request);
void on_request(uint64 id, td_api::translateMessage &request);
void on_request(uint64 id, td_api::translateText &request);
void on_request(uint64 id, const td_api::getFile &request);

View File

@ -2777,14 +2777,12 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::getMessageEmbeddingCode>(chat_id, message_id, for_album));
} else if (op == "gmli") {
send_request(td_api::make_object<td_api::getMessageLinkInfo>(args));
} else if (op == "tm") {
ChatId chat_id;
MessageId message_id;
} else if (op == "tt") {
string text;
string from_language_code;
string to_language_code;
get_args(args, chat_id, message_id, from_language_code, to_language_code);
send_request(
td_api::make_object<td_api::translateMessage>(chat_id, message_id, from_language_code, to_language_code));
get_args(args, text, from_language_code, to_language_code);
send_request(td_api::make_object<td_api::translateText>(text, from_language_code, to_language_code));
} else if (op == "gf" || op == "GetFile") {
send_request(td_api::make_object<td_api::getFile>(as_file_id(args)));
} else if (op == "gfdps") {