Merge remote-tracking branch 'td/master'

This commit is contained in:
Andrea Cavalli 2021-10-04 00:06:53 +02:00
commit 65f4b8ba57
6 changed files with 274 additions and 233 deletions

View File

@ -242,7 +242,7 @@ void GameManager::set_game_score(FullMessageId full_message_id, bool edit_messag
void GameManager::on_set_game_score(FullMessageId full_message_id, void GameManager::on_set_game_score(FullMessageId full_message_id,
Promise<td_api::object_ptr<td_api::message>> &&promise) { Promise<td_api::object_ptr<td_api::message>> &&promise) {
promise.set_value(td_->messages_manager_->get_message_object(full_message_id)); promise.set_value(td_->messages_manager_->get_message_object(full_message_id, "on_set_game_score"));
} }
void GameManager::set_inline_game_score(const string &inline_message_id, bool edit_message, UserId user_id, int32 score, void GameManager::set_inline_game_score(const string &inline_message_id, bool edit_message, UserId user_id, int32 score,

View File

@ -585,7 +585,7 @@ class UpdateDialogPinnedMessageQuery final : public Td::ResultHandler {
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Write); auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) { if (input_peer == nullptr) {
LOG(INFO) << "Can't update pinned message in " << dialog_id; LOG(INFO) << "Can't update pinned message in " << dialog_id;
return on_error(0, Status::Error(500, "Can't update pinned message")); return on_error(0, Status::Error(400, "Can't update pinned message"));
} }
int32 flags = 0; int32 flags = 0;
@ -628,7 +628,7 @@ class UnpinAllMessagesQuery final : public Td::ResultHandler {
auto input_peer = td->messages_manager_->get_input_peer(dialog_id_, AccessRights::Write); auto input_peer = td->messages_manager_->get_input_peer(dialog_id_, AccessRights::Write);
if (input_peer == nullptr) { if (input_peer == nullptr) {
LOG(INFO) << "Can't unpin all messages in " << dialog_id_; LOG(INFO) << "Can't unpin all messages in " << dialog_id_;
return on_error(0, Status::Error(500, "Can't unpin all messages")); return on_error(0, Status::Error(400, "Can't unpin all messages"));
} }
send_query(G()->net_query_creator().create(telegram_api::messages_unpinAllMessages(std::move(input_peer)))); send_query(G()->net_query_creator().create(telegram_api::messages_unpinAllMessages(std::move(input_peer))));
@ -1187,7 +1187,7 @@ class UploadImportedMediaQuery final : public Td::ResultHandler {
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Write); auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) { if (input_peer == nullptr) {
return on_error(0, Status::Error(400, "Have no write access to the chat")); return on_error(0, Status::Error(400, "Can't access the chat"));
} }
send_query(G()->net_query_creator().create(telegram_api::messages_uploadImportedMedia( send_query(G()->net_query_creator().create(telegram_api::messages_uploadImportedMedia(
@ -1532,7 +1532,7 @@ class SaveDraftMessageQuery final : public Td::ResultHandler {
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Write); auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) { if (input_peer == nullptr) {
LOG(INFO) << "Can't update draft message because have no write access to " << dialog_id; LOG(INFO) << "Can't update draft message because have no write access to " << dialog_id;
return on_error(0, Status::Error(500, "Can't save draft message")); return on_error(0, Status::Error(400, "Can't save draft message"));
} }
int32 flags = 0; int32 flags = 0;
@ -1631,7 +1631,7 @@ class ToggleDialogPinQuery final : public Td::ResultHandler {
auto input_peer = td->messages_manager_->get_input_dialog_peer(dialog_id, AccessRights::Read); auto input_peer = td->messages_manager_->get_input_dialog_peer(dialog_id, AccessRights::Read);
if (input_peer == nullptr) { if (input_peer == nullptr) {
return on_error(0, Status::Error(500, "Can't update dialog is_pinned")); return on_error(0, Status::Error(400, "Can't access the chat"));
} }
int32 flags = 0; int32 flags = 0;
@ -1721,7 +1721,7 @@ class ToggleDialogUnreadMarkQuery final : public Td::ResultHandler {
auto input_peer = td->messages_manager_->get_input_dialog_peer(dialog_id, AccessRights::Read); auto input_peer = td->messages_manager_->get_input_dialog_peer(dialog_id, AccessRights::Read);
if (input_peer == nullptr) { if (input_peer == nullptr) {
return on_error(0, Status::Error(500, "Can't update dialog is_marked_as_unread")); return on_error(0, Status::Error(400, "Can't access the chat"));
} }
int32 flags = 0; int32 flags = 0;
@ -1817,8 +1817,7 @@ class GetMessagesViewsQuery final : public Td::ResultHandler {
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read); auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
if (input_peer == nullptr) { if (input_peer == nullptr) {
LOG(ERROR) << "Can't update message view count because doesn't have info about the " << dialog_id; return on_error(0, Status::Error(400, "Can't access the chat"));
return on_error(0, Status::Error(500, "Can't update message view count"));
} }
LOG(INFO) << "View " << message_ids_.size() << " messages in " << dialog_id LOG(INFO) << "View " << message_ids_.size() << " messages in " << dialog_id
@ -1956,7 +1955,7 @@ class GetDialogMessageByDateQuery final : public Td::ResultHandler {
void send(DialogId dialog_id, int32 date, int64 random_id) { void send(DialogId dialog_id, int32 date, int64 random_id) {
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read); auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
if (input_peer == nullptr) { if (input_peer == nullptr) {
return promise_.set_error(Status::Error(500, "Have no info about the chat")); return promise_.set_error(Status::Error(400, "Can't access the chat"));
} }
dialog_id_ = dialog_id; dialog_id_ = dialog_id;
@ -2015,8 +2014,7 @@ class GetHistoryQuery final : public Td::ResultHandler {
int32 limit) { int32 limit) {
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read); auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
if (input_peer == nullptr) { if (input_peer == nullptr) {
LOG(ERROR) << "Can't get chat history in " << dialog_id << " because doesn't have info about the chat"; return promise_.set_error(Status::Error(400, "Can't access the chat"));
return promise_.set_error(Status::Error(500, "Have no info about the chat"));
} }
CHECK(offset < 0); CHECK(offset < 0);
@ -2033,8 +2031,7 @@ class GetHistoryQuery final : public Td::ResultHandler {
void send_get_from_the_end(DialogId dialog_id, MessageId old_last_new_message_id, int32 limit) { void send_get_from_the_end(DialogId dialog_id, MessageId old_last_new_message_id, int32 limit) {
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read); auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
if (input_peer == nullptr) { if (input_peer == nullptr) {
LOG(ERROR) << "Can't get chat history because doesn't have info about the chat"; return promise_.set_error(Status::Error(400, "Can't access the chat"));
return promise_.set_error(Status::Error(500, "Have no info about the chat"));
} }
dialog_id_ = dialog_id; dialog_id_ = dialog_id;
@ -2209,8 +2206,7 @@ class SearchMessagesQuery final : public Td::ResultHandler {
auto input_peer = dialog_id.is_valid() ? td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read) auto input_peer = dialog_id.is_valid() ? td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read)
: make_tl_object<telegram_api::inputPeerEmpty>(); : make_tl_object<telegram_api::inputPeerEmpty>();
if (input_peer == nullptr) { if (input_peer == nullptr) {
LOG(ERROR) << "Can't search messages because doesn't have info about the chat"; return promise_.set_error(Status::Error(400, "Can't access the chat"));
return promise_.set_error(Status::Error(500, "Have no info about the chat"));
} }
dialog_id_ = dialog_id; dialog_id_ = dialog_id;
@ -2296,6 +2292,55 @@ class SearchMessagesQuery final : public Td::ResultHandler {
} }
}; };
class GetSearchCountersQuery final : public Td::ResultHandler {
Promise<int32> promise_;
DialogId dialog_id_;
MessageSearchFilter filter_;
public:
explicit GetSearchCountersQuery(Promise<int32> &&promise) : promise_(std::move(promise)) {
}
void send(DialogId dialog_id, MessageSearchFilter filter) {
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
if (input_peer == nullptr) {
return promise_.set_error(Status::Error(400, "Can't access the chat"));
}
dialog_id_ = dialog_id;
filter_ = filter;
CHECK(filter != MessageSearchFilter::Empty);
CHECK(filter != MessageSearchFilter::UnreadMention);
CHECK(filter != MessageSearchFilter::FailedToSend);
vector<telegram_api::object_ptr<telegram_api::MessagesFilter>> filters;
filters.push_back(get_input_messages_filter(filter));
send_query(G()->net_query_creator().create(
telegram_api::messages_getSearchCounters(std::move(input_peer), std::move(filters))));
}
void on_result(uint64 id, BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_getSearchCounters>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
auto result = result_ptr.move_as_ok();
if (result.size() != 1 || result[0]->filter_->get_id() != get_input_messages_filter(filter_)->get_id()) {
LOG(ERROR) << "Receive unexpected response for get message count in " << dialog_id_ << " with filter " << filter_
<< ": " << to_string(result);
return on_error(id, Status::Error(500, "Receive wrong response"));
}
td->messages_manager_->on_get_dialog_message_count(dialog_id_, filter_, result[0]->count_, std::move(promise_));
}
void on_error(uint64 id, Status status) final {
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetSearchCountersQuery");
promise_.set_error(std::move(status));
}
};
class SearchMessagesGlobalQuery final : public Td::ResultHandler { class SearchMessagesGlobalQuery final : public Td::ResultHandler {
Promise<Unit> promise_; Promise<Unit> promise_;
string query_; string query_;
@ -2427,8 +2472,7 @@ class GetRecentLocationsQuery final : public Td::ResultHandler {
void send(DialogId dialog_id, int32 limit, int64 random_id) { void send(DialogId dialog_id, int32 limit, int64 random_id) {
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read); auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
if (input_peer == nullptr) { if (input_peer == nullptr) {
LOG(ERROR) << "Can't get recent locations because doesn't have info about the chat"; return on_error(0, Status::Error(400, "Have no info about the chat"));
return promise_.set_error(Status::Error(500, "Have no info about the chat"));
} }
dialog_id_ = dialog_id; dialog_id_ = dialog_id;
@ -8693,9 +8737,9 @@ void MessagesManager::do_send_media(DialogId dialog_id, Message *m, FileId file_
auto input_media = get_input_media(content, td_, std::move(input_file), std::move(input_thumbnail), file_id, auto input_media = get_input_media(content, td_, std::move(input_file), std::move(input_thumbnail), file_id,
thumbnail_file_id, m->ttl, true); thumbnail_file_id, m->ttl, true);
LOG_CHECK(input_media != nullptr) << to_string(get_message_object(dialog_id, m)) << ' ' << have_input_file << ' ' LOG_CHECK(input_media != nullptr) << to_string(get_message_object(dialog_id, m, "do_send_media")) << ' '
<< have_input_thumbnail << ' ' << file_id << ' ' << thumbnail_file_id << ' ' << have_input_file << ' ' << have_input_thumbnail << ' ' << file_id << ' '
<< m->ttl; << thumbnail_file_id << ' ' << m->ttl;
on_message_media_uploaded(dialog_id, m, std::move(input_media), file_id, thumbnail_file_id); on_message_media_uploaded(dialog_id, m, std::move(input_media), file_id, thumbnail_file_id);
} }
@ -9141,16 +9185,16 @@ void MessagesManager::after_get_difference() {
dump_debug_message_op(get_dialog(dialog_id)); dump_debug_message_op(get_dialog(dialog_id));
} }
if (message_id <= d->last_new_message_id) { if (message_id <= d->last_new_message_id) {
get_message_from_server(it.first, PromiseCreator::lambda([this, full_message_id](Result<Unit> result) { get_message_from_server(
if (result.is_error()) { it.first, PromiseCreator::lambda([this, full_message_id](Result<Unit> result) {
LOG(WARNING) if (result.is_error()) {
<< "Failed to get missing " << full_message_id << ": " << result.error(); LOG(WARNING) << "Failed to get missing " << full_message_id << ": " << result.error();
} else { } else {
LOG(WARNING) << "Successfully get missing " << full_message_id << ": " LOG(WARNING) << "Successfully get missing " << full_message_id << ": "
<< to_string(get_message_object(full_message_id)); << to_string(get_message_object(full_message_id, "after_get_difference"));
} }
}), }),
"get missing"); "get missing");
} else if (dialog_id.get_type() == DialogType::Channel) { } else if (dialog_id.get_type() == DialogType::Channel) {
LOG(INFO) << "Schedule getDifference in " << dialog_id.get_channel_id(); LOG(INFO) << "Schedule getDifference in " << dialog_id.get_channel_id();
channel_get_difference_retry_timeout_.add_timeout_in(dialog_id.get(), 0.001); channel_get_difference_retry_timeout_.add_timeout_in(dialog_id.get(), 0.001);
@ -9649,6 +9693,10 @@ void MessagesManager::on_get_dialog_messages_search_result(DialogId dialog_id, c
MessageId top_thread_message_id, int64 random_id, MessageId top_thread_message_id, int64 random_id,
int32 total_count, int32 total_count,
vector<tl_object_ptr<telegram_api::Message>> &&messages) { vector<tl_object_ptr<telegram_api::Message>> &&messages) {
if (G()->close_flag()) {
return;
}
LOG(INFO) << "Receive " << messages.size() << " found messages in " << dialog_id; LOG(INFO) << "Receive " << messages.size() << " found messages in " << dialog_id;
if (!dialog_id.is_valid()) { if (!dialog_id.is_valid()) {
CHECK(query.empty()); CHECK(query.empty());
@ -9778,29 +9826,28 @@ void MessagesManager::on_get_dialog_messages_search_result(DialogId dialog_id, c
bool from_the_end = !from_message_id.is_valid() || bool from_the_end = !from_message_id.is_valid() ||
(d->last_message_id != MessageId() && from_message_id > d->last_message_id) || (d->last_message_id != MessageId() && from_message_id > d->last_message_id) ||
from_message_id >= MessageId::max(); from_message_id >= MessageId::max();
if (G()->parameters().use_message_db) { bool update_dialog = false;
bool update_dialog = false;
auto &old_message_count = d->message_count_by_index[message_search_filter_index(filter)]; auto &old_message_count = d->message_count_by_index[message_search_filter_index(filter)];
if (old_message_count != total_count) { if (old_message_count != total_count) {
old_message_count = total_count; old_message_count = total_count;
if (filter == MessageSearchFilter::UnreadMention) { if (filter == MessageSearchFilter::UnreadMention) {
d->unread_mention_count = old_message_count; d->unread_mention_count = old_message_count;
update_dialog_mention_notification_count(d); update_dialog_mention_notification_count(d);
send_update_chat_unread_mention_count(d); send_update_chat_unread_mention_count(d);
}
update_dialog = true;
} }
update_dialog = true;
}
auto &old_first_db_message_id = d->first_database_message_id_by_index[message_search_filter_index(filter)]; auto &old_first_database_message_id = d->first_database_message_id_by_index[message_search_filter_index(filter)];
if ((from_the_end || (old_first_db_message_id.is_valid() && old_first_db_message_id <= from_message_id)) && if ((from_the_end ||
(!old_first_db_message_id.is_valid() || first_added_message_id < old_first_db_message_id)) { (old_first_database_message_id.is_valid() && old_first_database_message_id <= from_message_id)) &&
old_first_db_message_id = first_added_message_id; (!old_first_database_message_id.is_valid() || first_added_message_id < old_first_database_message_id)) {
update_dialog = true; old_first_database_message_id = first_added_message_id;
} update_dialog = true;
if (update_dialog) { }
on_dialog_updated(dialog_id, "search results"); if (update_dialog) {
} on_dialog_updated(dialog_id, "search results");
} }
if (from_the_end && filter == MessageSearchFilter::Pinned) { if (from_the_end && filter == MessageSearchFilter::Pinned) {
@ -9824,6 +9871,39 @@ void MessagesManager::on_failed_dialog_messages_search(DialogId dialog_id, int64
found_dialog_messages_.erase(it); found_dialog_messages_.erase(it);
} }
void MessagesManager::on_get_dialog_message_count(DialogId dialog_id, MessageSearchFilter filter, int32 total_count,
Promise<int32> &&promise) {
LOG(INFO) << "Receive " << total_count << " message count in " << dialog_id << " with filter " << filter;
if (total_count < 0) {
LOG(ERROR) << "Receive total message count = " << total_count << " in " << dialog_id << " with filter " << filter;
total_count = 0;
}
Dialog *d = get_dialog(dialog_id);
CHECK(d != nullptr);
CHECK(filter != MessageSearchFilter::Empty);
CHECK(filter != MessageSearchFilter::UnreadMention);
CHECK(filter != MessageSearchFilter::FailedToSend);
auto &old_message_count = d->message_count_by_index[message_search_filter_index(filter)];
if (old_message_count != total_count) {
old_message_count = total_count;
on_dialog_updated(dialog_id, "on_get_dialog_message_count");
}
if (total_count == 0) {
auto &old_first_database_message_id = d->first_database_message_id_by_index[message_search_filter_index(filter)];
if (old_first_database_message_id != MessageId::min()) {
old_first_database_message_id = MessageId::min();
on_dialog_updated(dialog_id, "on_get_dialog_message_count");
}
if (filter == MessageSearchFilter::Pinned) {
set_dialog_last_pinned_message_id(d, MessageId());
}
}
promise.set_value(std::move(total_count));
}
void MessagesManager::on_get_messages_search_result(const string &query, int32 offset_date, DialogId offset_dialog_id, void MessagesManager::on_get_messages_search_result(const string &query, int32 offset_date, DialogId offset_dialog_id,
MessageId offset_message_id, int32 limit, MessageId offset_message_id, int32 limit,
MessageSearchFilter filter, int32 min_date, int32 max_date, MessageSearchFilter filter, int32 min_date, int32 max_date,
@ -9978,7 +10058,7 @@ void MessagesManager::on_get_message_public_forwards(int32 total_count,
false, false, false, "get message public forwards"); false, false, false, "get message public forwards");
if (new_full_message_id != FullMessageId()) { if (new_full_message_id != FullMessageId()) {
CHECK(dialog_id == new_full_message_id.get_dialog_id()); CHECK(dialog_id == new_full_message_id.get_dialog_id());
result.push_back(get_message_object(new_full_message_id)); result.push_back(get_message_object(new_full_message_id, "on_get_message_public_forwards"));
CHECK(result.back() != nullptr); CHECK(result.back() != nullptr);
last_full_message_id = new_full_message_id; last_full_message_id = new_full_message_id;
} else { } else {
@ -13647,10 +13727,9 @@ FullMessageId MessagesManager::on_get_message(MessageInfo &&message_info, bool f
<< " with identifier less than last_new_message_id = " << d->last_new_message_id << " with identifier less than last_new_message_id = " << d->last_new_message_id
<< " and trying to add it anyway"; << " and trying to add it anyway";
} else { } else {
// TODO move to INFO
LOG(ERROR) << "Ignore " << old_message_id << "/" << message_id << " received not through update from " << source LOG(ERROR) << "Ignore " << old_message_id << "/" << message_id << " received not through update from " << source
<< ": " << ": " << oneline(to_string(get_message_object(dialog_id, new_message.get(), "on_get_message")));
<< oneline(to_string(get_message_object(dialog_id, new_message.get()))); // TODO move to INFO
dump_debug_message_op(d, 3); // TODO remove
if (dialog_id.get_type() == DialogType::Channel && have_input_peer(dialog_id, AccessRights::Read)) { if (dialog_id.get_type() == DialogType::Channel && have_input_peer(dialog_id, AccessRights::Read)) {
channel_get_difference_retry_timeout_.add_timeout_in(dialog_id.get(), 0.001); channel_get_difference_retry_timeout_.add_timeout_in(dialog_id.get(), 0.001);
} }
@ -17180,7 +17259,7 @@ td_api::object_ptr<td_api::messageThreadInfo> MessagesManager::get_message_threa
messages.reserve(info.message_ids.size()); messages.reserve(info.message_ids.size());
for (auto message_id : info.message_ids) { for (auto message_id : info.message_ids) {
const Message *m = get_message_force(d, message_id, "get_message_thread_info_object"); const Message *m = get_message_force(d, message_id, "get_message_thread_info_object");
auto message = get_message_object(d->dialog_id, m); auto message = get_message_object(d->dialog_id, m, "get_message_thread_info_object");
if (message != nullptr) { if (message != nullptr) {
if (message->interaction_info_ != nullptr && message->interaction_info_->reply_info_ != nullptr) { if (message->interaction_info_ != nullptr && message->interaction_info_->reply_info_ != nullptr) {
reply_info = m->reply_info.get_message_reply_info_object(td_->contacts_manager_.get(), this); reply_info = m->reply_info.get_message_reply_info_object(td_->contacts_manager_.get(), this);
@ -17902,7 +17981,7 @@ td_api::object_ptr<td_api::messageLinkInfo> MessagesManager::get_message_link_in
} else { } else {
const Message *m = get_message(d, message_id); const Message *m = get_message(d, message_id);
if (m != nullptr) { if (m != nullptr) {
message = get_message_object(dialog_id, m); message = get_message_object(dialog_id, m, "get_message_link_info_object");
for_album = !info.is_single && m->media_album_id != 0; for_album = !info.is_single && m->media_album_id != 0;
for_comment = (info.comment_dialog_id.is_valid() || info.for_comment) && m->top_thread_message_id.is_valid(); for_comment = (info.comment_dialog_id.is_valid() || info.for_comment) && m->top_thread_message_id.is_valid();
if (can_message_content_have_media_timestamp(m->content.get())) { if (can_message_content_have_media_timestamp(m->content.get())) {
@ -20182,11 +20261,11 @@ td_api::object_ptr<td_api::chat> MessagesManager::get_chat_object(const Dialog *
d->dialog_id.get(), get_chat_type_object(d->dialog_id), get_dialog_title(d->dialog_id), d->dialog_id.get(), get_chat_type_object(d->dialog_id), get_dialog_title(d->dialog_id),
get_chat_photo_info_object(td_->file_manager_.get(), get_dialog_photo(d->dialog_id)), get_chat_photo_info_object(td_->file_manager_.get(), get_dialog_photo(d->dialog_id)),
get_dialog_permissions(d->dialog_id).get_chat_permissions_object(), get_dialog_permissions(d->dialog_id).get_chat_permissions_object(),
get_message_object(d->dialog_id, get_message(d, d->last_message_id)), get_chat_positions_object(d), get_message_object(d->dialog_id, get_message(d, d->last_message_id), "get_chat_object"),
d->is_marked_as_unread, d->is_blocked, get_dialog_has_scheduled_messages(d), can_delete_for_self, get_chat_positions_object(d), d->is_marked_as_unread, d->is_blocked, get_dialog_has_scheduled_messages(d),
can_delete_for_all_users, can_report_dialog(d->dialog_id), d->notification_settings.silent_send_message, can_delete_for_self, can_delete_for_all_users, can_report_dialog(d->dialog_id),
d->server_unread_count + d->local_unread_count, d->last_read_inbox_message_id.get(), d->notification_settings.silent_send_message, d->server_unread_count + d->local_unread_count,
d->last_read_outbox_message_id.get(), d->unread_mention_count, d->last_read_inbox_message_id.get(), d->last_read_outbox_message_id.get(), d->unread_mention_count,
get_chat_notification_settings_object(&d->notification_settings), get_chat_notification_settings_object(&d->notification_settings),
d->message_ttl_setting.get_message_ttl_setting_object(), get_dialog_theme_name(d), get_chat_action_bar_object(d), d->message_ttl_setting.get_message_ttl_setting_object(), get_dialog_theme_name(d), get_chat_action_bar_object(d),
get_voice_chat_object(d), d->reply_markup_message_id.get(), std::move(draft_message), d->client_data); get_voice_chat_object(d), d->reply_markup_message_id.get(), std::move(draft_message), d->client_data);
@ -20653,7 +20732,7 @@ tl_object_ptr<td_api::messages> MessagesManager::get_dialog_history(DialogId dia
vector<tl_object_ptr<td_api::message>> messages; vector<tl_object_ptr<td_api::message>> messages;
if (*p != nullptr && offset == 0) { if (*p != nullptr && offset == 0) {
while (*p != nullptr && messages.size() < static_cast<size_t>(limit)) { while (*p != nullptr && messages.size() < static_cast<size_t>(limit)) {
messages.push_back(get_message_object(dialog_id, *p)); messages.push_back(get_message_object(dialog_id, *p, "get_dialog_history"));
from_message_id = (*p)->message_id; from_message_id = (*p)->message_id;
from_the_end = false; from_the_end = false;
--p; --p;
@ -21896,11 +21975,11 @@ void MessagesManager::on_search_dialog_messages_db_result(int64 random_id, Dialo
} }
td_api::object_ptr<td_api::foundMessages> MessagesManager::get_found_messages_object( td_api::object_ptr<td_api::foundMessages> MessagesManager::get_found_messages_object(
const FoundMessages &found_messages) { const FoundMessages &found_messages, const char *source) {
vector<tl_object_ptr<td_api::message>> result; vector<tl_object_ptr<td_api::message>> result;
result.reserve(found_messages.full_message_ids.size()); result.reserve(found_messages.full_message_ids.size());
for (auto full_message_id : found_messages.full_message_ids) { for (auto full_message_id : found_messages.full_message_ids) {
auto message = get_message_object(full_message_id); auto message = get_message_object(full_message_id, source);
if (message != nullptr) { if (message != nullptr) {
result.push_back(std::move(message)); result.push_back(std::move(message));
} }
@ -22259,69 +22338,46 @@ tl_object_ptr<td_api::message> MessagesManager::get_dialog_message_by_date_objec
CHECK(it != get_dialog_message_by_date_results_.end()); CHECK(it != get_dialog_message_by_date_results_.end());
auto full_message_id = std::move(it->second); auto full_message_id = std::move(it->second);
get_dialog_message_by_date_results_.erase(it); get_dialog_message_by_date_results_.erase(it);
return get_message_object(full_message_id); return get_message_object(full_message_id, "get_dialog_message_by_date_object");
} }
int32 MessagesManager::get_dialog_message_count(DialogId dialog_id, MessageSearchFilter filter, bool return_local, void MessagesManager::get_dialog_message_count(DialogId dialog_id, MessageSearchFilter filter, bool return_local,
int64 &random_id, Promise<Unit> &&promise) { Promise<int32> &&promise) {
if (random_id != 0) {
// request has already been sent before
auto it = found_dialog_messages_.find(random_id);
CHECK(it != found_dialog_messages_.end());
auto result = std::move(it->second);
found_dialog_messages_.erase(it);
CHECK(found_dialog_messages_dialog_id_.count(random_id) == 0);
promise.set_value(Unit());
return result.first;
}
LOG(INFO) << "Get " << (return_local ? "local " : "") << "number of messages in " << dialog_id << " filtered by " LOG(INFO) << "Get " << (return_local ? "local " : "") << "number of messages in " << dialog_id << " filtered by "
<< filter; << filter;
const Dialog *d = get_dialog_force(dialog_id, "get_dialog_message_count"); const Dialog *d = get_dialog_force(dialog_id, "get_dialog_message_count");
if (d == nullptr) { if (d == nullptr) {
promise.set_error(Status::Error(400, "Chat not found")); return promise.set_error(Status::Error(400, "Chat not found"));
return -1;
} }
if (filter == MessageSearchFilter::Empty) { if (filter == MessageSearchFilter::Empty) {
promise.set_error(Status::Error(400, "Can't use searchMessagesFilterEmpty")); return promise.set_error(Status::Error(400, "Can't use searchMessagesFilterEmpty"));
return -1;
} }
auto dialog_type = dialog_id.get_type(); auto dialog_type = dialog_id.get_type();
int32 message_count = d->message_count_by_index[message_search_filter_index(filter)]; int32 message_count = d->message_count_by_index[message_search_filter_index(filter)];
if (message_count == -1) { if (message_count == -1 && filter == MessageSearchFilter::UnreadMention) {
if (filter == MessageSearchFilter::UnreadMention) { message_count = d->unread_mention_count;
message_count = d->unread_mention_count;
}
} }
if (message_count != -1 || return_local || dialog_type == DialogType::SecretChat || if (message_count != -1 || return_local || dialog_type == DialogType::SecretChat ||
filter == MessageSearchFilter::FailedToSend) { filter == MessageSearchFilter::FailedToSend) {
promise.set_value(Unit()); return promise.set_value(std::move(message_count));
return message_count;
} }
LOG(INFO) << "Get number of messages in " << dialog_id << " filtered by " << filter << " from the server"; LOG(INFO) << "Get number of messages in " << dialog_id << " filtered by " << filter << " from the server";
do {
random_id = Random::secure_int64();
} while (random_id == 0 || found_dialog_messages_.find(random_id) != found_dialog_messages_.end());
found_dialog_messages_[random_id]; // reserve place for result
switch (dialog_id.get_type()) { switch (dialog_id.get_type()) {
case DialogType::User: case DialogType::User:
case DialogType::Chat: case DialogType::Chat:
case DialogType::Channel: case DialogType::Channel:
td_->create_handler<SearchMessagesQuery>(std::move(promise)) td_->create_handler<GetSearchCountersQuery>(std::move(promise))->send(dialog_id, filter);
->send(dialog_id, "", DialogId(), MessageId(), 0, 1, filter, MessageId(), random_id);
break; break;
case DialogType::None: case DialogType::None:
case DialogType::SecretChat: case DialogType::SecretChat:
default: default:
UNREACHABLE(); UNREACHABLE();
} }
return -1;
} }
void MessagesManager::preload_newer_messages(const Dialog *d, MessageId max_message_id) { void MessagesManager::preload_newer_messages(const Dialog *d, MessageId max_message_id) {
@ -22539,7 +22595,8 @@ void MessagesManager::on_get_history_from_database(DialogId dialog_id, MessageId
<< ' ' << from_message_id << ' ' << offset << ' ' << limit << ' ' << from_the_end << ' ' << only_local << ' ' << from_message_id << ' ' << offset << ' ' << limit << ' ' << from_the_end << ' ' << only_local
<< ' ' << messages.size() << ' ' << debug_first_database_message_id << ' ' << last_added_message_id << ' ' << ' ' << messages.size() << ' ' << debug_first_database_message_id << ' ' << last_added_message_id << ' '
<< added_new_message << ' ' << pos << ' ' << m << ' ' << next_message << ' ' << old_message << ' ' << added_new_message << ' ' << pos << ' ' << m << ' ' << next_message << ' ' << old_message << ' '
<< to_string(get_message_object(dialog_id, m)) << to_string(get_message_object(dialog_id, next_message)); << to_string(get_message_object(dialog_id, m, "on_get_history_from_database"))
<< to_string(get_message_object(dialog_id, next_message, "on_get_history_from_database"));
LOG(INFO) << "Fix have_previous for " << next_message->message_id; LOG(INFO) << "Fix have_previous for " << next_message->message_id;
next_message->have_previous = true; next_message->have_previous = true;
attach_message_to_previous( attach_message_to_previous(
@ -23074,15 +23131,16 @@ tl_object_ptr<td_api::MessageSchedulingState> MessagesManager::get_message_sched
return td_api::make_object<td_api::messageSchedulingStateSendAtDate>(send_date); return td_api::make_object<td_api::messageSchedulingStateSendAtDate>(send_date);
} }
tl_object_ptr<td_api::message> MessagesManager::get_message_object(FullMessageId full_message_id) { tl_object_ptr<td_api::message> MessagesManager::get_message_object(FullMessageId full_message_id, const char *source) {
return get_message_object(full_message_id.get_dialog_id(), get_message_force(full_message_id, "get_message_object")); return get_message_object(full_message_id.get_dialog_id(), get_message_force(full_message_id, source), source);
} }
tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dialog_id, const Message *m, tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dialog_id, const Message *m,
bool for_event_log) const { const char *source, bool for_event_log) const {
if (m == nullptr) { if (m == nullptr) {
return nullptr; return nullptr;
} }
LOG_CHECK(have_dialog(dialog_id)) << source;
m->is_update_sent = true; m->is_update_sent = true;
@ -23169,9 +23227,8 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
int32 max_media_timestamp = int32 max_media_timestamp =
for_event_log ? get_message_own_max_media_timestamp(m) : get_message_max_media_timestamp(m); for_event_log ? get_message_own_max_media_timestamp(m) : get_message_max_media_timestamp(m);
bool has_timestamped_media = for_event_log || reply_to_message_id == 0 || m->max_own_media_timestamp >= 0; bool has_timestamped_media = for_event_log || reply_to_message_id == 0 || m->max_own_media_timestamp >= 0;
string source = PSTRING() << dialog_id << ' ' << m->message_id;
return make_tl_object<td_api::message>( return make_tl_object<td_api::message>(
m->message_id.get(), get_message_sender_object_const(m->sender_user_id, m->sender_dialog_id, source.c_str()), m->message_id.get(), get_message_sender_object_const(m->sender_user_id, m->sender_dialog_id, source),
dialog_id.get(), std::move(sending_state), std::move(scheduling_state), is_outgoing, is_pinned, can_be_edited, dialog_id.get(), std::move(sending_state), std::move(scheduling_state), is_outgoing, is_pinned, can_be_edited,
can_be_forwarded, can_delete_for_self, can_delete_for_all_users, can_get_statistics, can_get_message_thread, can_be_forwarded, can_delete_for_self, can_delete_for_all_users, can_get_statistics, can_get_message_thread,
can_get_viewers, can_get_media_timestamp_links, has_timestamped_media, m->is_channel_post, can_get_viewers, can_get_media_timestamp_links, has_timestamped_media, m->is_channel_post,
@ -23186,20 +23243,21 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
tl_object_ptr<td_api::messages> MessagesManager::get_messages_object(int32 total_count, DialogId dialog_id, tl_object_ptr<td_api::messages> MessagesManager::get_messages_object(int32 total_count, DialogId dialog_id,
const vector<MessageId> &message_ids, const vector<MessageId> &message_ids,
bool skip_not_found) { bool skip_not_found, const char *source) {
Dialog *d = get_dialog(dialog_id); Dialog *d = get_dialog(dialog_id);
CHECK(d != nullptr); CHECK(d != nullptr);
auto message_objects = transform(message_ids, [this, dialog_id, d](MessageId message_id) { auto message_objects = transform(message_ids, [this, dialog_id, d, source](MessageId message_id) {
return get_message_object(dialog_id, get_message_force(d, message_id, "get_messages_object")); return get_message_object(dialog_id, get_message_force(d, message_id, source), source);
}); });
return get_messages_object(total_count, std::move(message_objects), skip_not_found); return get_messages_object(total_count, std::move(message_objects), skip_not_found);
} }
tl_object_ptr<td_api::messages> MessagesManager::get_messages_object(int32 total_count, tl_object_ptr<td_api::messages> MessagesManager::get_messages_object(int32 total_count,
const vector<FullMessageId> &full_message_ids, const vector<FullMessageId> &full_message_ids,
bool skip_not_found) { bool skip_not_found, const char *source) {
auto message_objects = transform( auto message_objects = transform(full_message_ids, [this, source](FullMessageId full_message_id) {
full_message_ids, [this](FullMessageId full_message_id) { return get_message_object(full_message_id); }); return get_message_object(full_message_id, source);
});
return get_messages_object(total_count, std::move(message_objects), skip_not_found); return get_messages_object(total_count, std::move(message_objects), skip_not_found);
} }
@ -23714,7 +23772,7 @@ Result<td_api::object_ptr<td_api::message>> MessagesManager::send_message(
send_update_chat_last_message(d, "send_message"); send_update_chat_last_message(d, "send_message");
} }
return get_message_object(dialog_id, m); return get_message_object(dialog_id, m, "send_message");
} }
Result<InputMessageContent> MessagesManager::process_input_message_content( Result<InputMessageContent> MessagesManager::process_input_message_content(
@ -26593,7 +26651,7 @@ Result<td_api::object_ptr<td_api::messages>> MessagesManager::forward_messages(
forwarded_message_ids.push_back(message_id); forwarded_message_ids.push_back(message_id);
} }
result[forwarded_message_contents[j].index] = get_message_object(to_dialog_id, m, false); result[forwarded_message_contents[j].index] = get_message_object(to_dialog_id, m, "forward_messages");
} }
if (!forwarded_messages.empty()) { if (!forwarded_messages.empty()) {
@ -26629,7 +26687,7 @@ Result<td_api::object_ptr<td_api::messages>> MessagesManager::forward_messages(
send_update_new_message(to_dialog, m); send_update_new_message(to_dialog, m);
} }
result[copied_message.index] = get_message_object(to_dialog_id, m, false); result[copied_message.index] = get_message_object(to_dialog_id, m, "forward_messages");
} }
if (need_update_dialog_pos) { if (need_update_dialog_pos) {
@ -27255,8 +27313,9 @@ void MessagesManager::send_update_new_message(const Dialog *d, const Message *m)
CHECK(d != nullptr); CHECK(d != nullptr);
CHECK(m != nullptr); CHECK(m != nullptr);
CHECK(d->is_update_new_chat_sent); CHECK(d->is_update_new_chat_sent);
send_closure(G()->td(), &Td::send_update, send_closure(
make_tl_object<td_api::updateNewMessage>(get_message_object(d->dialog_id, m))); G()->td(), &Td::send_update,
make_tl_object<td_api::updateNewMessage>(get_message_object(d->dialog_id, m, "send_update_new_message")));
} }
MessagesManager::NotificationGroupInfo &MessagesManager::get_notification_group_info(Dialog *d, const Message *m) { MessagesManager::NotificationGroupInfo &MessagesManager::get_notification_group_info(Dialog *d, const Message *m) {
@ -28506,9 +28565,9 @@ void MessagesManager::send_update_message_send_succeeded(Dialog *d, MessageId ol
if (!td_->auth_manager_->is_bot()) { if (!td_->auth_manager_->is_bot()) {
d->yet_unsent_message_id_to_persistent_message_id.emplace(old_message_id, m->message_id); d->yet_unsent_message_id_to_persistent_message_id.emplace(old_message_id, m->message_id);
} }
send_closure( send_closure(G()->td(), &Td::send_update,
G()->td(), &Td::send_update, make_tl_object<td_api::updateMessageSendSucceeded>(
make_tl_object<td_api::updateMessageSendSucceeded>(get_message_object(d->dialog_id, m), old_message_id.get())); get_message_object(d->dialog_id, m, "send_update_message_send_succeeded"), old_message_id.get()));
} }
void MessagesManager::send_update_message_content(DialogId dialog_id, Message *m, bool is_message_in_dialog, void MessagesManager::send_update_message_content(DialogId dialog_id, Message *m, bool is_message_in_dialog,
@ -28640,7 +28699,8 @@ void MessagesManager::send_update_chat_last_message_impl(const Dialog *d, const
<< source; << source;
LOG(INFO) << "Send updateChatLastMessage in " << d->dialog_id << " to " << d->last_message_id << " from " << source; LOG(INFO) << "Send updateChatLastMessage in " << d->dialog_id << " to " << d->last_message_id << " from " << source;
auto update = make_tl_object<td_api::updateChatLastMessage>( auto update = make_tl_object<td_api::updateChatLastMessage>(
d->dialog_id.get(), get_message_object(d->dialog_id, get_message(d, d->last_message_id)), d->dialog_id.get(),
get_message_object(d->dialog_id, get_message(d, d->last_message_id), "send_update_chat_last_message_impl"),
get_chat_positions_object(d)); get_chat_positions_object(d));
send_closure(G()->td(), &Td::send_update, std::move(update)); send_closure(G()->td(), &Td::send_update, std::move(update));
} }
@ -29448,7 +29508,8 @@ void MessagesManager::on_send_message_fail(int64 random_id, Status error) {
} }
if (error.message() == "REPLY_MARKUP_INVALID") { if (error.message() == "REPLY_MARKUP_INVALID") {
if (m->reply_markup == nullptr) { if (m->reply_markup == nullptr) {
LOG(ERROR) << "Receive " << error.message() << " for " << oneline(to_string(get_message_object(dialog_id, m))); LOG(ERROR) << "Receive " << error.message() << " for "
<< oneline(to_string(get_message_object(dialog_id, m, "on_send_message_fail")));
} else { } else {
LOG(ERROR) << "Receive " << error.message() << " for " << full_message_id << " with keyboard " LOG(ERROR) << "Receive " << error.message() << " for " << full_message_id << " with keyboard "
<< *m->reply_markup; << *m->reply_markup;
@ -29595,8 +29656,8 @@ void MessagesManager::fail_send_message(FullMessageId full_message_id, int error
d->yet_unsent_message_id_to_persistent_message_id.emplace(old_message_id, m->message_id); d->yet_unsent_message_id_to_persistent_message_id.emplace(old_message_id, m->message_id);
} }
send_closure(G()->td(), &Td::send_update, send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateMessageSendFailed>(get_message_object(dialog_id, m), old_message_id.get(), make_tl_object<td_api::updateMessageSendFailed>(get_message_object(dialog_id, m, "fail_send_message"),
error_code, error_message)); old_message_id.get(), error_code, error_message));
if (need_update_dialog_pos) { if (need_update_dialog_pos) {
send_update_chat_last_message(d, "fail_send_message"); send_update_chat_last_message(d, "fail_send_message");
} }
@ -31869,11 +31930,11 @@ tl_object_ptr<td_api::ChatEventAction> MessagesManager::get_chat_event_action_ob
auto message = create_message( auto message = create_message(
parse_telegram_api_message(std::move(action->message_), false, "channelAdminLogEventActionUpdatePinned"), parse_telegram_api_message(std::move(action->message_), false, "channelAdminLogEventActionUpdatePinned"),
true); true);
if (message.second == nullptr) { if (message.second == nullptr || message.first != DialogId(channel_id)) {
LOG(ERROR) << "Failed to get pinned message"; LOG(ERROR) << "Failed to get pinned message";
return nullptr; return nullptr;
} }
auto message_object = get_message_object(message.first, message.second.get(), true); auto message_object = get_message_object(message.first, message.second.get(), "admin log", true);
if (message.second->is_pinned) { if (message.second->is_pinned) {
return make_tl_object<td_api::chatEventMessagePinned>(std::move(message_object)); return make_tl_object<td_api::chatEventMessagePinned>(std::move(message_object));
} else { } else {
@ -31888,19 +31949,20 @@ tl_object_ptr<td_api::ChatEventAction> MessagesManager::get_chat_event_action_ob
auto new_message = create_message(parse_telegram_api_message(std::move(action->new_message_), false, auto new_message = create_message(parse_telegram_api_message(std::move(action->new_message_), false,
"new channelAdminLogEventActionEditMessage"), "new channelAdminLogEventActionEditMessage"),
true); true);
if (old_message.second == nullptr || new_message.second == nullptr || old_message.first != new_message.first) { if (old_message.second == nullptr || new_message.second == nullptr || old_message.first != new_message.first ||
old_message.first != DialogId(channel_id)) {
LOG(ERROR) << "Failed to get edited message"; LOG(ERROR) << "Failed to get edited message";
return nullptr; return nullptr;
} }
return make_tl_object<td_api::chatEventMessageEdited>( return make_tl_object<td_api::chatEventMessageEdited>(
get_message_object(old_message.first, old_message.second.get(), true), get_message_object(old_message.first, old_message.second.get(), "admin log", true),
get_message_object(new_message.first, new_message.second.get(), true)); get_message_object(new_message.first, new_message.second.get(), "admin log", true));
} }
case telegram_api::channelAdminLogEventActionStopPoll::ID: { case telegram_api::channelAdminLogEventActionStopPoll::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionStopPoll>(action_ptr); auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionStopPoll>(action_ptr);
auto message = create_message( auto message = create_message(
parse_telegram_api_message(std::move(action->message_), false, "channelAdminLogEventActionStopPoll"), true); parse_telegram_api_message(std::move(action->message_), false, "channelAdminLogEventActionStopPoll"), true);
if (message.second == nullptr) { if (message.second == nullptr || message.first != DialogId(channel_id)) {
LOG(ERROR) << "Failed to get stopped poll message"; LOG(ERROR) << "Failed to get stopped poll message";
return nullptr; return nullptr;
} }
@ -31909,19 +31971,19 @@ tl_object_ptr<td_api::ChatEventAction> MessagesManager::get_chat_event_action_ob
return nullptr; return nullptr;
} }
return make_tl_object<td_api::chatEventPollStopped>( return make_tl_object<td_api::chatEventPollStopped>(
get_message_object(message.first, message.second.get(), true)); get_message_object(message.first, message.second.get(), "admin log", true));
} }
case telegram_api::channelAdminLogEventActionDeleteMessage::ID: { case telegram_api::channelAdminLogEventActionDeleteMessage::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionDeleteMessage>(action_ptr); auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionDeleteMessage>(action_ptr);
auto message = create_message( auto message = create_message(
parse_telegram_api_message(std::move(action->message_), false, "channelAdminLogEventActionDeleteMessage"), parse_telegram_api_message(std::move(action->message_), false, "channelAdminLogEventActionDeleteMessage"),
true); true);
if (message.second == nullptr) { if (message.second == nullptr || message.first != DialogId(channel_id)) {
LOG(ERROR) << "Failed to get deleted message"; LOG(ERROR) << "Failed to get deleted message";
return nullptr; return nullptr;
} }
return make_tl_object<td_api::chatEventMessageDeleted>( return make_tl_object<td_api::chatEventMessageDeleted>(
get_message_object(message.first, message.second.get(), true)); get_message_object(message.first, message.second.get(), "admin log", true));
} }
case telegram_api::channelAdminLogEventActionChangeStickerSet::ID: { case telegram_api::channelAdminLogEventActionChangeStickerSet::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionChangeStickerSet>(action_ptr); auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionChangeStickerSet>(action_ptr);
@ -32500,7 +32562,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
<< ". The maximum allowed is " << max_message_id << ", last is " << d->last_message_id << ". The maximum allowed is " << max_message_id << ", last is " << d->last_message_id
<< ", being added message is " << d->being_added_message_id << ", channel difference " << ", being added message is " << d->being_added_message_id << ", channel difference "
<< debug_channel_difference_dialog_ << " " << debug_channel_difference_dialog_ << " "
<< to_string(get_message_object(dialog_id, message.get())); << to_string(get_message_object(dialog_id, message.get(), "add_message_to_dialog"));
dump_debug_message_op(d, 3); dump_debug_message_op(d, 3);
if (need_channel_difference_to_add_message(dialog_id, nullptr)) { if (need_channel_difference_to_add_message(dialog_id, nullptr)) {
@ -33936,8 +33998,8 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
LOG_IF(ERROR, old_message->edit_date == 0 && is_new_available && !replace_legacy) LOG_IF(ERROR, old_message->edit_date == 0 && is_new_available && !replace_legacy)
<< "Disable_notification has changed from " << old_message->disable_notification << " to " << "Disable_notification has changed from " << old_message->disable_notification << " to "
<< new_message->disable_notification << new_message->disable_notification
<< ". Old message: " << to_string(get_message_object(dialog_id, old_message)) << ". Old message: " << to_string(get_message_object(dialog_id, old_message, "update_message"))
<< ". New message: " << to_string(get_message_object(dialog_id, new_message.get())); << ". New message: " << to_string(get_message_object(dialog_id, new_message.get(), "update_message"));
// disable_notification flag shouldn't be changed, because we are unable to show/hide message notification // disable_notification flag shouldn't be changed, because we are unable to show/hide message notification
// old_message->disable_notification = new_message->disable_notification; // old_message->disable_notification = new_message->disable_notification;
// need_send_update = true; // need_send_update = true;
@ -34035,8 +34097,9 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
if (need_message_changed_warning(old_message) && is_new_available) { if (need_message_changed_warning(old_message) && is_new_available) {
LOG(ERROR) << message_id << " in " << dialog_id << " sent by " << old_message->sender_user_id << "/" LOG(ERROR) << message_id << " in " << dialog_id << " sent by " << old_message->sender_user_id << "/"
<< old_message->sender_dialog_id << " has lost reply markup " << *old_message->reply_markup << old_message->sender_dialog_id << " has lost reply markup " << *old_message->reply_markup
<< ". Old message: " << to_string(get_message_object(dialog_id, old_message)) << ". Old message: " << to_string(get_message_object(dialog_id, old_message, "update_message"))
<< ". New message: " << to_string(get_message_object(dialog_id, new_message.get())); << ". New message: "
<< to_string(get_message_object(dialog_id, new_message.get(), "update_message"));
} }
} }
} }

View File

@ -214,6 +214,9 @@ class MessagesManager final : public Actor {
vector<tl_object_ptr<telegram_api::Message>> &&messages); vector<tl_object_ptr<telegram_api::Message>> &&messages);
void on_failed_dialog_messages_search(DialogId dialog_id, int64 random_id); void on_failed_dialog_messages_search(DialogId dialog_id, int64 random_id);
void on_get_dialog_message_count(DialogId dialog_id, MessageSearchFilter filter, int32 total_count,
Promise<int32> &&promise);
void on_get_messages_search_result(const string &query, int32 offset_date, DialogId offset_dialog_id, void on_get_messages_search_result(const string &query, int32 offset_date, DialogId offset_dialog_id,
MessageId offset_message_id, int32 limit, MessageSearchFilter filter, MessageId offset_message_id, int32 limit, MessageSearchFilter filter,
int32 min_date, int32 max_date, int64 random_id, int32 total_count, int32 min_date, int32 max_date, int64 random_id, int32 total_count,
@ -702,7 +705,8 @@ class MessagesManager final : public Actor {
int32 total_count = 0; int32 total_count = 0;
}; };
td_api::object_ptr<td_api::foundMessages> get_found_messages_object(const FoundMessages &found_messages); td_api::object_ptr<td_api::foundMessages> get_found_messages_object(const FoundMessages &found_messages,
const char *source);
FoundMessages offline_search_messages(DialogId dialog_id, const string &query, const string &offset, int32 limit, FoundMessages offline_search_messages(DialogId dialog_id, const string &query, const string &offset, int32 limit,
MessageSearchFilter filter, int64 &random_id, Promise<> &&promise); MessageSearchFilter filter, int64 &random_id, Promise<> &&promise);
@ -728,8 +732,8 @@ class MessagesManager final : public Actor {
void on_get_dialog_message_by_date_fail(int64 random_id); void on_get_dialog_message_by_date_fail(int64 random_id);
int32 get_dialog_message_count(DialogId dialog_id, MessageSearchFilter filter, bool return_local, int64 &random_id, void get_dialog_message_count(DialogId dialog_id, MessageSearchFilter filter, bool return_local,
Promise<Unit> &&promise); Promise<int32> &&promise);
vector<MessageId> get_dialog_scheduled_messages(DialogId dialog_id, bool force, bool ignore_result, vector<MessageId> get_dialog_scheduled_messages(DialogId dialog_id, bool force, bool ignore_result,
Promise<Unit> &&promise); Promise<Unit> &&promise);
@ -739,13 +743,14 @@ class MessagesManager final : public Actor {
tl_object_ptr<td_api::message> get_dialog_message_by_date_object(int64 random_id); tl_object_ptr<td_api::message> get_dialog_message_by_date_object(int64 random_id);
tl_object_ptr<td_api::message> get_message_object(FullMessageId full_message_id); tl_object_ptr<td_api::message> get_message_object(FullMessageId full_message_id, const char *source);
tl_object_ptr<td_api::messages> get_messages_object(int32 total_count, DialogId dialog_id, tl_object_ptr<td_api::messages> get_messages_object(int32 total_count, DialogId dialog_id,
const vector<MessageId> &message_ids, bool skip_not_found); const vector<MessageId> &message_ids, bool skip_not_found,
const char *source);
tl_object_ptr<td_api::messages> get_messages_object(int32 total_count, const vector<FullMessageId> &full_message_ids, tl_object_ptr<td_api::messages> get_messages_object(int32 total_count, const vector<FullMessageId> &full_message_ids,
bool skip_not_found); bool skip_not_found, const char *source);
void process_pts_update(tl_object_ptr<telegram_api::Update> &&update); void process_pts_update(tl_object_ptr<telegram_api::Update> &&update);
@ -2350,7 +2355,7 @@ class MessagesManager final : public Actor {
static tl_object_ptr<td_api::MessageSchedulingState> get_message_scheduling_state_object(int32 send_date); static tl_object_ptr<td_api::MessageSchedulingState> get_message_scheduling_state_object(int32 send_date);
tl_object_ptr<td_api::message> get_message_object(DialogId dialog_id, const Message *m, tl_object_ptr<td_api::message> get_message_object(DialogId dialog_id, const Message *m, const char *source,
bool for_event_log = false) const; bool for_event_log = false) const;
static tl_object_ptr<td_api::messages> get_messages_object(int32 total_count, static tl_object_ptr<td_api::messages> get_messages_object(int32 total_count,

View File

@ -42,7 +42,8 @@ class NotificationTypeMessage final : public NotificationType {
} }
td_api::object_ptr<td_api::NotificationType> get_notification_type_object(DialogId dialog_id) const final { td_api::object_ptr<td_api::NotificationType> get_notification_type_object(DialogId dialog_id) const final {
auto message_object = G()->td().get_actor_unsafe()->messages_manager_->get_message_object({dialog_id, message_id_}); auto message_object = G()->td().get_actor_unsafe()->messages_manager_->get_message_object(
{dialog_id, message_id_}, "get_notification_type_object");
if (message_object == nullptr) { if (message_object == nullptr) {
return nullptr; return nullptr;
} }

View File

@ -471,9 +471,11 @@ class SaveAppLogQuery final : public Td::ResultHandler {
} }
}; };
class TestQuery final : public Td::ResultHandler { class TestNetworkQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public: public:
explicit TestQuery(uint64 request_id) : request_id_(request_id) { explicit TestNetworkQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
} }
void send() { void send() {
@ -486,17 +488,14 @@ class TestQuery final : public Td::ResultHandler {
return on_error(id, Status::Error(500, "Fetch failed")); return on_error(id, Status::Error(500, "Fetch failed"));
} }
LOG(DEBUG) << "TestOK: " << to_string(result_ptr.ok()); LOG(DEBUG) << "TestNetwork OK: " << to_string(result_ptr.ok());
send_closure(G()->td(), &Td::send_result, request_id_, make_tl_object<td_api::ok>()); promise_.set_value(Unit());
} }
void on_error(uint64 id, Status status) final { void on_error(uint64 id, Status status) final {
status.ignore();
LOG(ERROR) << "Test query failed: " << status; LOG(ERROR) << "Test query failed: " << status;
promise_.set_error(std::move(status));
} }
private:
uint64 request_id_;
}; };
class TestProxyRequest final : public RequestOnceActor { class TestProxyRequest final : public RequestOnceActor {
@ -987,7 +986,7 @@ class GetMessageRequest final : public RequestOnceActor {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_message_object(full_message_id_)); send_result(td->messages_manager_->get_message_object(full_message_id_, "GetMessageRequest"));
} }
public: public:
@ -1008,7 +1007,7 @@ class GetRepliedMessageRequest final : public RequestOnceActor {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_message_object(replied_message_id_)); send_result(td->messages_manager_->get_message_object(replied_message_id_, "GetRepliedMessageRequest"));
} }
public: public:
@ -1056,7 +1055,8 @@ class GetChatPinnedMessageRequest final : public RequestOnceActor {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_message_object({dialog_id_, pinned_message_id_})); send_result(
td->messages_manager_->get_message_object({dialog_id_, pinned_message_id_}, "GetChatPinnedMessageRequest"));
} }
public: public:
@ -1076,7 +1076,7 @@ class GetCallbackQueryMessageRequest final : public RequestOnceActor {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_message_object({dialog_id_, message_id_})); send_result(td->messages_manager_->get_message_object({dialog_id_, message_id_}, "GetCallbackQueryMessageRequest"));
} }
public: public:
@ -1098,7 +1098,7 @@ class GetMessagesRequest final : public RequestOnceActor {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_messages_object(-1, dialog_id_, message_ids_, false)); send_result(td->messages_manager_->get_messages_object(-1, dialog_id_, message_ids_, false, "GetMessagesRequest"));
} }
public: public:
@ -1170,7 +1170,7 @@ class EditMessageTextRequest final : public RequestOnceActor {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_message_object(full_message_id_)); send_result(td->messages_manager_->get_message_object(full_message_id_, "EditMessageTextRequest"));
} }
public: public:
@ -1197,7 +1197,7 @@ class EditMessageLiveLocationRequest final : public RequestOnceActor {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_message_object(full_message_id_)); send_result(td->messages_manager_->get_message_object(full_message_id_, "EditMessageLiveLocationRequest"));
} }
public: public:
@ -1224,7 +1224,7 @@ class EditMessageMediaRequest final : public RequestOnceActor {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_message_object(full_message_id_)); send_result(td->messages_manager_->get_message_object(full_message_id_, "EditMessageMediaRequest"));
} }
public: public:
@ -1249,7 +1249,7 @@ class EditMessageCaptionRequest final : public RequestOnceActor {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_message_object(full_message_id_)); send_result(td->messages_manager_->get_message_object(full_message_id_, "EditMessageCaptionRequest"));
} }
public: public:
@ -1272,7 +1272,7 @@ class EditMessageReplyMarkupRequest final : public RequestOnceActor {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_message_object(full_message_id_)); send_result(td->messages_manager_->get_message_object(full_message_id_, "EditMessageReplyMarkupRequest"));
} }
public: public:
@ -1333,7 +1333,8 @@ class GetMessageThreadHistoryRequest final : public RequestActor<> {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_messages_object(-1, messages_.first, messages_.second, true)); send_result(td->messages_manager_->get_messages_object(-1, messages_.first, messages_.second, true,
"GetMessageThreadHistoryRequest"));
} }
public: public:
@ -1370,7 +1371,8 @@ class SearchChatMessagesRequest final : public RequestActor<> {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_messages_object(messages_.first, dialog_id_, messages_.second, true)); send_result(td->messages_manager_->get_messages_object(messages_.first, dialog_id_, messages_.second, true,
"SearchChatMessagesRequest"));
} }
void do_send_error(Status &&status) final { void do_send_error(Status &&status) final {
@ -1416,7 +1418,7 @@ class SearchSecretMessagesRequest final : public RequestActor<> {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_found_messages_object(found_messages_)); send_result(td->messages_manager_->get_found_messages_object(found_messages_, "SearchSecretMessagesRequest"));
} }
public: public:
@ -1454,7 +1456,8 @@ class SearchMessagesRequest final : public RequestActor<> {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_messages_object(messages_.first, messages_.second, true)); send_result(
td->messages_manager_->get_messages_object(messages_.first, messages_.second, true, "SearchMessagesRequest"));
} }
void do_send_error(Status &&status) final { void do_send_error(Status &&status) final {
@ -1499,7 +1502,8 @@ class SearchCallMessagesRequest final : public RequestActor<> {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_messages_object(messages_.first, messages_.second, true)); send_result(td->messages_manager_->get_messages_object(messages_.first, messages_.second, true,
"SearchCallMessagesRequest"));
} }
public: public:
@ -1526,7 +1530,8 @@ class SearchChatRecentLocationMessagesRequest final : public RequestActor<> {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_messages_object(messages_.first, dialog_id_, messages_.second, true)); send_result(td->messages_manager_->get_messages_object(messages_.first, dialog_id_, messages_.second, true,
"SearchChatRecentLocationMessagesRequest"));
} }
public: public:
@ -1543,7 +1548,8 @@ class GetActiveLiveLocationMessagesRequest final : public RequestActor<> {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_messages_object(-1, full_message_ids_, true)); send_result(td->messages_manager_->get_messages_object(-1, full_message_ids_, true,
"GetActiveLiveLocationMessagesRequest"));
} }
public: public:
@ -1572,34 +1578,6 @@ class GetChatMessageByDateRequest final : public RequestOnceActor {
} }
}; };
class GetChatMessageCountRequest final : public RequestActor<> {
DialogId dialog_id_;
MessageSearchFilter filter_;
bool return_local_;
int64 random_id_;
int32 result_ = 0;
void do_run(Promise<Unit> &&promise) final {
result_ = td->messages_manager_->get_dialog_message_count(dialog_id_, filter_, return_local_, random_id_,
std::move(promise));
}
void do_send_result() final {
send_result(td_api::make_object<td_api::count>(result_));
}
public:
GetChatMessageCountRequest(ActorShared<Td> td, uint64 request_id, int64 dialog_id,
tl_object_ptr<td_api::SearchMessagesFilter> filter, bool return_local)
: RequestActor(std::move(td), request_id)
, dialog_id_(dialog_id)
, filter_(get_message_search_filter(filter))
, return_local_(return_local)
, random_id_(0) {
}
};
class GetChatScheduledMessagesRequest final : public RequestActor<> { class GetChatScheduledMessagesRequest final : public RequestActor<> {
DialogId dialog_id_; DialogId dialog_id_;
@ -1611,7 +1589,8 @@ class GetChatScheduledMessagesRequest final : public RequestActor<> {
} }
void do_send_result() final { void do_send_result() final {
send_result(td->messages_manager_->get_messages_object(-1, dialog_id_, message_ids_, true)); send_result(td->messages_manager_->get_messages_object(-1, dialog_id_, message_ids_, true,
"GetChatScheduledMessagesRequest"));
} }
public: public:
@ -3268,30 +3247,19 @@ td_api::object_ptr<td_api::Object> Td::static_request(td_api::object_ptr<td_api:
} }
void Td::add_handler(uint64 id, std::shared_ptr<ResultHandler> handler) { void Td::add_handler(uint64 id, std::shared_ptr<ResultHandler> handler) {
result_handlers_.emplace_back(id, handler); result_handlers_[id] = std::move(handler);
} }
std::shared_ptr<Td::ResultHandler> Td::extract_handler(uint64 id) { std::shared_ptr<Td::ResultHandler> Td::extract_handler(uint64 id) {
std::shared_ptr<Td::ResultHandler> result; auto it = result_handlers_.find(id);
for (size_t i = 0; i < result_handlers_.size(); i++) { if (it == result_handlers_.end()) {
if (result_handlers_[i].first == id) { return nullptr;
result = std::move(result_handlers_[i].second);
result_handlers_.erase(result_handlers_.begin() + i);
break;
}
} }
auto result = std::move(it->second);
result_handlers_.erase(it);
return result; return result;
} }
void Td::invalidate_handler(ResultHandler *handler) {
for (size_t i = 0; i < result_handlers_.size(); i++) {
if (result_handlers_[i].second.get() == handler) {
result_handlers_.erase(result_handlers_.begin() + i);
i--;
}
}
}
void Td::send(NetQueryPtr &&query) { void Td::send(NetQueryPtr &&query) {
VLOG(net_query) << "Send " << query << " to dispatcher"; VLOG(net_query) << "Send " << query << " to dispatcher";
query->debug("Td: send to NetQueryDispatcher"); query->debug("Td: send to NetQueryDispatcher");
@ -3655,10 +3623,6 @@ void Td::dec_request_actor_refcnt() {
} }
} }
void Td::clear_handlers() {
result_handlers_.clear();
}
void Td::clear_requests() { void Td::clear_requests() {
while (!pending_alarms_.empty()) { while (!pending_alarms_.empty()) {
auto it = pending_alarms_.begin(); auto it = pending_alarms_.begin();
@ -3702,7 +3666,7 @@ void Td::clear() {
LOG(DEBUG) << "Options was cleared" << timer; LOG(DEBUG) << "Options was cleared" << timer;
G()->net_query_creator().stop_check(); G()->net_query_creator().stop_check();
clear_handlers(); result_handlers_.clear();
LOG(DEBUG) << "Handlers was cleared" << timer; LOG(DEBUG) << "Handlers was cleared" << timer;
G()->net_query_dispatcher().stop(); G()->net_query_dispatcher().stop();
LOG(DEBUG) << "NetQueryDispatcher was stopped" << timer; LOG(DEBUG) << "NetQueryDispatcher was stopped" << timer;
@ -4946,7 +4910,8 @@ void Td::on_request(uint64 id, const td_api::getMessage &request) {
void Td::on_request(uint64 id, const td_api::getMessageLocally &request) { void Td::on_request(uint64 id, const td_api::getMessageLocally &request) {
FullMessageId full_message_id(DialogId(request.chat_id_), MessageId(request.message_id_)); FullMessageId full_message_id(DialogId(request.chat_id_), MessageId(request.message_id_));
send_closure(actor_id(this), &Td::send_result, id, messages_manager_->get_message_object(full_message_id)); send_closure(actor_id(this), &Td::send_result, id,
messages_manager_->get_message_object(full_message_id, "getMessageLocally"));
} }
void Td::on_request(uint64 id, const td_api::getRepliedMessage &request) { void Td::on_request(uint64 id, const td_api::getRepliedMessage &request) {
@ -5484,7 +5449,16 @@ void Td::on_request(uint64 id, const td_api::getChatMessageByDate &request) {
void Td::on_request(uint64 id, td_api::getChatMessageCount &request) { void Td::on_request(uint64 id, td_api::getChatMessageCount &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_REQUEST(GetChatMessageCountRequest, request.chat_id_, std::move(request.filter_), request.return_local_); CREATE_REQUEST_PROMISE();
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<int32> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
promise.set_value(make_tl_object<td_api::count>(result.move_as_ok()));
}
});
messages_manager_->get_dialog_message_count(DialogId(request.chat_id_), get_message_search_filter(request.filter_),
request.return_local_, std::move(query_promise));
} }
void Td::on_request(uint64 id, const td_api::getChatScheduledMessages &request) { void Td::on_request(uint64 id, const td_api::getChatScheduledMessages &request) {
@ -5556,7 +5530,7 @@ void Td::on_request(uint64 id, td_api::sendMessageAlbum &request) {
} }
send_closure(actor_id(this), &Td::send_result, id, send_closure(actor_id(this), &Td::send_result, id,
messages_manager_->get_messages_object(-1, dialog_id, r_message_ids.ok(), false)); messages_manager_->get_messages_object(-1, dialog_id, r_message_ids.ok(), false, "sendMessageAlbum"));
} }
void Td::on_request(uint64 id, td_api::sendBotStartMessage &request) { void Td::on_request(uint64 id, td_api::sendBotStartMessage &request) {
@ -5572,7 +5546,7 @@ void Td::on_request(uint64 id, td_api::sendBotStartMessage &request) {
CHECK(r_new_message_id.ok().is_valid() || r_new_message_id.ok().is_valid_scheduled()); CHECK(r_new_message_id.ok().is_valid() || r_new_message_id.ok().is_valid_scheduled());
send_closure(actor_id(this), &Td::send_result, id, send_closure(actor_id(this), &Td::send_result, id,
messages_manager_->get_message_object({dialog_id, r_new_message_id.ok()})); messages_manager_->get_message_object({dialog_id, r_new_message_id.ok()}, "sendBotStartMessage"));
} }
void Td::on_request(uint64 id, td_api::sendInlineQueryResultMessage &request) { void Td::on_request(uint64 id, td_api::sendInlineQueryResultMessage &request) {
@ -5588,8 +5562,9 @@ void Td::on_request(uint64 id, td_api::sendInlineQueryResultMessage &request) {
} }
CHECK(r_new_message_id.ok().is_valid() || r_new_message_id.ok().is_valid_scheduled()); CHECK(r_new_message_id.ok().is_valid() || r_new_message_id.ok().is_valid_scheduled());
send_closure(actor_id(this), &Td::send_result, id, send_closure(
messages_manager_->get_message_object({dialog_id, r_new_message_id.ok()})); actor_id(this), &Td::send_result, id,
messages_manager_->get_message_object({dialog_id, r_new_message_id.ok()}, "sendInlineQueryResultMessage"));
} }
void Td::on_request(uint64 id, td_api::addLocalMessage &request) { void Td::on_request(uint64 id, td_api::addLocalMessage &request) {
@ -5605,7 +5580,7 @@ void Td::on_request(uint64 id, td_api::addLocalMessage &request) {
CHECK(r_new_message_id.ok().is_valid()); CHECK(r_new_message_id.ok().is_valid());
send_closure(actor_id(this), &Td::send_result, id, send_closure(actor_id(this), &Td::send_result, id,
messages_manager_->get_message_object({dialog_id, r_new_message_id.ok()})); messages_manager_->get_message_object({dialog_id, r_new_message_id.ok()}, "addLocalMessage"));
} }
void Td::on_request(uint64 id, td_api::editMessageText &request) { void Td::on_request(uint64 id, td_api::editMessageText &request) {
@ -5754,7 +5729,7 @@ void Td::on_request(uint64 id, const td_api::resendMessages &request) {
} }
send_closure(actor_id(this), &Td::send_result, id, send_closure(actor_id(this), &Td::send_result, id,
messages_manager_->get_messages_object(-1, dialog_id, r_message_ids.ok(), false)); messages_manager_->get_messages_object(-1, dialog_id, r_message_ids.ok(), false, "resendMessages"));
} }
void Td::on_request(uint64 id, td_api::getWebPagePreview &request) { void Td::on_request(uint64 id, td_api::getWebPagePreview &request) {
@ -8516,7 +8491,8 @@ td_api::object_ptr<td_api::Object> Td::do_static_request(td_api::testReturnError
// test // test
void Td::on_request(uint64 id, const td_api::testNetwork &request) { void Td::on_request(uint64 id, const td_api::testNetwork &request) {
create_handler<TestQuery>(id)->send(); CREATE_OK_REQUEST_PROMISE();
create_handler<TestNetworkQuery>(std::move(promise))->send();
} }
void Td::on_request(uint64 id, td_api::testProxy &request) { void Td::on_request(uint64 id, td_api::testProxy &request) {

View File

@ -300,7 +300,7 @@ class Td final : public Actor {
enum class State : int32 { WaitParameters, Decrypt, Run, Close } state_ = State::WaitParameters; enum class State : int32 { WaitParameters, Decrypt, Run, Close } state_ = State::WaitParameters;
bool is_database_encrypted_ = false; bool is_database_encrypted_ = false;
vector<std::pair<uint64, std::shared_ptr<ResultHandler>>> result_handlers_; std::unordered_map<uint64, std::shared_ptr<ResultHandler>> result_handlers_;
enum : int8 { RequestActorIdType = 1, ActorIdType = 2 }; enum : int8 { RequestActorIdType = 1, ActorIdType = 2 };
Container<ActorOwn<Actor>> request_actors_; Container<ActorOwn<Actor>> request_actors_;
@ -341,15 +341,11 @@ class Td final : public Actor {
template <class T> template <class T>
friend class RequestActor; // uses send_result/send_error friend class RequestActor; // uses send_result/send_error
friend class TestQuery; // uses send_result/send_error, TODO pass Promise<>
friend class AuthManager; // uses send_result/send_error, TODO pass Promise<> friend class AuthManager; // uses send_result/send_error, TODO pass Promise<>
friend class PhoneNumberManager; // uses send_result/send_error, TODO pass Promise<> friend class PhoneNumberManager; // uses send_result/send_error, TODO pass Promise<>
void add_handler(uint64 id, std::shared_ptr<ResultHandler> handler); void add_handler(uint64 id, std::shared_ptr<ResultHandler> handler);
std::shared_ptr<ResultHandler> extract_handler(uint64 id); std::shared_ptr<ResultHandler> extract_handler(uint64 id);
void invalidate_handler(ResultHandler *handler);
void clear_handlers();
// void destroy_handler(ResultHandler *handler);
void clear_requests(); void clear_requests();