Merge remote-tracking branch 'td/master'

This commit is contained in:
Andrea Cavalli 2022-03-24 21:15:45 +01:00
commit d152847309
4 changed files with 447 additions and 428 deletions

View File

@ -364,10 +364,9 @@ UserId InlineQueriesManager::get_inline_bot_user_id(int64 query_id) const {
return it->second; return it->second;
} }
void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_personal, void InlineQueriesManager::answer_inline_query(
vector<tl_object_ptr<td_api::InputInlineQueryResult>> &&input_results, int64 inline_query_id, bool is_personal, vector<td_api::object_ptr<td_api::InputInlineQueryResult>> &&input_results,
int32 cache_time, const string &next_offset, int32 cache_time, const string &next_offset, const string &switch_pm_text, const string &switch_pm_parameter,
const string &switch_pm_text, const string &switch_pm_parameter,
Promise<Unit> &&promise) const { Promise<Unit> &&promise) const {
if (!td_->auth_manager_->is_bot()) { if (!td_->auth_manager_->is_bot()) {
return promise.set_error(Status::Error(400, "Method can be used by bots only")); return promise.set_error(Status::Error(400, "Method can be used by bots only"));
@ -390,8 +389,20 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
bool is_gallery = false; bool is_gallery = false;
bool force_vertical = false; bool force_vertical = false;
for (auto &input_result : input_results) { for (auto &input_result : input_results) {
if (input_result == nullptr) { TRY_RESULT_PROMISE(promise, result,
return promise.set_error(Status::Error(400, "Inline query result must be non-empty")); get_input_bot_inline_result(std::move(input_result), &is_gallery, &force_vertical));
results.push_back(std::move(result));
}
td_->create_handler<SetInlineBotResultsQuery>(std::move(promise))
->send(inline_query_id, is_gallery && !force_vertical, is_personal, std::move(results), cache_time, next_offset,
switch_pm_text, switch_pm_parameter);
}
Result<tl_object_ptr<telegram_api::InputBotInlineResult>> InlineQueriesManager::get_input_bot_inline_result(
td_api::object_ptr<td_api::InputInlineQueryResult> &&result, bool *is_gallery, bool *force_vertical) const {
if (result == nullptr) {
return Status::Error(400, "Inline query result must be non-empty");
} }
string id; string id;
@ -411,9 +422,9 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
FileType file_type = FileType::Temp; FileType file_type = FileType::Temp;
Result<tl_object_ptr<telegram_api::InputBotInlineMessage>> r_inline_message = Status::Error(500, "Uninited"); Result<tl_object_ptr<telegram_api::InputBotInlineMessage>> r_inline_message = Status::Error(500, "Uninited");
switch (input_result->get_id()) { switch (result->get_id()) {
case td_api::inputInlineQueryResultAnimation::ID: { case td_api::inputInlineQueryResultAnimation::ID: {
auto animation = move_tl_object_as<td_api::inputInlineQueryResultAnimation>(input_result); auto animation = move_tl_object_as<td_api::inputInlineQueryResultAnimation>(result);
type = "gif"; type = "gif";
id = std::move(animation->id_); id = std::move(animation->id_);
title = std::move(animation->title_); title = std::move(animation->title_);
@ -424,12 +435,14 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
content_url = std::move(animation->video_url_); content_url = std::move(animation->video_url_);
content_type = std::move(animation->video_mime_type_); content_type = std::move(animation->video_mime_type_);
if (content_type != "image/gif" && content_type != "video/mp4") { if (content_type != "image/gif" && content_type != "video/mp4") {
return promise.set_error(Status::Error(400, "Wrong animation MIME type specified")); return Status::Error(400, "Wrong animation MIME type specified");
} }
duration = animation->video_duration_; duration = animation->video_duration_;
width = animation->video_width_; width = animation->video_width_;
height = animation->video_height_; height = animation->video_height_;
is_gallery = true; if (is_gallery != nullptr) {
*is_gallery = true;
}
file_type = FileType::Animation; file_type = FileType::Animation;
r_inline_message = get_inline_message(std::move(animation->input_message_content_), r_inline_message = get_inline_message(std::move(animation->input_message_content_),
@ -437,7 +450,7 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
break; break;
} }
case td_api::inputInlineQueryResultArticle::ID: { case td_api::inputInlineQueryResultArticle::ID: {
auto article = move_tl_object_as<td_api::inputInlineQueryResultArticle>(input_result); auto article = move_tl_object_as<td_api::inputInlineQueryResultArticle>(result);
type = "article"; type = "article";
id = std::move(article->id_); id = std::move(article->id_);
if (!article->url_.empty()) { if (!article->url_.empty()) {
@ -454,14 +467,16 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
thumbnail_width = article->thumbnail_width_; thumbnail_width = article->thumbnail_width_;
thumbnail_height = article->thumbnail_height_; thumbnail_height = article->thumbnail_height_;
} }
force_vertical = true; if (force_vertical != nullptr) {
*force_vertical = true;
}
r_inline_message = r_inline_message =
get_inline_message(std::move(article->input_message_content_), std::move(article->reply_markup_), -1); get_inline_message(std::move(article->input_message_content_), std::move(article->reply_markup_), -1);
break; break;
} }
case td_api::inputInlineQueryResultAudio::ID: { case td_api::inputInlineQueryResultAudio::ID: {
auto audio = move_tl_object_as<td_api::inputInlineQueryResultAudio>(input_result); auto audio = move_tl_object_as<td_api::inputInlineQueryResultAudio>(result);
type = "audio"; type = "audio";
id = std::move(audio->id_); id = std::move(audio->id_);
title = std::move(audio->title_); title = std::move(audio->title_);
@ -469,7 +484,9 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
content_url = std::move(audio->audio_url_); content_url = std::move(audio->audio_url_);
content_type = "audio/mpeg"; content_type = "audio/mpeg";
duration = audio->audio_duration_; duration = audio->audio_duration_;
force_vertical = true; if (force_vertical != nullptr) {
*force_vertical = true;
}
file_type = FileType::Audio; file_type = FileType::Audio;
r_inline_message = get_inline_message(std::move(audio->input_message_content_), std::move(audio->reply_markup_), r_inline_message = get_inline_message(std::move(audio->input_message_content_), std::move(audio->reply_markup_),
@ -477,9 +494,9 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
break; break;
} }
case td_api::inputInlineQueryResultContact::ID: { case td_api::inputInlineQueryResultContact::ID: {
auto contact = move_tl_object_as<td_api::inputInlineQueryResultContact>(input_result); auto contact = move_tl_object_as<td_api::inputInlineQueryResultContact>(result);
if (contact->contact_ == nullptr) { if (contact->contact_ == nullptr) {
return promise.set_error(Status::Error(400, "Contact must be non-empty")); return Status::Error(400, "Contact must be non-empty");
} }
type = "contact"; type = "contact";
id = std::move(contact->id_); id = std::move(contact->id_);
@ -487,10 +504,10 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
string first_name = trim(contact->contact_->first_name_); string first_name = trim(contact->contact_->first_name_);
string last_name = trim(contact->contact_->last_name_); string last_name = trim(contact->contact_->last_name_);
if (phone_number.empty()) { if (phone_number.empty()) {
return promise.set_error(Status::Error(400, "Field \"phone_number\" must contain a valid phone number")); return Status::Error(400, "Field \"phone_number\" must contain a valid phone number");
} }
if (first_name.empty()) { if (first_name.empty()) {
return promise.set_error(Status::Error(400, "Field \"first_name\" must be non-empty")); return Status::Error(400, "Field \"first_name\" must be non-empty");
} }
if (last_name.empty()) { if (last_name.empty()) {
title = std::move(first_name); title = std::move(first_name);
@ -503,14 +520,16 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
thumbnail_width = contact->thumbnail_width_; thumbnail_width = contact->thumbnail_width_;
thumbnail_height = contact->thumbnail_height_; thumbnail_height = contact->thumbnail_height_;
} }
force_vertical = true; if (force_vertical != nullptr) {
*force_vertical = true;
}
r_inline_message = r_inline_message =
get_inline_message(std::move(contact->input_message_content_), std::move(contact->reply_markup_), -1); get_inline_message(std::move(contact->input_message_content_), std::move(contact->reply_markup_), -1);
break; break;
} }
case td_api::inputInlineQueryResultDocument::ID: { case td_api::inputInlineQueryResultDocument::ID: {
auto document = move_tl_object_as<td_api::inputInlineQueryResultDocument>(input_result); auto document = move_tl_object_as<td_api::inputInlineQueryResultDocument>(result);
type = "file"; type = "file";
id = std::move(document->id_); id = std::move(document->id_);
title = std::move(document->title_); title = std::move(document->title_);
@ -527,7 +546,7 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
} else if (begins_with(content_type, "application/zip")) { } else if (begins_with(content_type, "application/zip")) {
content_type = "application/zip"; content_type = "application/zip";
} else { } else {
return promise.set_error(Status::Error(400, "Unallowed document MIME type")); return Status::Error(400, "Unallowed document MIME type");
} }
} }
@ -537,10 +556,10 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
break; break;
} }
case td_api::inputInlineQueryResultGame::ID: { case td_api::inputInlineQueryResultGame::ID: {
auto game = move_tl_object_as<td_api::inputInlineQueryResultGame>(input_result); auto game = move_tl_object_as<td_api::inputInlineQueryResultGame>(result);
auto r_reply_markup = get_reply_markup(std::move(game->reply_markup_), true, true, false, true); auto r_reply_markup = get_reply_markup(std::move(game->reply_markup_), true, true, false, true);
if (r_reply_markup.is_error()) { if (r_reply_markup.is_error()) {
return promise.set_error(r_reply_markup.move_as_error()); return r_reply_markup.move_as_error();
} }
auto input_reply_markup = get_input_reply_markup(r_reply_markup.ok()); auto input_reply_markup = get_input_reply_markup(r_reply_markup.ok());
@ -548,16 +567,14 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
if (input_reply_markup != nullptr) { if (input_reply_markup != nullptr) {
flags |= telegram_api::inputBotInlineMessageGame::REPLY_MARKUP_MASK; flags |= telegram_api::inputBotInlineMessageGame::REPLY_MARKUP_MASK;
} }
auto result = make_tl_object<telegram_api::inputBotInlineResultGame>( return make_tl_object<telegram_api::inputBotInlineResultGame>(
game->id_, game->game_short_name_, game->id_, game->game_short_name_,
make_tl_object<telegram_api::inputBotInlineMessageGame>(flags, std::move(input_reply_markup))); make_tl_object<telegram_api::inputBotInlineMessageGame>(flags, std::move(input_reply_markup)));
results.push_back(std::move(result));
continue;
} }
case td_api::inputInlineQueryResultLocation::ID: { case td_api::inputInlineQueryResultLocation::ID: {
auto location = move_tl_object_as<td_api::inputInlineQueryResultLocation>(input_result); auto location = move_tl_object_as<td_api::inputInlineQueryResultLocation>(result);
if (location->location_ == nullptr) { if (location->location_ == nullptr) {
return promise.set_error(Status::Error(400, "Location must be non-empty")); return Status::Error(400, "Location must be non-empty");
} }
type = "geo"; type = "geo";
id = std::move(location->id_); id = std::move(location->id_);
@ -575,7 +592,7 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
break; break;
} }
case td_api::inputInlineQueryResultPhoto::ID: { case td_api::inputInlineQueryResultPhoto::ID: {
auto photo = move_tl_object_as<td_api::inputInlineQueryResultPhoto>(input_result); auto photo = move_tl_object_as<td_api::inputInlineQueryResultPhoto>(result);
type = "photo"; type = "photo";
id = std::move(photo->id_); id = std::move(photo->id_);
title = std::move(photo->title_); title = std::move(photo->title_);
@ -585,7 +602,9 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
content_type = "image/jpeg"; content_type = "image/jpeg";
width = photo->photo_width_; width = photo->photo_width_;
height = photo->photo_height_; height = photo->photo_height_;
is_gallery = true; if (is_gallery != nullptr) {
*is_gallery = true;
}
file_type = FileType::Photo; file_type = FileType::Photo;
r_inline_message = get_inline_message(std::move(photo->input_message_content_), std::move(photo->reply_markup_), r_inline_message = get_inline_message(std::move(photo->input_message_content_), std::move(photo->reply_markup_),
@ -593,19 +612,19 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
break; break;
} }
case td_api::inputInlineQueryResultSticker::ID: { case td_api::inputInlineQueryResultSticker::ID: {
auto sticker = move_tl_object_as<td_api::inputInlineQueryResultSticker>(input_result); auto sticker = move_tl_object_as<td_api::inputInlineQueryResultSticker>(result);
type = "sticker"; type = "sticker";
id = std::move(sticker->id_); id = std::move(sticker->id_);
thumbnail_url = std::move(sticker->thumbnail_url_); thumbnail_url = std::move(sticker->thumbnail_url_);
content_url = std::move(sticker->sticker_url_); content_url = std::move(sticker->sticker_url_);
content_type = content_type = "image/webp"; // or "application/x-tgsticker"/"video/webm"; not used for previously uploaded files
"image/webp"; // or "application/x-tgsticker"/"video/webm"; not used for previously uploaded files
width = sticker->sticker_width_; width = sticker->sticker_width_;
height = sticker->sticker_height_; height = sticker->sticker_height_;
is_gallery = true; if (is_gallery != nullptr) {
*is_gallery = true;
}
if (content_url.find('.') != string::npos) { if (content_url.find('.') != string::npos) {
return promise.set_error(Status::Error(400, "Wrong sticker_file_id specified")); return Status::Error(400, "Wrong sticker_file_id specified");
} }
file_type = FileType::Sticker; file_type = FileType::Sticker;
@ -614,9 +633,9 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
break; break;
} }
case td_api::inputInlineQueryResultVenue::ID: { case td_api::inputInlineQueryResultVenue::ID: {
auto venue = move_tl_object_as<td_api::inputInlineQueryResultVenue>(input_result); auto venue = move_tl_object_as<td_api::inputInlineQueryResultVenue>(result);
if (venue->venue_ == nullptr) { if (venue->venue_ == nullptr) {
return promise.set_error(Status::Error(400, "Venue must be non-empty")); return Status::Error(400, "Venue must be non-empty");
} }
type = "venue"; type = "venue";
id = std::move(venue->id_); id = std::move(venue->id_);
@ -633,7 +652,7 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
break; break;
} }
case td_api::inputInlineQueryResultVideo::ID: { case td_api::inputInlineQueryResultVideo::ID: {
auto video = move_tl_object_as<td_api::inputInlineQueryResultVideo>(input_result); auto video = move_tl_object_as<td_api::inputInlineQueryResultVideo>(result);
type = "video"; type = "video";
id = std::move(video->id_); id = std::move(video->id_);
title = std::move(video->title_); title = std::move(video->title_);
@ -651,7 +670,7 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
} else if (begins_with(content_type, "text/html")) { } else if (begins_with(content_type, "text/html")) {
content_type = "text/html"; content_type = "text/html";
} else { } else {
return promise.set_error(Status::Error(400, "Unallowed video MIME type")); return Status::Error(400, "Unallowed video MIME type");
} }
} }
@ -661,14 +680,16 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
break; break;
} }
case td_api::inputInlineQueryResultVoiceNote::ID: { case td_api::inputInlineQueryResultVoiceNote::ID: {
auto voice_note = move_tl_object_as<td_api::inputInlineQueryResultVoiceNote>(input_result); auto voice_note = move_tl_object_as<td_api::inputInlineQueryResultVoiceNote>(result);
type = "voice"; type = "voice";
id = std::move(voice_note->id_); id = std::move(voice_note->id_);
title = std::move(voice_note->title_); title = std::move(voice_note->title_);
content_url = std::move(voice_note->voice_note_url_); content_url = std::move(voice_note->voice_note_url_);
content_type = "audio/ogg"; content_type = "audio/ogg";
duration = voice_note->voice_note_duration_; duration = voice_note->voice_note_duration_;
force_vertical = true; if (force_vertical != nullptr) {
*force_vertical = true;
}
file_type = FileType::VoiceNote; file_type = FileType::VoiceNote;
r_inline_message = get_inline_message(std::move(voice_note->input_message_content_), r_inline_message = get_inline_message(std::move(voice_note->input_message_content_),
@ -680,11 +701,11 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
break; break;
} }
if (r_inline_message.is_error()) { if (r_inline_message.is_error()) {
return promise.set_error(r_inline_message.move_as_error()); return r_inline_message.move_as_error();
} }
auto inline_message = r_inline_message.move_as_ok(); auto inline_message = r_inline_message.move_as_ok();
if (inline_message->get_id() == telegram_api::inputBotInlineMessageMediaAuto::ID && file_type == FileType::Temp) { if (inline_message->get_id() == telegram_api::inputBotInlineMessageMediaAuto::ID && file_type == FileType::Temp) {
return promise.set_error(Status::Error(400, "Sent message content must be explicitly specified")); return Status::Error(400, "Sent message content must be explicitly specified");
} }
if (duration < 0) { if (duration < 0) {
@ -695,13 +716,13 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
if (!title.empty()) { if (!title.empty()) {
flags |= telegram_api::inputBotInlineResult::TITLE_MASK; flags |= telegram_api::inputBotInlineResult::TITLE_MASK;
if (!clean_input_string(title)) { if (!clean_input_string(title)) {
return promise.set_error(Status::Error(400, "Strings must be encoded in UTF-8")); return Status::Error(400, "Strings must be encoded in UTF-8");
} }
} }
if (!description.empty()) { if (!description.empty()) {
flags |= telegram_api::inputBotInlineResult::DESCRIPTION_MASK; flags |= telegram_api::inputBotInlineResult::DESCRIPTION_MASK;
if (!clean_input_string(description)) { if (!clean_input_string(description)) {
return promise.set_error(Status::Error(400, "Strings must be encoded in UTF-8")); return Status::Error(400, "Strings must be encoded in UTF-8");
} }
} }
@ -709,60 +730,54 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
auto r_file_id = td_->file_manager_->get_input_file_id( auto r_file_id = td_->file_manager_->get_input_file_id(
file_type, make_tl_object<td_api::inputFileRemote>(content_url), DialogId(), false, false); file_type, make_tl_object<td_api::inputFileRemote>(content_url), DialogId(), false, false);
if (r_file_id.is_error()) { if (r_file_id.is_error()) {
return promise.set_error(Status::Error(400, r_file_id.error().message())); return Status::Error(400, r_file_id.error().message());
} }
auto file_id = r_file_id.ok(); auto file_id = r_file_id.ok();
FileView file_view = td_->file_manager_->get_file_view(file_id); FileView file_view = td_->file_manager_->get_file_view(file_id);
CHECK(file_view.has_remote_location()); CHECK(file_view.has_remote_location());
if (file_view.is_encrypted()) { if (file_view.is_encrypted()) {
return promise.set_error(Status::Error(400, "Can't send encrypted file")); return Status::Error(400, "Can't send encrypted file");
} }
if (file_view.main_remote_location().is_web()) { if (file_view.main_remote_location().is_web()) {
return promise.set_error(Status::Error(400, "Can't send web file")); return Status::Error(400, "Can't send web file");
} }
if (file_type == FileType::Photo) { if (file_type == FileType::Photo) {
auto result = make_tl_object<telegram_api::inputBotInlineResultPhoto>( return make_tl_object<telegram_api::inputBotInlineResultPhoto>(
id, type, file_view.main_remote_location().as_input_photo(), std::move(inline_message)); id, type, file_view.main_remote_location().as_input_photo(), std::move(inline_message));
results.push_back(std::move(result));
continue;
} }
auto result = make_tl_object<telegram_api::inputBotInlineResultDocument>( return make_tl_object<telegram_api::inputBotInlineResultDocument>(
flags, id, type, title, description, file_view.main_remote_location().as_input_document(), flags, id, type, title, description, file_view.main_remote_location().as_input_document(),
std::move(inline_message)); std::move(inline_message));
results.push_back(std::move(result));
continue;
} }
if (!url.empty()) { if (!url.empty()) {
flags |= telegram_api::inputBotInlineResult::URL_MASK; flags |= telegram_api::inputBotInlineResult::URL_MASK;
if (!clean_input_string(url)) { if (!clean_input_string(url)) {
return promise.set_error(Status::Error(400, "Strings must be encoded in UTF-8")); return Status::Error(400, "Strings must be encoded in UTF-8");
} }
} }
tl_object_ptr<telegram_api::inputWebDocument> thumbnail; tl_object_ptr<telegram_api::inputWebDocument> thumbnail;
if (!thumbnail_url.empty()) { if (!thumbnail_url.empty()) {
flags |= telegram_api::inputBotInlineResult::THUMB_MASK; flags |= telegram_api::inputBotInlineResult::THUMB_MASK;
if (!clean_input_string(thumbnail_url)) { if (!clean_input_string(thumbnail_url)) {
return promise.set_error(Status::Error(400, "Strings must be encoded in UTF-8")); return Status::Error(400, "Strings must be encoded in UTF-8");
} }
vector<tl_object_ptr<telegram_api::DocumentAttribute>> attributes; vector<tl_object_ptr<telegram_api::DocumentAttribute>> attributes;
if (thumbnail_width > 0 && thumbnail_height > 0) { if (thumbnail_width > 0 && thumbnail_height > 0) {
attributes.push_back( attributes.push_back(make_tl_object<telegram_api::documentAttributeImageSize>(thumbnail_width, thumbnail_height));
make_tl_object<telegram_api::documentAttributeImageSize>(thumbnail_width, thumbnail_height));
} }
thumbnail = thumbnail = make_tl_object<telegram_api::inputWebDocument>(thumbnail_url, 0, thumbnail_type, std::move(attributes));
make_tl_object<telegram_api::inputWebDocument>(thumbnail_url, 0, thumbnail_type, std::move(attributes));
} }
tl_object_ptr<telegram_api::inputWebDocument> content; tl_object_ptr<telegram_api::inputWebDocument> content;
if (!content_url.empty() || !content_type.empty()) { if (!content_url.empty() || !content_type.empty()) {
flags |= telegram_api::inputBotInlineResult::CONTENT_MASK; flags |= telegram_api::inputBotInlineResult::CONTENT_MASK;
if (!clean_input_string(content_url)) { if (!clean_input_string(content_url)) {
return promise.set_error(Status::Error(400, "Strings must be encoded in UTF-8")); return Status::Error(400, "Strings must be encoded in UTF-8");
} }
if (!clean_input_string(content_type)) { if (!clean_input_string(content_type)) {
return promise.set_error(Status::Error(400, "Strings must be encoded in UTF-8")); return Status::Error(400, "Strings must be encoded in UTF-8");
} }
vector<tl_object_ptr<telegram_api::DocumentAttribute>> attributes; vector<tl_object_ptr<telegram_api::DocumentAttribute>> attributes;
@ -786,14 +801,8 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
content = make_tl_object<telegram_api::inputWebDocument>(content_url, 0, content_type, std::move(attributes)); content = make_tl_object<telegram_api::inputWebDocument>(content_url, 0, content_type, std::move(attributes));
} }
auto result = make_tl_object<telegram_api::inputBotInlineResult>( return make_tl_object<telegram_api::inputBotInlineResult>(
flags, id, type, title, description, url, std::move(thumbnail), std::move(content), std::move(inline_message)); flags, id, type, title, description, url, std::move(thumbnail), std::move(content), std::move(inline_message));
results.push_back(std::move(result));
}
td_->create_handler<SetInlineBotResultsQuery>(std::move(promise))
->send(inline_query_id, is_gallery && !force_vertical, is_personal, std::move(results), cache_time, next_offset,
switch_pm_text, switch_pm_parameter);
} }
uint64 InlineQueriesManager::send_inline_query(UserId bot_user_id, DialogId dialog_id, Location user_location, uint64 InlineQueriesManager::send_inline_query(UserId bot_user_id, DialogId dialog_id, Location user_location,

View File

@ -43,7 +43,7 @@ class InlineQueriesManager final : public Actor {
void after_get_difference(); void after_get_difference();
void answer_inline_query(int64 inline_query_id, bool is_personal, void answer_inline_query(int64 inline_query_id, bool is_personal,
vector<tl_object_ptr<td_api::InputInlineQueryResult>> &&input_results, int32 cache_time, vector<td_api::object_ptr<td_api::InputInlineQueryResult>> &&input_results, int32 cache_time,
const string &next_offset, const string &switch_pm_text, const string &switch_pm_parameter, const string &next_offset, const string &switch_pm_text, const string &switch_pm_parameter,
Promise<Unit> &&promise) const; Promise<Unit> &&promise) const;
@ -87,6 +87,9 @@ class InlineQueriesManager final : public Actor {
static constexpr int32 BOT_INLINE_MEDIA_RESULT_FLAG_HAS_TITLE = 1 << 2; static constexpr int32 BOT_INLINE_MEDIA_RESULT_FLAG_HAS_TITLE = 1 << 2;
static constexpr int32 BOT_INLINE_MEDIA_RESULT_FLAG_HAS_DESCRIPTION = 1 << 3; static constexpr int32 BOT_INLINE_MEDIA_RESULT_FLAG_HAS_DESCRIPTION = 1 << 3;
Result<tl_object_ptr<telegram_api::InputBotInlineResult>> get_input_bot_inline_result(
td_api::object_ptr<td_api::InputInlineQueryResult> &&result, bool *is_gallery, bool *force_vertical) const;
Result<tl_object_ptr<telegram_api::InputBotInlineMessage>> get_inline_message( Result<tl_object_ptr<telegram_api::InputBotInlineMessage>> get_inline_message(
tl_object_ptr<td_api::InputMessageContent> &&input_message_content, tl_object_ptr<td_api::InputMessageContent> &&input_message_content,
tl_object_ptr<td_api::ReplyMarkup> &&reply_markup_ptr, tl_object_ptr<td_api::ReplyMarkup> &&reply_markup_ptr,

View File

@ -13431,7 +13431,7 @@ void MessagesManager::on_message_ttl_expired_impl(Dialog *d, Message *m) {
remove_message_notification_id(d, m, true, true); remove_message_notification_id(d, m, true, true);
update_message_contains_unread_mention(d, m, false, "on_message_ttl_expired_impl"); update_message_contains_unread_mention(d, m, false, "on_message_ttl_expired_impl");
remove_message_unread_reactions(d, m, "on_message_ttl_expired_impl"); remove_message_unread_reactions(d, m, "on_message_ttl_expired_impl");
unregister_message_reply(d, m); unregister_message_reply(d->dialog_id, m);
m->noforwards = false; m->noforwards = false;
m->contains_mention = false; m->contains_mention = false;
m->reply_to_message_id = MessageId(); m->reply_to_message_id = MessageId();
@ -16596,7 +16596,7 @@ void MessagesManager::on_message_deleted(Dialog *d, Message *m, bool is_permanen
ttl_period_unregister_message(d->dialog_id, m); ttl_period_unregister_message(d->dialog_id, m);
delete_bot_command_message_id(d->dialog_id, m->message_id); delete_bot_command_message_id(d->dialog_id, m->message_id);
unregister_message_content(td_, m->content.get(), {d->dialog_id, m->message_id}, "on_message_deleted"); unregister_message_content(td_, m->content.get(), {d->dialog_id, m->message_id}, "on_message_deleted");
unregister_message_reply(d, m); unregister_message_reply(d->dialog_id, m);
if (m->notification_id.is_valid()) { if (m->notification_id.is_valid()) {
delete_notification_id_to_message_id_correspondence(d, m->notification_id, m->message_id); delete_notification_id_to_message_id_correspondence(d, m->notification_id, m->message_id);
} }
@ -16643,7 +16643,7 @@ unique_ptr<MessagesManager::Message> MessagesManager::do_delete_scheduled_messag
cancel_send_deleted_message(d->dialog_id, result.get(), is_permanently_deleted); cancel_send_deleted_message(d->dialog_id, result.get(), is_permanently_deleted);
unregister_message_content(td_, result->content.get(), {d->dialog_id, message_id}, "do_delete_scheduled_message"); unregister_message_content(td_, result->content.get(), {d->dialog_id, message_id}, "do_delete_scheduled_message");
unregister_message_reply(d, m); unregister_message_reply(d->dialog_id, m);
return result; return result;
} }
@ -27938,25 +27938,25 @@ void MessagesManager::update_message_max_reply_media_timestamp_in_replied_messag
} }
} }
void MessagesManager::register_message_reply(const Dialog *d, const Message *m) { void MessagesManager::register_message_reply(DialogId dialog_id, const Message *m) {
if (!m->reply_to_message_id.is_valid() || td_->auth_manager_->is_bot()) { if (!m->reply_to_message_id.is_valid() || td_->auth_manager_->is_bot()) {
return; return;
} }
if (has_media_timestamps(get_message_content_text(m->content.get()), 0, std::numeric_limits<int32>::max())) { if (has_media_timestamps(get_message_content_text(m->content.get()), 0, std::numeric_limits<int32>::max())) {
LOG(INFO) << "Register " << m->message_id << " in " << d->dialog_id << " as reply to " << m->reply_to_message_id; LOG(INFO) << "Register " << m->message_id << " in " << dialog_id << " as reply to " << m->reply_to_message_id;
FullMessageId full_message_id{d->dialog_id, m->reply_to_message_id}; FullMessageId full_message_id{dialog_id, m->reply_to_message_id};
bool is_inserted = replied_by_media_timestamp_messages_[full_message_id].insert(m->message_id).second; bool is_inserted = replied_by_media_timestamp_messages_[full_message_id].insert(m->message_id).second;
CHECK(is_inserted); CHECK(is_inserted);
} }
} }
void MessagesManager::reregister_message_reply(const Dialog *d, const Message *m) { void MessagesManager::reregister_message_reply(DialogId dialog_id, const Message *m) {
if (!m->reply_to_message_id.is_valid() || td_->auth_manager_->is_bot()) { if (!m->reply_to_message_id.is_valid() || td_->auth_manager_->is_bot()) {
return; return;
} }
auto it = replied_by_media_timestamp_messages_.find({d->dialog_id, m->reply_to_message_id}); auto it = replied_by_media_timestamp_messages_.find({dialog_id, m->reply_to_message_id});
bool was_registered = it != replied_by_media_timestamp_messages_.end() && it->second.count(m->message_id) > 0; bool was_registered = it != replied_by_media_timestamp_messages_.end() && it->second.count(m->message_id) > 0;
bool need_register = bool need_register =
has_media_timestamps(get_message_content_text(m->content.get()), 0, std::numeric_limits<int32>::max()); has_media_timestamps(get_message_content_text(m->content.get()), 0, std::numeric_limits<int32>::max());
@ -27964,21 +27964,21 @@ void MessagesManager::reregister_message_reply(const Dialog *d, const Message *m
return; return;
} }
if (was_registered) { if (was_registered) {
unregister_message_reply(d, m); unregister_message_reply(dialog_id, m);
} else { } else {
register_message_reply(d, m); register_message_reply(dialog_id, m);
} }
} }
void MessagesManager::unregister_message_reply(const Dialog *d, const Message *m) { void MessagesManager::unregister_message_reply(DialogId dialog_id, const Message *m) {
auto it = replied_by_media_timestamp_messages_.find({d->dialog_id, m->reply_to_message_id}); auto it = replied_by_media_timestamp_messages_.find({dialog_id, m->reply_to_message_id});
if (it == replied_by_media_timestamp_messages_.end()) { if (it == replied_by_media_timestamp_messages_.end()) {
return; return;
} }
auto is_deleted = it->second.erase(m->message_id) > 0; auto is_deleted = it->second.erase(m->message_id) > 0;
if (is_deleted) { if (is_deleted) {
LOG(INFO) << "Unregister " << m->message_id << " in " << d->dialog_id << " as reply to " << m->reply_to_message_id; LOG(INFO) << "Unregister " << m->message_id << " in " << dialog_id << " as reply to " << m->reply_to_message_id;
if (it->second.empty()) { if (it->second.empty()) {
replied_by_media_timestamp_messages_.erase(it); replied_by_media_timestamp_messages_.erase(it);
} }
@ -30635,7 +30635,7 @@ void MessagesManager::send_update_message_content(const Dialog *d, Message *m, b
if (is_message_in_dialog) { if (is_message_in_dialog) {
delete_bot_command_message_id(d->dialog_id, m->message_id); delete_bot_command_message_id(d->dialog_id, m->message_id);
try_add_bot_command_message_id(d->dialog_id, m); try_add_bot_command_message_id(d->dialog_id, m);
reregister_message_reply(d, m); reregister_message_reply(d->dialog_id, m);
update_message_max_reply_media_timestamp(d, m, false); // because the message reply can be just registered update_message_max_reply_media_timestamp(d, m, false); // because the message reply can be just registered
update_message_max_own_media_timestamp(d, m); update_message_max_own_media_timestamp(d, m);
} }
@ -35059,7 +35059,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
register_message_content(td_, m->content.get(), {dialog_id, m->message_id}, "add_message_to_dialog"); register_message_content(td_, m->content.get(), {dialog_id, m->message_id}, "add_message_to_dialog");
register_message_reply(d, m); register_message_reply(dialog_id, m);
if (*need_update && m->message_id.is_server() && message_content_type == MessageContentType::PinMessage) { if (*need_update && m->message_id.is_server() && message_content_type == MessageContentType::PinMessage) {
auto pinned_message_id = get_message_content_pinned_message_id(m->content.get()); auto pinned_message_id = get_message_content_pinned_message_id(m->content.get());
@ -35287,7 +35287,7 @@ MessagesManager::Message *MessagesManager::add_scheduled_message_to_dialog(Dialo
update_message_max_reply_media_timestamp(d, message.get(), false); update_message_max_reply_media_timestamp(d, message.get(), false);
update_message_max_own_media_timestamp(d, message.get()); update_message_max_own_media_timestamp(d, message.get());
register_message_reply(d, m); register_message_reply(dialog_id, m);
if (from_update) { if (from_update) {
update_sent_message_contents(dialog_id, m); update_sent_message_contents(dialog_id, m);
@ -35901,16 +35901,23 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
// can change message tree and invalidate reference to old_message // can change message tree and invalidate reference to old_message
if (new_message->reply_to_message_id == MessageId() || replace_legacy) { if (new_message->reply_to_message_id == MessageId() || replace_legacy) {
LOG(DEBUG) << "Drop message reply_to_message_id"; LOG(DEBUG) << "Drop message reply_to_message_id";
unregister_message_reply(d, old_message); unregister_message_reply(dialog_id, old_message);
old_message->reply_to_message_id = MessageId(); old_message->reply_to_message_id = MessageId();
update_message_max_reply_media_timestamp(d, old_message, true); update_message_max_reply_media_timestamp(d, old_message, is_message_in_dialog);
need_send_update = true; need_send_update = true;
} else if (is_new_available) { } else if (is_new_available) {
if (message_id.is_yet_unsent() && old_message->reply_to_message_id == MessageId()) {
CHECK(!is_message_in_dialog);
CHECK(new_message->reply_to_message_id.is_valid());
CHECK(new_message->reply_to_message_id.is_server());
old_message->reply_to_message_id = new_message->reply_to_message_id;
} else {
LOG(ERROR) << message_id << " in " << dialog_id << " has changed message it is reply to from " LOG(ERROR) << message_id << " in " << dialog_id << " has changed message it is reply to from "
<< old_message->reply_to_message_id << " to " << new_message->reply_to_message_id << old_message->reply_to_message_id << " to " << new_message->reply_to_message_id
<< ", message content type is " << old_content_type << '/' << new_content_type; << ", message content type is " << old_content_type << '/' << new_content_type;
} }
} }
}
if (old_message->reply_in_dialog_id != new_message->reply_in_dialog_id) { if (old_message->reply_in_dialog_id != new_message->reply_in_dialog_id) {
if (new_message->reply_in_dialog_id == DialogId() || replace_legacy) { if (new_message->reply_in_dialog_id == DialogId() || replace_legacy) {
LOG(DEBUG) << "Drop message reply_in_dialog_id"; LOG(DEBUG) << "Drop message reply_in_dialog_id";

View File

@ -2358,11 +2358,11 @@ class MessagesManager final : public Actor {
void update_message_max_reply_media_timestamp_in_replied_messages(DialogId dialog_id, MessageId reply_to_message_id); void update_message_max_reply_media_timestamp_in_replied_messages(DialogId dialog_id, MessageId reply_to_message_id);
void register_message_reply(const Dialog *d, const Message *m); void register_message_reply(DialogId dialog_id, const Message *m);
void reregister_message_reply(const Dialog *d, const Message *m); void reregister_message_reply(DialogId dialog_id, const Message *m);
void unregister_message_reply(const Dialog *d, const Message *m); void unregister_message_reply(DialogId dialog_id, const Message *m);
void send_update_new_message(const Dialog *d, const Message *m); void send_update_new_message(const Dialog *d, const Message *m);