Use send_closure_later in timeout callbacks.

GitOrigin-RevId: 21822d261a31900c94e2a37d3d3afa8240a49fc3
This commit is contained in:
levlam 2018-01-30 09:16:25 +03:00
parent 8e14bd16b2
commit 4bfa015e84
5 changed files with 32 additions and 15 deletions

View File

@ -2195,27 +2195,28 @@ void ContactsManager::on_user_online_timeout_callback(void *contacts_manager_ptr
CHECK(u != nullptr); CHECK(u != nullptr);
LOG(INFO) << "Update " << user_id << " online status to offline"; LOG(INFO) << "Update " << user_id << " online status to offline";
send_closure(G()->td(), &Td::send_update, send_closure_later(G()->td(), &Td::send_update,
make_tl_object<td_api::updateUserStatus>(user_id.get(), get_user_status_object(u))); make_tl_object<td_api::updateUserStatus>(user_id.get(), get_user_status_object(u)));
} }
void ContactsManager::on_channel_unban_timeout_callback(void *contacts_manager_ptr, int64 channel_id_long) { void ContactsManager::on_channel_unban_timeout_callback(void *contacts_manager_ptr, int64 channel_id_long) {
auto contacts_manager = static_cast<ContactsManager *>(contacts_manager_ptr); auto td = static_cast<ContactsManager *>(contacts_manager_ptr)->td_;
ChannelId channel_id(narrow_cast<int32>(channel_id_long)); send_closure_later(td->actor_id(td), &Td::on_channel_unban_timeout, channel_id_long);
auto c = contacts_manager->get_channel(channel_id); }
void ContactsManager::on_channel_unban_timeout(ChannelId channel_id) {
auto c = get_channel(channel_id);
CHECK(c != nullptr); CHECK(c != nullptr);
auto old_status = c->status; auto old_status = c->status;
c->status.update_restrictions(); c->status.update_restrictions();
if (c->status == old_status) { LOG_IF(ERROR, c->status == old_status && (c->status.is_restricted() || c->status.is_banned()))
LOG(ERROR) << "Status of " << channel_id << " wasn't updated: " << c->status; << "Status of " << channel_id << " wasn't updated: " << c->status;
return;
}
LOG(INFO) << "Update " << channel_id << " status"; LOG(INFO) << "Update " << channel_id << " status";
c->is_status_changed = true; c->is_status_changed = true;
contacts_manager->invalidate_channel_full(channel_id); invalidate_channel_full(channel_id);
contacts_manager->update_channel(c, channel_id); update_channel(c, channel_id); // always call, because in case of failure we need to reactivate timeout
} }
template <class StorerT> template <class StorerT>

View File

@ -204,6 +204,8 @@ class ContactsManager : public Actor {
void on_update_online_status_privacy(); void on_update_online_status_privacy();
void on_channel_unban_timeout(ChannelId channel_id);
void set_account_ttl(int32 account_ttl, Promise<Unit> &&promise) const; void set_account_ttl(int32 account_ttl, Promise<Unit> &&promise) const;
void get_account_ttl(Promise<int32> &&promise) const; void get_account_ttl(Promise<int32> &&promise) const;

View File

@ -7595,10 +7595,15 @@ void MessagesManager::unload_dialog(DialogId dialog_id) {
unloaded_message_ids.push_back(message_id.get()); unloaded_message_ids.push_back(message_id.get());
} }
if (!unloaded_message_ids.empty() && !G()->parameters().use_message_db) { if (!unloaded_message_ids.empty()) {
d->have_full_history = false; if (!G()->parameters().use_message_db) {
d->have_full_history = false;
}
send_closure_later(
G()->td(), &Td::send_update,
make_tl_object<td_api::updateDeleteMessages>(dialog_id.get(), std::move(unloaded_message_ids), false, true));
} }
send_update_delete_messages(dialog_id, std::move(unloaded_message_ids), false, true);
if (left_to_unload > 0) { if (left_to_unload > 0) {
LOG(INFO) << "Need to unload " << left_to_unload << " messages more in " << dialog_id; LOG(INFO) << "Need to unload " << left_to_unload << " messages more in " << dialog_id;

View File

@ -3527,7 +3527,7 @@ Td::Td(std::unique_ptr<TdCallback> callback) : callback_(std::move(callback)) {
void Td::on_alarm_timeout_callback(void *td_ptr, int64 request_id) { void Td::on_alarm_timeout_callback(void *td_ptr, int64 request_id) {
auto td = static_cast<Td *>(td_ptr); auto td = static_cast<Td *>(td_ptr);
auto td_id = td->actor_id(td); auto td_id = td->actor_id(td);
send_closure(td_id, &Td::on_alarm_timeout, request_id); send_closure_later(td_id, &Td::on_alarm_timeout, request_id);
} }
void Td::on_alarm_timeout(int64 request_id) { void Td::on_alarm_timeout(int64 request_id) {
@ -3553,6 +3553,13 @@ void Td::on_online_updated(bool force, bool send_update) {
} }
} }
void Td::on_channel_unban_timeout(int64 channel_id_long) {
if (close_flag_ >= 2) {
return;
}
contacts_manager_->on_channel_unban_timeout(ChannelId(narrow_cast<int32>(channel_id_long)));
}
void Td::request(uint64 id, tl_object_ptr<td_api::Function> function) { void Td::request(uint64 id, tl_object_ptr<td_api::Function> function) {
request_set_.insert(id); request_set_.insert(id);

View File

@ -95,6 +95,8 @@ class Td final : public NetQueryCallback {
void on_online_updated(bool force, bool send_update); void on_online_updated(bool force, bool send_update);
void on_channel_unban_timeout(int64 channel_id_long);
template <class ActorT, class... ArgsT> template <class ActorT, class... ArgsT>
ActorId<ActorT> create_net_actor(ArgsT &&... args) { ActorId<ActorT> create_net_actor(ArgsT &&... args) {
auto slot_id = request_actors_.create(ActorOwn<>(), RequestActorIdType); auto slot_id = request_actors_.create(ActorOwn<>(), RequestActorIdType);