2018-09-28 22:57:34 +02:00
|
|
|
//
|
2021-01-01 13:57:46 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
2018-09-28 22:57:34 +02:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#include "td/telegram/InputMessageText.h"
|
|
|
|
|
2020-03-12 18:20:59 +01:00
|
|
|
#include "td/telegram/ConfigShared.h"
|
|
|
|
#include "td/telegram/Global.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/MessageEntity.h"
|
|
|
|
|
2019-02-12 21:48:16 +01:00
|
|
|
#include "td/utils/common.h"
|
2018-09-29 01:45:43 +02:00
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
namespace td {
|
|
|
|
|
|
|
|
bool operator==(const InputMessageText &lhs, const InputMessageText &rhs) {
|
|
|
|
return lhs.text == rhs.text && lhs.disable_web_page_preview == rhs.disable_web_page_preview &&
|
|
|
|
lhs.clear_draft == rhs.clear_draft;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const InputMessageText &lhs, const InputMessageText &rhs) {
|
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<InputMessageText> process_input_message_text(const ContactsManager *contacts_manager, DialogId dialog_id,
|
|
|
|
tl_object_ptr<td_api::InputMessageContent> &&input_message_content,
|
|
|
|
bool is_bot, bool for_draft) {
|
|
|
|
CHECK(input_message_content != nullptr);
|
|
|
|
CHECK(input_message_content->get_id() == td_api::inputMessageText::ID);
|
|
|
|
auto input_message_text = static_cast<td_api::inputMessageText *>(input_message_content.get());
|
|
|
|
if (input_message_text->text_ == nullptr) {
|
|
|
|
if (for_draft) {
|
|
|
|
return InputMessageText{FormattedText(), input_message_text->disable_web_page_preview_,
|
|
|
|
input_message_text->clear_draft_};
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status::Error(400, "Message text can't be empty");
|
|
|
|
}
|
|
|
|
|
|
|
|
TRY_RESULT(entities, get_message_entities(contacts_manager, std::move(input_message_text->text_->entities_)));
|
2021-07-26 21:48:33 +02:00
|
|
|
auto need_skip_bot_commands = need_always_skip_bot_commands(contacts_manager, dialog_id, is_bot);
|
2020-03-12 18:20:59 +01:00
|
|
|
bool parse_markdown = G()->shared_config().get_option_boolean("always_parse_markdown");
|
|
|
|
TRY_STATUS(fix_formatted_text(input_message_text->text_->text_, entities, for_draft, parse_markdown,
|
2021-07-26 21:48:33 +02:00
|
|
|
need_skip_bot_commands, is_bot || for_draft || parse_markdown, for_draft));
|
2020-03-12 18:20:59 +01:00
|
|
|
InputMessageText result{FormattedText{std::move(input_message_text->text_->text_), std::move(entities)},
|
2018-09-28 22:57:34 +02:00
|
|
|
input_message_text->disable_web_page_preview_, input_message_text->clear_draft_};
|
2021-07-26 21:48:33 +02:00
|
|
|
if (parse_markdown) {
|
2020-03-12 18:20:59 +01:00
|
|
|
result.text = parse_markdown_v3(std::move(result.text));
|
2021-07-26 21:48:33 +02:00
|
|
|
fix_formatted_text(result.text.text, result.text.entities, for_draft, false, need_skip_bot_commands,
|
|
|
|
is_bot || for_draft, for_draft)
|
2020-03-12 18:20:59 +01:00
|
|
|
.ensure();
|
|
|
|
}
|
|
|
|
return std::move(result);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
td_api::object_ptr<td_api::inputMessageText> get_input_message_text_object(const InputMessageText &input_message_text) {
|
2021-07-22 04:39:16 +02:00
|
|
|
return td_api::make_object<td_api::inputMessageText>(get_formatted_text_object(input_message_text.text, false),
|
2018-09-28 22:57:34 +02:00
|
|
|
input_message_text.disable_web_page_preview,
|
|
|
|
input_message_text.clear_draft);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|