Improve handling of too long messages and captions.
This commit is contained in:
parent
579d1dee8d
commit
d8c36c8062
@ -1818,6 +1818,11 @@ static Result<InputMessageContent> create_input_message_content(
|
||||
disable_web_page_preview = input_message_text.disable_web_page_preview;
|
||||
clear_draft = input_message_text.clear_draft;
|
||||
|
||||
if (is_bot && static_cast<int64>(utf8_length(input_message_text.text.text)) >
|
||||
G()->get_option_integer("message_text_length_max")) {
|
||||
return Status::Error(400, "Message is too long");
|
||||
}
|
||||
|
||||
WebPageId web_page_id;
|
||||
bool can_add_web_page_previews =
|
||||
dialog_id.get_type() != DialogType::Channel ||
|
||||
@ -2210,8 +2215,12 @@ Result<InputMessageContent> get_input_message_content(
|
||||
}
|
||||
}
|
||||
|
||||
TRY_RESULT(caption, get_formatted_text(td, dialog_id, extract_input_caption(input_message_content),
|
||||
td->auth_manager_->is_bot(), true, false, false));
|
||||
bool is_bot = td->auth_manager_->is_bot();
|
||||
TRY_RESULT(caption, get_formatted_text(td, dialog_id, extract_input_caption(input_message_content), is_bot, true,
|
||||
false, false));
|
||||
if (is_bot && static_cast<int64>(utf8_length(caption.text)) > G()->get_option_integer("message_caption_length_max")) {
|
||||
return Status::Error(400, "Message caption is too long");
|
||||
}
|
||||
return create_input_message_content(dialog_id, std::move(input_message_content), td, std::move(caption), file_id,
|
||||
std::move(thumbnail), std::move(sticker_file_ids), is_premium);
|
||||
}
|
||||
|
@ -4242,8 +4242,6 @@ Status fix_formatted_text(string &text, vector<MessageEntity> &entities, bool al
|
||||
// new whitespace-only entities could be added after splitting of entities
|
||||
remove_invalid_entities(text, entities);
|
||||
|
||||
// TODO MAX_MESSAGE_LENGTH and MAX_CAPTION_LENGTH
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
|
@ -32257,7 +32257,8 @@ void MessagesManager::on_send_message_fail(int64 random_id, Status error) {
|
||||
case 400:
|
||||
if (error.message() == "MESSAGE_TOO_LONG") {
|
||||
error_message = "Message is too long";
|
||||
// TODO move check to send_message
|
||||
} else if (error.message() == "MEDIA_CAPTION_TOO_LONG") {
|
||||
error_message = "Message caption is too long";
|
||||
} else if (error.message() == "INPUT_USER_DEACTIVATED") {
|
||||
error_code = 403;
|
||||
error_message = "User is deactivated";
|
||||
|
Loading…
Reference in New Issue
Block a user