Add the ability to send messages with protected content.

This commit is contained in:
levlam 2021-12-30 14:41:30 +03:00
parent 8e637b482a
commit 6ec2104b81
2 changed files with 21 additions and 14 deletions

View File

@ -5249,8 +5249,9 @@ td::Result<td_api::object_ptr<td_api::InputMessageContent>> Client::get_input_me
return nullptr;
}
td_api::object_ptr<td_api::messageSendOptions> Client::get_message_send_options(bool disable_notification) {
return make_object<td_api::messageSendOptions>(disable_notification, false, false, nullptr);
td_api::object_ptr<td_api::messageSendOptions> Client::get_message_send_options(bool disable_notification,
bool protect_content) {
return make_object<td_api::messageSendOptions>(disable_notification, false, protect_content, nullptr);
}
td::Result<td::vector<td_api::object_ptr<td_api::InputInlineQueryResult>>> Client::get_inline_query_results(
@ -6846,6 +6847,7 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) {
auto reply_to_message_id = get_message_id(query.get(), "reply_to_message_id");
auto allow_sending_without_reply = to_bool(query->arg("allow_sending_without_reply"));
auto disable_notification = to_bool(query->arg("disable_notification"));
auto protect_content = to_bool(query->arg("protect_content"));
// TRY_RESULT(reply_markup, get_reply_markup(query.get()));
auto reply_markup = nullptr;
TRY_RESULT(input_message_contents, get_input_message_contents(query.get(), "media"));
@ -6853,9 +6855,10 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) {
resolve_reply_markup_bot_usernames(
std::move(reply_markup), std::move(query),
[this, chat_id = chat_id.str(), reply_to_message_id, allow_sending_without_reply, disable_notification,
input_message_contents = std::move(input_message_contents)](object_ptr<td_api::ReplyMarkup> reply_markup,
PromisedQueryPtr query) mutable {
auto on_success = [this, disable_notification, input_message_contents = std::move(input_message_contents),
protect_content, input_message_contents = std::move(input_message_contents)](
object_ptr<td_api::ReplyMarkup> reply_markup, PromisedQueryPtr query) mutable {
auto on_success = [this, disable_notification, protect_content,
input_message_contents = std::move(input_message_contents),
reply_markup = std::move(reply_markup)](int64 chat_id, int64 reply_to_message_id,
PromisedQueryPtr query) mutable {
auto it = yet_unsent_message_count_.find(chat_id);
@ -6863,10 +6866,11 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) {
return query->set_retry_after_error(60);
}
send_request(make_object<td_api::sendMessageAlbum>(chat_id, 0, reply_to_message_id,
get_message_send_options(disable_notification),
std::move(input_message_contents)),
std::make_unique<TdOnSendMessageAlbumCallback>(this, std::move(query)));
send_request(
make_object<td_api::sendMessageAlbum>(chat_id, 0, reply_to_message_id,
get_message_send_options(disable_notification, protect_content),
std::move(input_message_contents)),
std::make_unique<TdOnSendMessageAlbumCallback>(this, std::move(query)));
};
check_message(chat_id, reply_to_message_id, reply_to_message_id <= 0 || allow_sending_without_reply,
AccessRights::Write, "replied message", std::move(query), std::move(on_success));
@ -8184,6 +8188,7 @@ void Client::do_send_message(object_ptr<td_api::InputMessageContent> input_messa
auto reply_to_message_id = get_message_id(query.get(), "reply_to_message_id");
auto allow_sending_without_reply = to_bool(query->arg("allow_sending_without_reply"));
auto disable_notification = to_bool(query->arg("disable_notification"));
auto protect_content = to_bool(query->arg("protect_content"));
auto r_reply_markup = get_reply_markup(query.get());
if (r_reply_markup.is_error()) {
return fail_query_with_error(std::move(query), 400, r_reply_markup.error().message());
@ -8193,9 +8198,10 @@ void Client::do_send_message(object_ptr<td_api::InputMessageContent> input_messa
resolve_reply_markup_bot_usernames(
std::move(reply_markup), std::move(query),
[this, chat_id = chat_id.str(), reply_to_message_id, allow_sending_without_reply, disable_notification,
input_message_content = std::move(input_message_content)](object_ptr<td_api::ReplyMarkup> reply_markup,
PromisedQueryPtr query) mutable {
auto on_success = [this, disable_notification, input_message_content = std::move(input_message_content),
protect_content, input_message_content = std::move(input_message_content)](
object_ptr<td_api::ReplyMarkup> reply_markup, PromisedQueryPtr query) mutable {
auto on_success = [this, disable_notification, protect_content,
input_message_content = std::move(input_message_content),
reply_markup = std::move(reply_markup)](int64 chat_id, int64 reply_to_message_id,
PromisedQueryPtr query) mutable {
auto it = yet_unsent_message_count_.find(chat_id);
@ -8204,7 +8210,7 @@ void Client::do_send_message(object_ptr<td_api::InputMessageContent> input_messa
}
send_request(make_object<td_api::sendMessage>(chat_id, 0, reply_to_message_id,
get_message_send_options(disable_notification),
get_message_send_options(disable_notification, protect_content),
std::move(reply_markup), std::move(input_message_content)),
std::make_unique<TdOnSendMessageCallback>(this, std::move(query)));
};

View File

@ -412,7 +412,8 @@ class Client : public WebhookActor::Callback {
td::Result<td::vector<object_ptr<td_api::InputMessageContent>>> get_input_message_contents(
const Query *query, td::JsonValue &&value) const;
static object_ptr<td_api::messageSendOptions> get_message_send_options(bool disable_notification);
static object_ptr<td_api::messageSendOptions> get_message_send_options(bool disable_notification,
bool protect_content);
static td::Result<td::vector<td::string>> get_poll_options(const Query *query);