Send stats.getMessagePublicForwards to the correct DC.

This commit is contained in:
levlam 2021-09-24 09:07:38 +03:00
parent bc4058b8be
commit e212d1293d
4 changed files with 42 additions and 20 deletions

View File

@ -357,6 +357,8 @@ class ContactsManager final : public Actor {
void delete_dialog(DialogId dialog_id, Promise<Unit> &&promise); void delete_dialog(DialogId dialog_id, Promise<Unit> &&promise);
void get_channel_statistics_dc_id(DialogId dialog_id, bool for_full_statistics, Promise<DcId> &&promise);
void get_channel_statistics(DialogId dialog_id, bool is_dark, void get_channel_statistics(DialogId dialog_id, bool is_dark,
Promise<td_api::object_ptr<td_api::ChatStatistics>> &&promise); Promise<td_api::object_ptr<td_api::ChatStatistics>> &&promise);
@ -1525,8 +1527,6 @@ class ContactsManager final : public Actor {
void delete_channel(ChannelId channel_id, Promise<Unit> &&promise); void delete_channel(ChannelId channel_id, Promise<Unit> &&promise);
void get_channel_statistics_dc_id(DialogId dialog_id, bool for_full_statistics, Promise<DcId> &&promise);
void get_channel_statistics_dc_id_impl(ChannelId channel_id, bool for_full_statistics, Promise<DcId> &&promise); void get_channel_statistics_dc_id_impl(ChannelId channel_id, bool for_full_statistics, Promise<DcId> &&promise);
void send_get_channel_stats_query(DcId dc_id, ChannelId channel_id, bool is_dark, void send_get_channel_stats_query(DcId dc_id, ChannelId channel_id, bool is_dark,

View File

@ -2477,7 +2477,7 @@ class GetMessagePublicForwardsQuery final : public Td::ResultHandler {
: promise_(std::move(promise)) { : promise_(std::move(promise)) {
} }
void send(FullMessageId full_message_id, int32 offset_date, DialogId offset_dialog_id, void send(DcId dc_id, FullMessageId full_message_id, int32 offset_date, DialogId offset_dialog_id,
ServerMessageId offset_message_id, int32 limit) { ServerMessageId offset_message_id, int32 limit) {
dialog_id_ = full_message_id.get_dialog_id(); dialog_id_ = full_message_id.get_dialog_id();
limit_ = limit; limit_ = limit;
@ -2485,10 +2485,12 @@ class GetMessagePublicForwardsQuery final : public Td::ResultHandler {
auto input_peer = MessagesManager::get_input_peer_force(offset_dialog_id); auto input_peer = MessagesManager::get_input_peer_force(offset_dialog_id);
CHECK(input_peer != nullptr); CHECK(input_peer != nullptr);
send_query(G()->net_query_creator().create(telegram_api::stats_getMessagePublicForwards( send_query(
td->contacts_manager_->get_input_channel(dialog_id_.get_channel_id()), G()->net_query_creator().create(telegram_api::stats_getMessagePublicForwards(
full_message_id.get_message_id().get_server_message_id().get(), offset_date, std::move(input_peer), td->contacts_manager_->get_input_channel(dialog_id_.get_channel_id()),
offset_message_id.get(), limit))); full_message_id.get_message_id().get_server_message_id().get(), offset_date,
std::move(input_peer), offset_message_id.get(), limit),
dc_id));
} }
void on_result(uint64 id, BufferSlice packet) final { void on_result(uint64 id, BufferSlice packet) final {
@ -9223,14 +9225,8 @@ void MessagesManager::get_channel_difference_if_needed(DialogId dialog_id, Messa
void MessagesManager::get_channel_differences_if_needed(MessagesInfo &&messages_info, Promise<MessagesInfo> &&promise) { void MessagesManager::get_channel_differences_if_needed(MessagesInfo &&messages_info, Promise<MessagesInfo> &&promise) {
MultiPromiseActorSafe mpas{"GetChannelDifferencesIfNeededMultiPromiseActor"}; MultiPromiseActorSafe mpas{"GetChannelDifferencesIfNeededMultiPromiseActor"};
mpas.add_promise(Promise<Unit>());
mpas.set_ignore_errors(true); mpas.set_ignore_errors(true);
mpas.add_promise(PromiseCreator::lambda(
[messages_info = std::move(messages_info), promise = std::move(promise)](Unit ignored) mutable {
if (G()->close_flag()) {
return promise.set_error(Status::Error(500, "Request aborted"));
}
promise.set_value(std::move(messages_info));
}));
auto lock = mpas.get_promise(); auto lock = mpas.get_promise();
for (auto &message : messages_info.messages) { for (auto &message : messages_info.messages) {
if (message == nullptr) { if (message == nullptr) {
@ -9242,6 +9238,14 @@ void MessagesManager::get_channel_differences_if_needed(MessagesInfo &&messages_
run_after_channel_difference(dialog_id, mpas.get_promise()); run_after_channel_difference(dialog_id, mpas.get_promise());
} }
} }
// must be added after messages_info is checked
mpas.add_promise(PromiseCreator::lambda(
[messages_info = std::move(messages_info), promise = std::move(promise)](Unit ignored) mutable {
if (G()->close_flag()) {
return promise.set_error(Status::Error(500, "Request aborted"));
}
promise.set_value(std::move(messages_info));
}));
lock.set_value(Unit()); lock.set_value(Unit());
} }
@ -22906,15 +22910,30 @@ void MessagesManager::on_get_scheduled_messages_from_database(DialogId dialog_id
} }
} }
void MessagesManager::get_message_public_forwards(FullMessageId full_message_id, const string &offset, int32 limit, void MessagesManager::get_message_public_forwards(FullMessageId full_message_id, string offset, int32 limit,
Promise<td_api::object_ptr<td_api::foundMessages>> &&promise) { Promise<td_api::object_ptr<td_api::foundMessages>> &&promise) {
auto dc_id_promise = PromiseCreator::lambda([actor_id = actor_id(this), full_message_id, offset = std::move(offset),
limit, promise = std::move(promise)](Result<DcId> r_dc_id) mutable {
if (r_dc_id.is_error()) {
return promise.set_error(r_dc_id.move_as_error());
}
send_closure(actor_id, &MessagesManager::send_get_message_public_forwards_query, r_dc_id.move_as_ok(),
full_message_id, std::move(offset), limit, std::move(promise));
});
td_->contacts_manager_->get_channel_statistics_dc_id(full_message_id.get_dialog_id(), false,
std::move(dc_id_promise));
}
void MessagesManager::send_get_message_public_forwards_query(
DcId dc_id, FullMessageId full_message_id, string offset, int32 limit,
Promise<td_api::object_ptr<td_api::foundMessages>> &&promise) {
auto dialog_id = full_message_id.get_dialog_id(); auto dialog_id = full_message_id.get_dialog_id();
Dialog *d = get_dialog_force(dialog_id, "get_message_public_forwards"); Dialog *d = get_dialog_force(dialog_id, "send_get_message_public_forwards_query");
if (d == nullptr) { if (d == nullptr) {
return promise.set_error(Status::Error(5, "Chat not found")); return promise.set_error(Status::Error(5, "Chat not found"));
} }
const Message *m = get_message_force(d, full_message_id.get_message_id(), "get_message_public_forwards"); const Message *m = get_message_force(d, full_message_id.get_message_id(), "send_get_message_public_forwards_query");
if (m == nullptr) { if (m == nullptr) {
return promise.set_error(Status::Error(5, "Message not found")); return promise.set_error(Status::Error(5, "Message not found"));
} }
@ -22953,7 +22972,7 @@ void MessagesManager::get_message_public_forwards(FullMessageId full_message_id,
} }
td_->create_handler<GetMessagePublicForwardsQuery>(std::move(promise)) td_->create_handler<GetMessagePublicForwardsQuery>(std::move(promise))
->send(full_message_id, offset_date, offset_dialog_id, offset_message_id, limit); ->send(dc_id, full_message_id, offset_date, offset_dialog_id, offset_message_id, limit);
} }
Result<int32> MessagesManager::get_message_schedule_date( Result<int32> MessagesManager::get_message_schedule_date(

View File

@ -734,7 +734,7 @@ class MessagesManager final : public Actor {
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);
void get_message_public_forwards(FullMessageId full_message_id, const string &offset, int32 limit, void get_message_public_forwards(FullMessageId full_message_id, string offset, int32 limit,
Promise<td_api::object_ptr<td_api::foundMessages>> &&promise); Promise<td_api::object_ptr<td_api::foundMessages>> &&promise);
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);
@ -2965,6 +2965,9 @@ class MessagesManager final : public Actor {
Status can_import_messages(DialogId dialog_id); Status can_import_messages(DialogId dialog_id);
void send_get_message_public_forwards_query(DcId dc_id, FullMessageId full_message_id, string offset, int32 limit,
Promise<td_api::object_ptr<td_api::foundMessages>> &&promise);
void on_animated_emoji_message_clicked(FullMessageId full_message_id, UserId user_id, Slice emoji, string data); void on_animated_emoji_message_clicked(FullMessageId full_message_id, UserId user_id, Slice emoji, string data);
void add_sponsored_dialog(const Dialog *d, DialogSource source); void add_sponsored_dialog(const Dialog *d, DialogSource source);

View File

@ -5497,7 +5497,7 @@ void Td::on_request(uint64 id, td_api::getMessagePublicForwards &request) {
CLEAN_INPUT_STRING(request.offset_); CLEAN_INPUT_STRING(request.offset_);
CREATE_REQUEST_PROMISE(); CREATE_REQUEST_PROMISE();
messages_manager_->get_message_public_forwards({DialogId(request.chat_id_), MessageId(request.message_id_)}, messages_manager_->get_message_public_forwards({DialogId(request.chat_id_), MessageId(request.message_id_)},
request.offset_, request.limit_, std::move(promise)); std::move(request.offset_), request.limit_, std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::removeNotification &request) { void Td::on_request(uint64 id, const td_api::removeNotification &request) {