Add and use generic MessagesManager::get_channel_differences_if_needed.
This commit is contained in:
parent
53cf01e7bf
commit
8900038324
@ -9793,30 +9793,24 @@ void MessagesManager::get_channel_differences_if_needed(MessagesInfo &&messages_
|
||||
}
|
||||
|
||||
void MessagesManager::get_channel_differences_if_needed(
|
||||
telegram_api::object_ptr<telegram_api::stats_publicForwards> &&public_forwards,
|
||||
Promise<telegram_api::object_ptr<telegram_api::stats_publicForwards>> &&promise, const char *source) {
|
||||
const vector<const telegram_api::object_ptr<telegram_api::Message> *> &messages, Promise<Unit> &&promise,
|
||||
const char *source) {
|
||||
if (td_->auth_manager_->is_bot()) {
|
||||
return promise.set_value(std::move(public_forwards));
|
||||
return promise.set_value(Unit());
|
||||
}
|
||||
MultiPromiseActorSafe mpas{"GetChannelDifferencesIfNeededForPublicForwardsMultiPromiseActor"};
|
||||
mpas.add_promise(Promise<Unit>());
|
||||
MultiPromiseActorSafe mpas{"GetChannelDifferencesIfNeededGenericMultiPromiseActor"};
|
||||
mpas.add_promise(std::move(promise));
|
||||
mpas.set_ignore_errors(true);
|
||||
auto lock = mpas.get_promise();
|
||||
for (const auto &forward : public_forwards->forwards_) {
|
||||
CHECK(forward != nullptr);
|
||||
if (forward->get_id() != telegram_api::publicForwardMessage::ID) {
|
||||
for (const auto &message : messages) {
|
||||
if (message == nullptr) {
|
||||
continue;
|
||||
}
|
||||
const auto &message = static_cast<const telegram_api::publicForwardMessage *>(forward.get())->message_;
|
||||
auto dialog_id = DialogId::get_message_dialog_id(message);
|
||||
if (need_channel_difference_to_add_message(dialog_id, message)) {
|
||||
run_after_channel_difference(dialog_id, MessageId::get_message_id(message, false), mpas.get_promise(), source);
|
||||
auto dialog_id = DialogId::get_message_dialog_id(*message);
|
||||
if (need_channel_difference_to_add_message(dialog_id, *message)) {
|
||||
run_after_channel_difference(dialog_id, MessageId::get_message_id(*message, false), mpas.get_promise(), source);
|
||||
}
|
||||
}
|
||||
// must be added after forwarded messages are checked
|
||||
mpas.add_promise(
|
||||
PromiseCreator::lambda([public_forwards = std::move(public_forwards), promise = std::move(promise)](
|
||||
Unit ignored) mutable { promise.set_value(std::move(public_forwards)); }));
|
||||
lock.set_value(Unit());
|
||||
}
|
||||
|
||||
|
@ -181,8 +181,8 @@ class MessagesManager final : public Actor {
|
||||
const char *source);
|
||||
|
||||
void get_channel_differences_if_needed(
|
||||
telegram_api::object_ptr<telegram_api::stats_publicForwards> &&public_forwards,
|
||||
Promise<telegram_api::object_ptr<telegram_api::stats_publicForwards>> &&promise, const char *source);
|
||||
const vector<const telegram_api::object_ptr<telegram_api::Message> *> &messages, Promise<Unit> &&promise,
|
||||
const char *source);
|
||||
|
||||
void on_get_messages(vector<tl_object_ptr<telegram_api::Message>> &&messages, bool is_channel_message,
|
||||
bool is_scheduled, Promise<Unit> &&promise, const char *source);
|
||||
|
@ -420,19 +420,8 @@ class GetMessagePublicForwardsQuery final : public Td::ResultHandler {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
td_->messages_manager_->get_channel_differences_if_needed(
|
||||
result_ptr.move_as_ok(),
|
||||
PromiseCreator::lambda(
|
||||
[actor_id = td_->statistics_manager_actor_.get(), promise = std::move(promise_)](
|
||||
Result<telegram_api::object_ptr<telegram_api::stats_publicForwards>> &&result) mutable {
|
||||
if (result.is_error()) {
|
||||
promise.set_error(result.move_as_error());
|
||||
} else {
|
||||
send_closure(actor_id, &StatisticsManager::on_get_public_forwards, result.move_as_ok(),
|
||||
std::move(promise));
|
||||
}
|
||||
}),
|
||||
"GetMessagePublicForwardsQuery");
|
||||
td_->statistics_manager_->get_channel_differences_if_needed(result_ptr.move_as_ok(), std::move(promise_),
|
||||
"GetMessagePublicForwardsQuery");
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
@ -470,19 +459,8 @@ class GetStoryPublicForwardsQuery final : public Td::ResultHandler {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
td_->messages_manager_->get_channel_differences_if_needed(
|
||||
result_ptr.move_as_ok(),
|
||||
PromiseCreator::lambda(
|
||||
[actor_id = td_->statistics_manager_actor_.get(), promise = std::move(promise_)](
|
||||
Result<telegram_api::object_ptr<telegram_api::stats_publicForwards>> &&result) mutable {
|
||||
if (result.is_error()) {
|
||||
promise.set_error(result.move_as_error());
|
||||
} else {
|
||||
send_closure(actor_id, &StatisticsManager::on_get_public_forwards, result.move_as_ok(),
|
||||
std::move(promise));
|
||||
}
|
||||
}),
|
||||
"GetStoryPublicForwardsQuery");
|
||||
td_->statistics_manager_->get_channel_differences_if_needed(result_ptr.move_as_ok(), std::move(promise_),
|
||||
"GetStoryPublicForwardsQuery");
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
@ -738,4 +716,29 @@ void StatisticsManager::on_get_public_forwards(
|
||||
td_api::make_object<td_api::publicForwards>(total_count, std::move(result), public_forwards->next_offset_));
|
||||
}
|
||||
|
||||
void StatisticsManager::get_channel_differences_if_needed(
|
||||
telegram_api::object_ptr<telegram_api::stats_publicForwards> &&public_forwards,
|
||||
Promise<td_api::object_ptr<td_api::publicForwards>> promise, const char *source) {
|
||||
vector<const telegram_api::object_ptr<telegram_api::Message> *> messages;
|
||||
for (const auto &forward : public_forwards->forwards_) {
|
||||
CHECK(forward != nullptr);
|
||||
if (forward->get_id() != telegram_api::publicForwardMessage::ID) {
|
||||
continue;
|
||||
}
|
||||
messages.push_back(&static_cast<const telegram_api::publicForwardMessage *>(forward.get())->message_);
|
||||
}
|
||||
td_->messages_manager_->get_channel_differences_if_needed(
|
||||
messages,
|
||||
PromiseCreator::lambda([actor_id = actor_id(this), public_forwards = std::move(public_forwards),
|
||||
promise = std::move(promise)](Result<Unit> &&result) mutable {
|
||||
if (result.is_error()) {
|
||||
promise.set_error(result.move_as_error());
|
||||
} else {
|
||||
send_closure(actor_id, &StatisticsManager::on_get_public_forwards, std::move(public_forwards),
|
||||
std::move(promise));
|
||||
}
|
||||
}),
|
||||
source);
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -48,6 +48,10 @@ class StatisticsManager final : public Actor {
|
||||
void on_get_public_forwards(telegram_api::object_ptr<telegram_api::stats_publicForwards> &&public_forwards,
|
||||
Promise<td_api::object_ptr<td_api::publicForwards>> &&promise);
|
||||
|
||||
void get_channel_differences_if_needed(telegram_api::object_ptr<telegram_api::stats_publicForwards> &&public_forwards,
|
||||
Promise<td_api::object_ptr<td_api::publicForwards>> promise,
|
||||
const char *source);
|
||||
|
||||
private:
|
||||
void tear_down() final;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user