diff --git a/td/telegram/CallActor.cpp b/td/telegram/CallActor.cpp index 0ca317618..81a4968c5 100644 --- a/td/telegram/CallActor.cpp +++ b/td/telegram/CallActor.cpp @@ -310,7 +310,7 @@ void CallActor::on_set_rating_query_result(NetQueryPtr net_query) { return on_error(res.move_as_error()); } call_state_.need_rating = false; - send_closure(G()->updates_manager(), &UpdatesManager::on_get_updates, res.move_as_ok()); + send_closure(G()->updates_manager(), &UpdatesManager::on_get_updates, res.move_as_ok(), Promise()); } void CallActor::send_call_debug_information(string data, Promise<> promise) { @@ -730,7 +730,7 @@ void CallActor::on_discard_query_result(NetQueryPtr net_query) { if (res.is_error()) { return on_error(res.move_as_error()); } - send_closure(G()->updates_manager(), &UpdatesManager::on_get_updates, res.move_as_ok()); + send_closure(G()->updates_manager(), &UpdatesManager::on_get_updates, res.move_as_ok(), Promise()); } void CallActor::flush_call_state() { diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index e86451de0..9aed8083e 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -424,9 +424,7 @@ class AddContactQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for AddContactQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -457,9 +455,7 @@ class AcceptContactQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for AcceptContactQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -591,9 +587,7 @@ class DeleteContactsQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for DeleteContactsQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -1140,9 +1134,7 @@ class ToggleChannelSignaturesQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for ToggleChannelSignaturesQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -1185,10 +1177,17 @@ class ToggleChannelIsAllHistoryAvailableQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for TogglePreHistoryHiddenQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - td->contacts_manager_->on_update_channel_is_all_history_available(channel_id_, is_all_history_available_); - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates( + std::move(ptr), + PromiseCreator::lambda([promise = std::move(promise_), channel_id = channel_id_, + is_all_history_available = is_all_history_available_](Unit result) mutable { + if (G()->close_flag()) { + return promise.set_error(Status::Error(500, "Request aborted")); + } + send_closure(G()->contacts_manager(), &ContactsManager::on_update_channel_is_all_history_available, + channel_id, is_all_history_available, std::move(promise)); + })); } void on_error(uint64 id, Status status) override { @@ -1372,15 +1371,21 @@ class ToggleSlowModeQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for ToggleSlowModeQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - td->contacts_manager_->on_update_channel_slow_mode_delay(channel_id_, slow_mode_delay_); - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates( + std::move(ptr), PromiseCreator::lambda([promise = std::move(promise_), channel_id = channel_id_, + slow_mode_delay = slow_mode_delay_](Unit result) mutable { + if (G()->close_flag()) { + return promise.set_error(Status::Error(500, "Request aborted")); + } + send_closure(G()->contacts_manager(), &ContactsManager::on_update_channel_slow_mode_delay, channel_id, + slow_mode_delay, std::move(promise)); + })); } void on_error(uint64 id, Status status) override { if (status.message() == "CHAT_NOT_MODIFIED") { - td->contacts_manager_->on_update_channel_slow_mode_delay(channel_id_, slow_mode_delay_); + td->contacts_manager_->on_update_channel_slow_mode_delay(channel_id_, slow_mode_delay_, Promise()); if (!td->auth_manager_->is_bot()) { promise_.set_value(Unit()); return; @@ -1456,9 +1461,7 @@ class DeleteChannelQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for DeleteChannelQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -1487,9 +1490,7 @@ class AddChatUserQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for AddChatUserQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -1667,10 +1668,13 @@ class ImportDialogInviteLinkQuery : public Td::ResultHandler { LOG(ERROR) << "Receive wrong result for ImportDialogInviteLinkQuery: " << to_string(ptr); return on_error(id, Status::Error(500, "Internal Server Error")); } + auto dialog_id = dialog_ids[0]; - td->updates_manager_->on_get_updates(std::move(ptr)); td->contacts_manager_->invalidate_invite_link_info(invite_link_); - promise_.set_value(std::move(dialog_ids[0])); + td->updates_manager_->on_get_updates( + std::move(ptr), PromiseCreator::lambda([promise = std::move(promise_), dialog_id](Unit) mutable { + promise.set_value(std::move(dialog_id)); + })); } void on_error(uint64 id, Status status) override { @@ -1699,9 +1703,7 @@ class DeleteChatUserQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for DeleteChatUserQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -1733,9 +1735,7 @@ class JoinChannelQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for JoinChannelQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -1769,10 +1769,8 @@ class InviteToChannelQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for InviteToChannelQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); td->contacts_manager_->invalidate_channel_full(channel_id_, false, false); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -1806,10 +1804,8 @@ class EditChannelAdminQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for EditChannelAdminQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); td->contacts_manager_->invalidate_channel_full(channel_id_, false, false); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -1843,10 +1839,8 @@ class EditChannelBannedQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for EditChannelBannedQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); td->contacts_manager_->invalidate_channel_full(channel_id_, false, false); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -1879,9 +1873,7 @@ class LeaveChannelQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for LeaveChannelQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -1953,10 +1945,8 @@ class EditChannelCreatorQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for EditChannelCreatorQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); td->contacts_manager_->invalidate_channel_full(channel_id_, false, false); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -1985,9 +1975,7 @@ class MigrateChatQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for MigrateChatQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -12168,12 +12156,17 @@ void ContactsManager::on_update_channel_location(ChannelId channel_id, const Dia } } -void ContactsManager::on_update_channel_slow_mode_delay(ChannelId channel_id, int32 slow_mode_delay) { +void ContactsManager::on_update_channel_slow_mode_delay(ChannelId channel_id, int32 slow_mode_delay, + Promise &&promise) { + if (G()->close_flag()) { + return promise.set_error(Status::Error(500, "Request aborted")); + } auto channel_full = get_channel_full_force(channel_id, "on_update_channel_slow_mode_delay"); if (channel_full != nullptr) { on_update_channel_full_slow_mode_delay(channel_full, channel_id, slow_mode_delay, 0); update_channel_full(channel_full, channel_id); } + promise.set_value(Unit()); } void ContactsManager::on_update_channel_slow_mode_next_send_date(ChannelId channel_id, int32 slow_mode_next_send_date) { @@ -12210,17 +12203,19 @@ void ContactsManager::on_update_channel_full_bot_user_ids(ChannelFull *channel_f } } -void ContactsManager::on_update_channel_is_all_history_available(ChannelId channel_id, bool is_all_history_available) { +void ContactsManager::on_update_channel_is_all_history_available(ChannelId channel_id, bool is_all_history_available, + Promise &&promise) { + if (G()->close_flag()) { + return promise.set_error(Status::Error(500, "Request aborted")); + } CHECK(channel_id.is_valid()); auto channel_full = get_channel_full_force(channel_id, "on_update_channel_is_all_history_available"); - if (channel_full == nullptr) { - return; - } - if (channel_full->is_all_history_available != is_all_history_available) { + if (channel_full != nullptr && channel_full->is_all_history_available != is_all_history_available) { channel_full->is_all_history_available = is_all_history_available; channel_full->is_changed = true; update_channel_full(channel_full, channel_id); } + promise.set_value(Unit()); } void ContactsManager::on_update_channel_default_permissions(ChannelId channel_id, diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 13bbe9034..c22151cf5 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -196,9 +196,10 @@ class ContactsManager : public Actor { void on_update_channel_sticker_set(ChannelId channel_id, StickerSetId sticker_set_id); void on_update_channel_linked_channel_id(ChannelId channel_id, ChannelId group_channel_id); void on_update_channel_location(ChannelId channel_id, const DialogLocation &location); - void on_update_channel_slow_mode_delay(ChannelId channel_id, int32 slow_mode_delay); + void on_update_channel_slow_mode_delay(ChannelId channel_id, int32 slow_mode_delay, Promise &&promise); void on_update_channel_slow_mode_next_send_date(ChannelId channel_id, int32 slow_mode_next_send_date); - void on_update_channel_is_all_history_available(ChannelId channel_id, bool is_all_history_available); + void on_update_channel_is_all_history_available(ChannelId channel_id, bool is_all_history_available, + Promise &&promise); void on_update_channel_default_permissions(ChannelId channel_id, RestrictedRights default_permissions); void on_update_channel_administrator_count(ChannelId channel_id, int32 administrator_count); void on_update_channel_participant(ChannelId channel_id, UserId user_id, int32 date, diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index 33761ef2e..8d50a1751 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -16,6 +16,8 @@ #include "td/telegram/Td.h" #include "td/telegram/UpdatesManager.h" +#include "td/actor/MultiPromise.h" + #include "td/utils/JsonBuilder.h" #include "td/utils/Random.h" @@ -56,11 +58,12 @@ class CreateGroupCallQuery : public Td::ResultHandler { LOG(ERROR) << "Receive wrong CreateGroupCallQuery response " << to_string(ptr); return on_error(id, Status::Error(500, "Receive wrong response")); } + auto group_call_id = group_call_ids[0]; - td->updates_manager_->on_get_updates(std::move(ptr)); - - // TODO set promise after updates are processed - promise_.set_value(std::move(group_call_ids[0])); + td->updates_manager_->on_get_updates( + std::move(ptr), PromiseCreator::lambda([promise = std::move(promise_), group_call_id](Unit) mutable { + promise.set_value(std::move(group_call_id)); + })); } void on_error(uint64 id, Status status) override { @@ -224,10 +227,7 @@ class ToggleGroupCallSettingsQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for ToggleGroupCallSettingsQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - // TODO set promise after updates are processed - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -255,10 +255,7 @@ class InviteToGroupCallQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for InviteToGroupCallQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - // TODO set promise after updates are processed - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -294,10 +291,7 @@ class EditGroupCallMemberQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for EditGroupCallMemberQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - // TODO set promise after updates are processed - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -358,10 +352,7 @@ class LeaveGroupCallQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for LeaveGroupCallQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - // TODO set promise after updates are processed - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -389,10 +380,7 @@ class DiscardGroupCallQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for DiscardGroupCallQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - // TODO set promise after updates are processed - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -1503,9 +1491,10 @@ void GroupCallManager::process_join_group_call_response(InputGroupCallId input_g } LOG(INFO) << "Receive result for JoinGroupCallQuery: " << to_string(updates); - td_->updates_manager_->on_get_updates(std::move(updates)); - - promise.set_error(Status::Error(500, "Wrong join response received")); + td_->updates_manager_->on_get_updates(std::move(updates), + PromiseCreator::lambda([promise = std::move(promise)](Unit) mutable { + promise.set_error(Status::Error(500, "Wrong join response received")); + })); } Result> GroupCallManager::get_group_call_join_response_object( diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 6e2008438..141bebb6a 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -243,7 +243,7 @@ class GetAllDraftsQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for GetAllDraftsQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); + td->updates_manager_->on_get_updates(std::move(ptr), Promise()); } void on_error(uint64 id, Status status) override { @@ -610,9 +610,7 @@ class UpdateDialogPinnedMessageQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for UpdateDialogPinnedMessageQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -1058,13 +1056,12 @@ class EditDialogPhotoQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for EditDialogPhotoQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); if (file_id_.is_valid() && was_uploaded_) { td->file_manager_->delete_partial_remote_location(file_id_); } - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -1134,9 +1131,7 @@ class EditDialogTitleQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for EditDialogTitleQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -1178,9 +1173,7 @@ class EditDialogDefaultBannedRightsQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for EditDialogPermissionsQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -2338,9 +2331,7 @@ class BlockFromRepliesQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for BlockFromRepliesQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -2570,7 +2561,7 @@ class SendMessageActor : public NetActorOnce { auto constructor_id = ptr->get_id(); if (constructor_id != telegram_api::updateShortSentMessage::ID) { td->messages_manager_->check_send_message_result(random_id_, dialog_id_, ptr.get(), "SendMessage"); - return td->updates_manager_->on_get_updates(std::move(ptr)); + return td->updates_manager_->on_get_updates(std::move(ptr), Promise()); } auto sent_message = move_tl_object_as(ptr); td->messages_manager_->on_update_sent_text_message(random_id_, std::move(sent_message->media_), @@ -2636,7 +2627,7 @@ class StartBotQuery : public Td::ResultHandler { LOG(INFO) << "Receive result for StartBotQuery for " << random_id_ << ": " << to_string(ptr); // Result may contain messageActionChatAddUser // td->messages_manager_->check_send_message_result(random_id_, dialog_id_, ptr.get(), "StartBot"); - td->updates_manager_->on_get_updates(std::move(ptr)); + td->updates_manager_->on_get_updates(std::move(ptr), Promise()); } void on_error(uint64 id, Status status) override { @@ -2680,7 +2671,7 @@ class SendInlineBotResultQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for SendInlineBotResultQuery for " << random_id_ << ": " << to_string(ptr); td->messages_manager_->check_send_message_result(random_id_, dialog_id_, ptr.get(), "SendInlineBotResult"); - td->updates_manager_->on_get_updates(std::move(ptr)); + td->updates_manager_->on_get_updates(std::move(ptr), Promise()); } void on_error(uint64 id, Status status) override { @@ -2773,7 +2764,7 @@ class SendMultiMediaActor : public NetActorOnce { td->updates_manager_->schedule_get_difference("Wrong sendMultiMedia result"); } - td->updates_manager_->on_get_updates(std::move(ptr)); + td->updates_manager_->on_get_updates(std::move(ptr), Promise()); } void on_error(uint64 id, Status status) override { @@ -2867,7 +2858,7 @@ class SendMediaActor : public NetActorOnce { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for SendMediaQuery for " << random_id_ << ": " << to_string(ptr); td->messages_manager_->check_send_message_result(random_id_, dialog_id_, ptr.get(), "SendMedia"); - td->updates_manager_->on_get_updates(std::move(ptr)); + td->updates_manager_->on_get_updates(std::move(ptr), Promise()); } void on_error(uint64 id, Status status) override { @@ -3026,9 +3017,7 @@ class SendScheduledMessageActor : public NetActorOnce { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for SendScheduledMessageActor: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -3102,9 +3091,7 @@ class EditMessageActor : public NetActorOnce { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for EditMessageActor: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -3220,9 +3207,7 @@ class SetGameScoreActor : public NetActorOnce { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for SetGameScoreActor: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -3445,8 +3430,7 @@ class ForwardMessagesActor : public NetActorOnce { td->updates_manager_->schedule_get_difference("Wrong forwardMessages result"); } - td->updates_manager_->on_get_updates(std::move(ptr)); - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -3494,8 +3478,7 @@ class SendScreenshotNotificationQuery : public Td::ResultHandler { LOG(INFO) << "Receive result for SendScreenshotNotificationQuery for " << random_id_ << ": " << to_string(ptr); td->messages_manager_->check_send_message_result(random_id_, dialog_id_, ptr.get(), "SendScreenshotNotificationQuery"); - td->updates_manager_->on_get_updates(std::move(ptr)); - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -3706,9 +3689,7 @@ class DeleteScheduledMessagesQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for DeleteScheduledMessagesQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -3801,9 +3782,7 @@ class GetNotifySettingsExceptionsQuery : public Td::ResultHandler { for (auto &dialog_id : dialog_ids) { td->messages_manager_->force_create_dialog(dialog_id, "GetNotifySettingsExceptionsQuery"); } - td->updates_manager_->on_get_updates(std::move(updates_ptr)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(updates_ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -4185,8 +4164,7 @@ class EditPeerFoldersQuery : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for EditPeerFoldersQuery: " << to_string(ptr); - td->updates_manager_->on_get_updates(std::move(ptr)); - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -29135,7 +29113,7 @@ void MessagesManager::on_create_new_dialog_success(int64 random_id, tl_object_pt return on_create_new_dialog_fail(random_id, Status::Error(500, "Chat was created earlier"), std::move(promise)); } - td_->updates_manager_->on_get_updates(std::move(updates)); + td_->updates_manager_->on_get_updates(std::move(updates), Promise()); } void MessagesManager::on_create_new_dialog_fail(int64 random_id, Status error, Promise &&promise) { diff --git a/td/telegram/Payments.cpp b/td/telegram/Payments.cpp index 17ee57e0c..984ac0270 100644 --- a/td/telegram/Payments.cpp +++ b/td/telegram/Payments.cpp @@ -361,8 +361,10 @@ class SendPaymentFormQuery : public Td::ResultHandler { switch (payment_result->get_id()) { case telegram_api::payments_paymentResult::ID: { auto result = move_tl_object_as(payment_result); - G()->td().get_actor_unsafe()->updates_manager_->on_get_updates(std::move(result->updates_)); - promise_.set_value(make_tl_object(true, string())); + td->updates_manager_->on_get_updates(std::move(result->updates_), + PromiseCreator::lambda([promise = std::move(promise_)](Unit) mutable { + promise.set_value(make_tl_object(true, string())); + })); return; } case telegram_api::payments_paymentVerificationNeeded::ID: { @@ -410,9 +412,7 @@ class GetPaymentReceiptQuery : public Td::ResultHandler { } promise_.set_value(make_tl_object( - payment_receipt->date_, - G()->td().get_actor_unsafe()->contacts_manager_->get_user_id_object(payments_provider_user_id, - "paymentReceipt"), + payment_receipt->date_, td->contacts_manager_->get_user_id_object(payments_provider_user_id, "paymentReceipt"), convert_invoice(std::move(payment_receipt->invoice_)), convert_order_info(std::move(payment_receipt->info_)), convert_shipping_option(std::move(payment_receipt->shipping_)), std::move(payment_receipt->credentials_title_))); diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index 4fec71262..db9340335 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -224,9 +224,7 @@ class StopPollActor : public NetActorOnce { auto result = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for StopPollQuery: " << to_string(result); - td->updates_manager_->on_get_updates(std::move(result)); - - promise_.set_value(Unit()); + td->updates_manager_->on_get_updates(std::move(result), std::move(promise_)); } void on_error(uint64 id, Status status) override { @@ -846,7 +844,7 @@ void PollManager::on_set_poll_answer(PollId poll_id, uint64 generation, poll->was_saved = false; } if (result.is_ok()) { - td_->updates_manager_->on_get_updates(result.move_as_ok()); + td_->updates_manager_->on_get_updates(result.move_as_ok(), Promise()); for (auto &promise : promises) { promise.set_value(Unit()); @@ -1220,7 +1218,7 @@ void PollManager::on_get_poll_results(PollId poll_id, uint64 generation, return; } - td_->updates_manager_->on_get_updates(result.move_as_ok()); + td_->updates_manager_->on_get_updates(result.move_as_ok(), Promise()); } void PollManager::on_online() { diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index f524e93bc..de6233e5d 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3620,7 +3620,7 @@ void Td::on_result(NetQueryPtr query) { LOG(ERROR) << "Failed to fetch update: " << parser.get_error() << format::as_hex_dump<4>(ok.as_slice()); updates_manager_->schedule_get_difference("failed to fetch update"); } else { - updates_manager_->on_get_updates(std::move(ptr)); + updates_manager_->on_get_updates(std::move(ptr), Promise()); if (auth_manager_->is_bot() && auth_manager_->is_authorized()) { alarm_timeout_.set_timeout_in(PING_SERVER_ALARM_ID, PING_SERVER_TIMEOUT + Random::fast(0, PING_SERVER_TIMEOUT / 5)); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index c8e3ac4ae..812cadc27 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -45,6 +45,8 @@ #include "td/telegram/TdDb.h" #include "td/telegram/WebPagesManager.h" +#include "td/actor/MultiPromise.h" + #include "td/utils/buffer.h" #include "td/utils/format.h" #include "td/utils/logging.h" @@ -64,16 +66,18 @@ class OnUpdate { UpdatesManager *manager_; tl_object_ptr &update_; bool force_apply_; + Promise &promise_; public: - OnUpdate(UpdatesManager *manager, tl_object_ptr &update, bool force_apply) - : manager_(manager), update_(update), force_apply_(force_apply) { + OnUpdate(UpdatesManager *manager, tl_object_ptr &update, bool force_apply, + Promise &promise) + : manager_(manager), update_(update), force_apply_(force_apply), promise_(promise) { } template void operator()(T &obj) const { CHECK(&*update_ == &obj); - manager_->on_update(move_tl_object_as(update_), force_apply_); + manager_->on_update(move_tl_object_as(update_), force_apply_, std::move(promise_)); } }; @@ -676,7 +680,14 @@ bool UpdatesManager::is_acceptable_update(const telegram_api::Update *update) co return true; } -void UpdatesManager::on_get_updates(tl_object_ptr &&updates_ptr) { +void UpdatesManager::on_get_updates(tl_object_ptr &&updates_ptr, Promise &&promise) { + promise = PromiseCreator::lambda([promise = std::move(promise)](Result result) mutable { + if (!G()->close_flag() && result.is_error()) { + LOG(ERROR) << "Failed to process updates: " << result.error(); + } + promise.set_value(Unit()); + }); + CHECK(updates_ptr != nullptr); auto updates_type = updates_ptr->get_id(); if (updates_type != telegram_api::updateShort::ID) { @@ -687,7 +698,8 @@ void UpdatesManager::on_get_updates(tl_object_ptr &&updat auto &update = static_cast(updates_ptr.get())->update_; auto update_id = update->get_id(); if (update_id == telegram_api::updateLoginToken::ID) { - return td_->auth_manager_->on_update_login_token(); + td_->auth_manager_->on_update_login_token(); + return promise.set_value(Unit()); } switch (update_id) { @@ -697,19 +709,20 @@ void UpdatesManager::on_get_updates(tl_object_ptr &&updat case telegram_api::updateLangPackTooLong::ID: case telegram_api::updateLangPack::ID: LOG(INFO) << "Apply without authorization " << to_string(updates_ptr); - downcast_call(*update, OnUpdate(this, update, false)); + downcast_call(*update, OnUpdate(this, update, false, promise)); return; default: break; } } LOG(INFO) << "Ignore received before authorization or after logout " << to_string(updates_ptr); - return; + return promise.set_value(Unit()); } switch (updates_type) { case telegram_api::updatesTooLong::ID: get_difference("updatesTooLong"); + promise.set_value(Unit()); break; case telegram_api::updateShortMessage::ID: { auto update = move_tl_object_as(updates_ptr); @@ -725,17 +738,16 @@ void UpdatesManager::on_get_updates(tl_object_ptr &&updat auto from_id = update->flags_ & MessagesManager::MESSAGE_FLAG_IS_OUT ? td_->contacts_manager_->get_my_id().get() : update->user_id_; update->flags_ |= MessagesManager::MESSAGE_FLAG_HAS_FROM_ID; + + auto message = make_tl_object( + update->flags_, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, + false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, update->id_, + make_tl_object(from_id), make_tl_object(update->user_id_), + std::move(update->fwd_from_), update->via_bot_id_, std::move(update->reply_to_), update->date_, + update->message_, nullptr, nullptr, std::move(update->entities_), 0, 0, nullptr, 0, string(), 0, Auto()); on_pending_update( - make_tl_object( - make_tl_object( - update->flags_, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, - false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, - update->id_, make_tl_object(from_id), - make_tl_object(update->user_id_), std::move(update->fwd_from_), - update->via_bot_id_, std::move(update->reply_to_), update->date_, update->message_, nullptr, nullptr, - std::move(update->entities_), 0, 0, nullptr, 0, string(), 0, Auto()), - update->pts_, update->pts_count_), - 0, "telegram_api::updatesShortMessage"); + make_tl_object(std::move(message), update->pts_, update->pts_count_), 0, + std::move(promise), "telegram_api::updatesShortMessage"); break; } case telegram_api::updateShortChatMessage::ID: { @@ -750,17 +762,16 @@ void UpdatesManager::on_get_updates(tl_object_ptr &&updat } update->flags_ |= MessagesManager::MESSAGE_FLAG_HAS_FROM_ID; + auto message = make_tl_object( + update->flags_, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, + false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, update->id_, + make_tl_object(update->from_id_), + make_tl_object(update->chat_id_), std::move(update->fwd_from_), update->via_bot_id_, + std::move(update->reply_to_), update->date_, update->message_, nullptr, nullptr, std::move(update->entities_), + 0, 0, nullptr, 0, string(), 0, Auto()); on_pending_update( - make_tl_object( - make_tl_object( - update->flags_, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, - false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, - update->id_, make_tl_object(update->from_id_), - make_tl_object(update->chat_id_), std::move(update->fwd_from_), - update->via_bot_id_, std::move(update->reply_to_), update->date_, update->message_, nullptr, nullptr, - std::move(update->entities_), 0, 0, nullptr, 0, string(), 0, Auto()), - update->pts_, update->pts_count_), - 0, "telegram_api::updatesShortChatMessage"); + make_tl_object(std::move(message), update->pts_, update->pts_count_), 0, + std::move(promise), "telegram_api::updatesShortChatMessage"); break; } case telegram_api::updateShort::ID: { @@ -768,11 +779,12 @@ void UpdatesManager::on_get_updates(tl_object_ptr &&updat LOG(DEBUG) << "Receive " << oneline(to_string(update)); if (!is_acceptable_update(update->update_.get())) { LOG(ERROR) << "Receive unacceptable short update: " << oneline(to_string(update)); + promise.set_value(Unit()); return get_difference("unacceptable short update"); } short_update_date_ = update->date_; - if (!downcast_call(*update->update_, OnUpdate(this, update->update_, false))) { - LOG(ERROR) << "Can't call on some update"; + if (!downcast_call(*update->update_, OnUpdate(this, update->update_, false, promise))) { + LOG(FATAL) << "Can't call on some update"; } short_update_date_ = 0; break; @@ -782,20 +794,21 @@ void UpdatesManager::on_get_updates(tl_object_ptr &&updat td_->contacts_manager_->on_get_users(std::move(updates->users_), "updatesCombined"); td_->contacts_manager_->on_get_chats(std::move(updates->chats_), "updatesCombined"); on_pending_updates(std::move(updates->updates_), updates->seq_start_, updates->seq_, updates->date_, - "telegram_api::updatesCombined"); + std::move(promise), "telegram_api::updatesCombined"); break; } case telegram_api::updates::ID: { auto updates = move_tl_object_as(updates_ptr); td_->contacts_manager_->on_get_users(std::move(updates->users_), "updates"); td_->contacts_manager_->on_get_chats(std::move(updates->chats_), "updates"); - on_pending_updates(std::move(updates->updates_), updates->seq_, updates->seq_, updates->date_, + on_pending_updates(std::move(updates->updates_), updates->seq_, updates->seq_, updates->date_, std::move(promise), "telegram_api::updates"); break; } case telegram_api::updateShortSentMessage::ID: LOG(ERROR) << "Receive " << oneline(to_string(updates_ptr)); get_difference("updateShortSentMessage"); + promise.set_value(Unit()); break; default: UNREACHABLE(); @@ -1050,17 +1063,17 @@ void UpdatesManager::process_get_difference_updates( auto constructor_id = update->get_id(); if (constructor_id == telegram_api::updateMessageID::ID) { // in getDifference updateMessageID can't be received for scheduled messages - on_update(move_tl_object_as(update), true); + on_update(move_tl_object_as(update), true, Promise()); CHECK(!running_get_difference_); } if (constructor_id == telegram_api::updateEncryption::ID) { - on_update(move_tl_object_as(update), true); + on_update(move_tl_object_as(update), true, Promise()); CHECK(!running_get_difference_); } if (constructor_id == telegram_api::updateFolderPeers::ID) { - on_update(move_tl_object_as(update), true); + on_update(move_tl_object_as(update), true, Promise()); CHECK(!running_get_difference_); } @@ -1068,7 +1081,7 @@ void UpdatesManager::process_get_difference_updates( // TODO can't apply it here, because dialog may not be created yet // process updateReadHistoryInbox before new messages if (constructor_id == telegram_api::updateReadHistoryInbox::ID) { - on_update(move_tl_object_as(update), true); + on_update(move_tl_object_as(update), true, Promise()); CHECK(!running_get_difference_); } */ @@ -1085,7 +1098,7 @@ void UpdatesManager::process_get_difference_updates( Promise()); } - process_updates(std::move(other_updates), true); + process_updates(std::move(other_updates), true, Promise()); } void UpdatesManager::on_get_difference(tl_object_ptr &&difference_ptr) { @@ -1106,10 +1119,16 @@ void UpdatesManager::on_get_difference(tl_object_ptrseq_; if (!pending_seq_updates_.empty()) { LOG(WARNING) << "Drop " << pending_seq_updates_.size() << " pending seq updates after receive empty difference"; + for (auto &pending_update : pending_seq_updates_) { + pending_update.second.promise.set_value(Unit()); + } pending_seq_updates_.clear(); } if (!pending_qts_updates_.empty()) { LOG(WARNING) << "Drop " << pending_qts_updates_.size() << " pending qts updates after receive empty difference"; + for (auto &pending_update : pending_qts_updates_) { + pending_update.second.promise.set_value(Unit()); + } pending_qts_updates_.clear(); } break; @@ -1194,9 +1213,11 @@ void UpdatesManager::after_get_difference() { auto updates = std::move(it->second.updates); auto updates_seq_begin = it->second.seq_begin; auto updates_seq_end = it->second.seq_end; + auto promise = std::move(it->second.promise); // ignore it->second.date, because it may be too old postponed_updates_.erase(it); - on_pending_updates(std::move(updates), updates_seq_begin, updates_seq_end, 0, "postponed updates"); + on_pending_updates(std::move(updates), updates_seq_begin, updates_seq_end, 0, std::move(promise), + "postponed updates"); if (running_get_difference_) { VLOG(get_difference) << "Finish to apply postponed updates with " << postponed_updates_.size() << " updates left, because forced to run getDifference"; @@ -1216,14 +1237,14 @@ void UpdatesManager::after_get_difference() { } void UpdatesManager::on_pending_updates(vector> &&updates, int32 seq_begin, - int32 seq_end, int32 date, const char *source) { + int32 seq_end, int32 date, Promise &&promise, const char *source) { if (get_pts() == -1) { init_state(); } if (!td_->auth_manager_->is_authorized()) { LOG(INFO) << "Ignore updates received before authorization or after logout"; - return; + return promise.set_value(Unit()); } // for (auto &update : updates) { @@ -1234,20 +1255,19 @@ void UpdatesManager::on_pending_updates(vector(update), false); + on_update(move_tl_object_as(update), false, mpas.get_promise()); processed_updates++; update = nullptr; } if (id == telegram_api::updateEncryption::ID) { - on_update(move_tl_object_as(update), false); + on_update(move_tl_object_as(update), false, mpas.get_promise()); processed_updates++; update = nullptr; } @@ -1373,8 +1399,9 @@ void UpdatesManager::on_pending_updates(vectorsecond.promise.set_value(Unit()); // TODO + } - pending_seq_updates_.emplace(seq_begin, PendingUpdates(seq_begin, seq_end, date, std::move(updates))); + pending_seq_updates_.emplace(seq_begin, + PendingUpdates(seq_begin, seq_end, date, std::move(updates), mpas.get_promise())); set_seq_gap_timeout(MAX_UNFILLED_GAP_TIME); + lock.set_value(Unit()); } -void UpdatesManager::add_pending_qts_update(tl_object_ptr &&update, int32 qts) { +void UpdatesManager::add_pending_qts_update(tl_object_ptr &&update, int32 qts, + Promise &&promise) { CHECK(update != nullptr); if (qts <= 1) { LOG(ERROR) << "Receive wrong qts " << qts << " in " << oneline(to_string(update)); + promise.set_value(Unit()); return; } @@ -1444,6 +1478,7 @@ void UpdatesManager::add_pending_qts_update(tl_object_ptr if (qts <= old_qts) { LOG(INFO) << "Skip already applied update with qts = " << qts; + promise.set_value(Unit()); return; } @@ -1454,19 +1489,28 @@ void UpdatesManager::add_pending_qts_update(tl_object_ptr if (pending_qts_updates_.empty()) { set_qts_gap_timeout(MAX_UNFILLED_GAP_TIME); } - bool is_inserted = pending_qts_updates_.emplace(qts, std::move(update)).second; - if (!is_inserted) { - LOG(INFO) << "Receive duplicate update with qts = " << qts; + auto &pending_update = pending_qts_updates_[qts]; + if (pending_update.update != nullptr) { + LOG(WARNING) << "Receive duplicate update with qts = " << qts; + pending_update.promise.set_value(Unit()); // TODO } + pending_update.update = std::move(update); + pending_update.promise = std::move(promise); return; } - process_qts_update(std::move(update), qts); + process_qts_update(std::move(update), qts, std::move(promise)); process_pending_qts_updates(); } -void UpdatesManager::process_updates(vector> &&updates, bool force_apply) { +void UpdatesManager::process_updates(vector> &&updates, bool force_apply, + Promise &&promise) { tl_object_ptr update_pts_changed; + + MultiPromiseActorSafe mpas{"OnPendingUpdatesMultiPromiseActor"}; + mpas.add_promise(std::move(promise)); + auto lock = mpas.get_promise(); + /* for (auto &update : updates) { if (update != nullptr) { @@ -1474,7 +1518,7 @@ void UpdatesManager::process_updates(vector> // process updateReadChannelInbox before updateNewChannelMessage auto constructor_id = update->get_id(); if (constructor_id == telegram_api::updateReadChannelInbox::ID) { - on_update(move_tl_object_as(update), force_apply); + on_update(move_tl_object_as(update), force_apply, mpas.get_promise()); } } } @@ -1484,12 +1528,12 @@ void UpdatesManager::process_updates(vector> // process updateNewChannelMessage first auto constructor_id = update->get_id(); if (constructor_id == telegram_api::updateNewChannelMessage::ID) { - on_update(move_tl_object_as(update), force_apply); + on_update(move_tl_object_as(update), force_apply, mpas.get_promise()); } // process updateNewScheduledMessage first if (constructor_id == telegram_api::updateNewScheduledMessage::ID) { - on_update(move_tl_object_as(update), force_apply); + on_update(move_tl_object_as(update), force_apply, mpas.get_promise()); } // updatePtsChanged forces get difference, so process it last @@ -1501,19 +1545,22 @@ void UpdatesManager::process_updates(vector> for (auto &update : updates) { if (update != nullptr) { LOG(INFO) << "Process update " << to_string(update); - if (!downcast_call(*update, OnUpdate(this, update, force_apply))) { - LOG(ERROR) << "Can't call on some update"; + auto update_promise = mpas.get_promise(); + if (!downcast_call(*update, OnUpdate(this, update, force_apply, update_promise))) { + LOG(FATAL) << "Can't call on some update"; } CHECK(!running_get_difference_); } } if (update_pts_changed != nullptr) { - on_update(std::move(update_pts_changed), force_apply); + on_update(std::move(update_pts_changed), force_apply, mpas.get_promise()); } + lock.set_value(Unit()); } void UpdatesManager::process_seq_updates(int32 seq_end, int32 date, - vector> &&updates) { + vector> &&updates, + Promise &&promise) { string serialized_updates = PSTRING() << "process_seq_updates [seq_ = " << seq_ << ", seq_end = " << seq_end << "]: "; // TODO remove after bugs will be fixed for (auto &update : updates) { @@ -1521,7 +1568,7 @@ void UpdatesManager::process_seq_updates(int32 seq_end, int32 date, serialized_updates += oneline(to_string(update)); } } - process_updates(std::move(updates), false); + process_updates(std::move(updates), false, std::move(promise)); if (seq_end) { seq_ = seq_end; } @@ -1530,7 +1577,8 @@ void UpdatesManager::process_seq_updates(int32 seq_end, int32 date, } } -void UpdatesManager::process_qts_update(tl_object_ptr &&update_ptr, int32 qts) { +void UpdatesManager::process_qts_update(tl_object_ptr &&update_ptr, int32 qts, + Promise &&promise) { LOG(DEBUG) << "Process " << to_string(update_ptr); switch (update_ptr->get_id()) { case telegram_api::updateNewEncryptedMessage::ID: { @@ -1550,6 +1598,7 @@ void UpdatesManager::process_qts_update(tl_object_ptr &&up UNREACHABLE(); break; } + promise.set_value(Unit()); } void UpdatesManager::process_pending_seq_updates() { @@ -1563,7 +1612,8 @@ void UpdatesManager::process_pending_seq_updates() { break; } if (seq_begin == seq_ + 1) { - process_seq_updates(update_it->second.seq_end, update_it->second.date, std::move(update_it->second.updates)); + process_seq_updates(update_it->second.seq_end, update_it->second.date, std::move(update_it->second.updates), + std::move(update_it->second.promise)); } else { // old update CHECK(seq_begin != 0); @@ -1594,7 +1644,7 @@ void UpdatesManager::process_pending_qts_updates() { break; } if (qts == get_qts() + 1) { - process_qts_update(std::move(update_it->second), qts); + process_qts_update(std::move(update_it->second.update), qts, std::move(update_it->second.promise)); } pending_qts_updates_.erase(update_it); } @@ -1622,26 +1672,29 @@ void UpdatesManager::set_qts_gap_timeout(double timeout) { } } -void UpdatesManager::on_pending_update(tl_object_ptr update, int32 seq, const char *source) { +void UpdatesManager::on_pending_update(tl_object_ptr update, int32 seq, Promise &&promise, + const char *source) { vector> updates; updates.push_back(std::move(update)); - on_pending_updates(std::move(updates), seq, seq, 0, source); + on_pending_updates(std::move(updates), seq, seq, 0, std::move(promise), source); } -void UpdatesManager::on_update(tl_object_ptr update, bool force_apply) { - CHECK(update != nullptr); +void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, + Promise &&promise) { int new_pts = update->pts_; int pts_count = update->pts_count_; td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, "on_updateNewMessage"); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { - CHECK(update != nullptr); +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->messages_manager_->on_update_new_channel_message(std::move(update)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool force_apply) { - CHECK(update != nullptr); +void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, + Promise &&promise) { if (!force_apply) { LOG(ERROR) << "Receive updateMessageID not in getDifference"; return; @@ -1649,26 +1702,29 @@ void UpdatesManager::on_update(tl_object_ptr upda LOG(INFO) << "Receive update about sent message " << to_string(update); td_->messages_manager_->on_update_message_id(update->random_id_, MessageId(ServerMessageId(update->id_)), "getDifference"); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool force_apply) { - CHECK(update != nullptr); +void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, + Promise &&promise) { int new_pts = update->pts_; int pts_count = update->pts_count_; td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, "on_updateReadMessagesContents"); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool force_apply) { - CHECK(update != nullptr); +void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, + Promise &&promise) { int new_pts = update->pts_; int pts_count = update->pts_count_; td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, "on_updateEditMessage"); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool force_apply) { - CHECK(update != nullptr); +void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, + Promise &&promise) { int new_pts = update->pts_; int pts_count = update->pts_count_; if (update->messages_.empty()) { @@ -1678,10 +1734,11 @@ void UpdatesManager::on_update(tl_object_ptr td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, "on_updateDeleteMessages"); } + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool force_apply) { - CHECK(update != nullptr); +void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, + Promise &&promise) { int new_pts = update->pts_; int pts_count = update->pts_count_; if (force_apply) { @@ -1689,97 +1746,118 @@ void UpdatesManager::on_update(tl_object_ptrmessages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, "on_updateReadHistoryInbox"); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool force_apply) { - CHECK(update != nullptr); +void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, + Promise &&promise) { int new_pts = update->pts_; int pts_count = update->pts_count_; td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, "on_updateReadHistoryOutbox"); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { - CHECK(update != nullptr); +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->messages_manager_->on_update_service_notification(std::move(update), true, Promise()); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { // nothing to do + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { - CHECK(update != nullptr); +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->messages_manager_->on_update_read_channel_inbox(std::move(update)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { - CHECK(update != nullptr); +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->messages_manager_->on_update_read_channel_outbox(std::move(update)); + promise.set_value(Unit()); } void UpdatesManager::on_update(tl_object_ptr update, - bool /*force_apply*/) { + bool /*force_apply*/, Promise &&promise) { td_->messages_manager_->on_update_read_channel_messages_contents(std::move(update)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool force_apply) { +void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, + Promise &&promise) { td_->messages_manager_->on_update_channel_too_long(std::move(update), force_apply); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool force_apply) { +void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, + Promise &&promise) { if (!force_apply) { td_->contacts_manager_->invalidate_channel_full(ChannelId(update->channel_id_), false, false); } + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->messages_manager_->on_update_edit_channel_message(std::move(update)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { ChannelId channel_id(update->channel_id_); if (!channel_id.is_valid()) { LOG(ERROR) << "Receive invalid " << channel_id; - return; + } else { + DialogId dialog_id(channel_id); + int new_pts = update->pts_; + int pts_count = update->pts_count_; + td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count, + "on_updateDeleteChannelMessages"); } - DialogId dialog_id(channel_id); - int new_pts = update->pts_; - int pts_count = update->pts_count_; - td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count, - "on_updateDeleteChannelMessages"); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { ChannelId channel_id(update->channel_id_); if (!channel_id.is_valid()) { LOG(ERROR) << "Receive invalid " << channel_id; - return; + } else { + DialogId dialog_id(channel_id); + td_->messages_manager_->on_update_message_view_count({dialog_id, MessageId(ServerMessageId(update->id_))}, + update->views_); } - DialogId dialog_id(channel_id); - td_->messages_manager_->on_update_message_view_count({dialog_id, MessageId(ServerMessageId(update->id_))}, - update->views_); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { ChannelId channel_id(update->channel_id_); if (!channel_id.is_valid()) { LOG(ERROR) << "Receive invalid " << channel_id; - return; + } else { + DialogId dialog_id(channel_id); + td_->messages_manager_->on_update_message_forward_count({dialog_id, MessageId(ServerMessageId(update->id_))}, + update->forwards_); } - DialogId dialog_id(channel_id); - td_->messages_manager_->on_update_message_forward_count({dialog_id, MessageId(ServerMessageId(update->id_))}, - update->forwards_); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, - bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->messages_manager_->on_update_channel_max_unavailable_message_id( ChannelId(update->channel_id_), MessageId(ServerMessageId(update->available_min_id_))); + promise.set_value(Unit()); } void UpdatesManager::on_update(tl_object_ptr update, - bool /*force_apply*/) { + bool /*force_apply*/, Promise &&promise) { td_->messages_manager_->on_update_read_message_comments( DialogId(ChannelId(update->channel_id_)), MessageId(ServerMessageId(update->top_msg_id_)), MessageId(), MessageId(ServerMessageId(update->read_max_id_)), MessageId()); @@ -1788,38 +1866,43 @@ void UpdatesManager::on_update(tl_object_ptrbroadcast_id_)), MessageId(ServerMessageId(update->broadcast_post_)), MessageId(), MessageId(ServerMessageId(update->read_max_id_)), MessageId()); } + promise.set_value(Unit()); } void UpdatesManager::on_update(tl_object_ptr update, - bool /*force_apply*/) { + bool /*force_apply*/, Promise &&promise) { td_->messages_manager_->on_update_read_message_comments( DialogId(ChannelId(update->channel_id_)), MessageId(ServerMessageId(update->top_msg_id_)), MessageId(), MessageId(), MessageId(ServerMessageId(update->read_max_id_))); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool force_apply) { - CHECK(update != nullptr); +void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, + Promise &&promise) { int new_pts = update->pts_; int pts_count = update->pts_count_; td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, "on_updatePinnedMessages"); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { ChannelId channel_id(update->channel_id_); if (!channel_id.is_valid()) { LOG(ERROR) << "Receive invalid " << channel_id; - return; + } else { + DialogId dialog_id(channel_id); + int new_pts = update->pts_; + int pts_count = update->pts_count_; + td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count, + "on_updatePinnedChannelMessages"); } - DialogId dialog_id(channel_id); - int new_pts = update->pts_; - int pts_count = update->pts_count_; - td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count, - "on_updatePinnedChannelMessages"); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { - CHECK(update != nullptr); +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { switch (update->peer_->get_id()) { case telegram_api::notifyPeer::ID: { DialogId dialog_id(static_cast(update->peer_.get())->peer_); @@ -1832,49 +1915,59 @@ void UpdatesManager::on_update(tl_object_ptr break; } case telegram_api::notifyUsers::ID: - return td_->messages_manager_->on_update_scope_notify_settings(NotificationSettingsScope::Private, - std::move(update->notify_settings_)); + td_->messages_manager_->on_update_scope_notify_settings(NotificationSettingsScope::Private, + std::move(update->notify_settings_)); + break; case telegram_api::notifyChats::ID: - return td_->messages_manager_->on_update_scope_notify_settings(NotificationSettingsScope::Group, - std::move(update->notify_settings_)); + td_->messages_manager_->on_update_scope_notify_settings(NotificationSettingsScope::Group, + std::move(update->notify_settings_)); + break; case telegram_api::notifyBroadcasts::ID: - return td_->messages_manager_->on_update_scope_notify_settings(NotificationSettingsScope::Channel, - std::move(update->notify_settings_)); + td_->messages_manager_->on_update_scope_notify_settings(NotificationSettingsScope::Channel, + std::move(update->notify_settings_)); + break; default: UNREACHABLE(); } + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->messages_manager_->on_get_peer_settings(DialogId(update->peer_), std::move(update->settings_)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->contacts_manager_->on_update_peer_located(std::move(update->peers_), true); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool force_apply) { - CHECK(update != nullptr); +void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, + Promise &&promise) { td_->web_pages_manager_->on_get_web_page(std::move(update->webpage_), DialogId()); td_->messages_manager_->add_pending_update(make_tl_object(), update->pts_, update->pts_count_, force_apply, "on_updateWebPage"); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { - CHECK(update != nullptr); +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->web_pages_manager_->on_get_web_page(std::move(update->webpage_), DialogId()); ChannelId channel_id(update->channel_id_); if (!channel_id.is_valid()) { LOG(ERROR) << "Receive invalid " << channel_id; - return; + } else { + DialogId dialog_id(channel_id); + td_->messages_manager_->add_pending_channel_update(dialog_id, make_tl_object(), update->pts_, + update->pts_count_, "on_updateChannelWebPage"); } - DialogId dialog_id(channel_id); - td_->messages_manager_->add_pending_channel_update(dialog_id, make_tl_object(), update->pts_, - update->pts_count_, "on_updateChannelWebPage"); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool force_apply) { - CHECK(update != nullptr); +void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, + Promise &&promise) { for (auto &folder_peer : update->folder_peers_) { DialogId dialog_id(folder_peer->peer_); FolderId folder_id(folder_peer->folder_id_); @@ -1883,6 +1976,7 @@ void UpdatesManager::on_update(tl_object_ptr up td_->messages_manager_->add_pending_update(make_tl_object(), update->pts_, update->pts_count_, force_apply, "on_updateFolderPeers"); + promise.set_value(Unit()); } int32 UpdatesManager::get_short_update_date() const { @@ -1893,19 +1987,24 @@ int32 UpdatesManager::get_short_update_date() const { return now; } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { UserId user_id(update->user_id_); td_->messages_manager_->on_user_dialog_action(DialogId(user_id), MessageId(), user_id, DialogAction(std::move(update->action_)), get_short_update_date()); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->messages_manager_->on_user_dialog_action(DialogId(ChatId(update->chat_id_)), MessageId(), UserId(update->user_id_), DialogAction(std::move(update->action_)), get_short_update_date()); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { MessageId top_thread_message_id; if ((update->flags_ & telegram_api::updateChannelUserTyping::TOP_MSG_ID_MASK) != 0) { top_thread_message_id = MessageId(ServerMessageId(update->top_msg_id_)); @@ -1913,245 +2012,331 @@ void UpdatesManager::on_update(tl_object_ptrmessages_manager_->on_user_dialog_action(DialogId(ChannelId(update->channel_id_)), top_thread_message_id, UserId(update->user_id_), DialogAction(std::move(update->action_)), get_short_update_date()); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { SecretChatId secret_chat_id(update->chat_id_); UserId user_id = td_->contacts_manager_->get_secret_chat_user_id(secret_chat_id); td_->messages_manager_->on_user_dialog_action(DialogId(secret_chat_id), MessageId(), user_id, DialogAction::get_typing_action(), get_short_update_date()); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->contacts_manager_->on_update_user_online(UserId(update->user_id_), std::move(update->status_)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->contacts_manager_->on_update_user_name(UserId(update->user_id_), std::move(update->first_name_), std::move(update->last_name_), std::move(update->username_)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->contacts_manager_->on_update_user_phone_number(UserId(update->user_id_), std::move(update->phone_)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { // TODO update->previous_, update->date_ td_->contacts_manager_->on_update_user_photo(UserId(update->user_id_), std::move(update->photo_)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->messages_manager_->on_update_dialog_is_blocked(DialogId(update->peer_id_), update->blocked_); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->contacts_manager_->on_get_chat_participants(std::move(update->participants_), true); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->contacts_manager_->on_update_chat_add_user(ChatId(update->chat_id_), UserId(update->inviter_id_), UserId(update->user_id_), update->date_, update->version_); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->contacts_manager_->on_update_chat_edit_administrator(ChatId(update->chat_id_), UserId(update->user_id_), update->is_admin_, update->version_); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->contacts_manager_->on_update_chat_delete_user(ChatId(update->chat_id_), UserId(update->user_id_), update->version_); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, - bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { DialogId dialog_id(update->peer_); RestrictedRights permissions = get_restricted_rights(std::move(update->default_banned_rights_)); auto version = update->version_; switch (dialog_id.get_type()) { + case DialogType::Chat: + td_->contacts_manager_->on_update_chat_default_permissions(dialog_id.get_chat_id(), permissions, version); + break; + case DialogType::Channel: + LOG_IF(ERROR, version != 0) << "Receive version " << version << " in " << dialog_id; + td_->contacts_manager_->on_update_channel_default_permissions(dialog_id.get_channel_id(), permissions); + break; case DialogType::None: case DialogType::User: case DialogType::SecretChat: default: LOG(ERROR) << "Receive updateChatDefaultBannedRights in the " << dialog_id; - return; - case DialogType::Chat: - return td_->contacts_manager_->on_update_chat_default_permissions(dialog_id.get_chat_id(), permissions, version); - case DialogType::Channel: { - LOG_IF(ERROR, version != 0) << "Receive version " << version << " in " << dialog_id; - return td_->contacts_manager_->on_update_channel_default_permissions(dialog_id.get_channel_id(), permissions); - } + break; } + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->messages_manager_->on_update_dialog_draft_message(DialogId(update->peer_), std::move(update->draft_)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { FolderId folder_id(update->flags_ & telegram_api::updateDialogPinned::FOLDER_ID_MASK ? update->folder_id_ : 0); td_->messages_manager_->on_update_dialog_is_pinned( folder_id, DialogId(update->peer_), (update->flags_ & telegram_api::updateDialogPinned::PINNED_MASK) != 0); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { FolderId folder_id(update->flags_ & telegram_api::updatePinnedDialogs::FOLDER_ID_MASK ? update->folder_id_ : 0); td_->messages_manager_->on_update_pinned_dialogs(folder_id); // TODO use update->order_ + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->messages_manager_->on_update_dialog_is_marked_as_unread( DialogId(update->peer_), (update->flags_ & telegram_api::updateDialogUnreadMark::UNREAD_MASK) != 0); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->messages_manager_->on_update_dialog_filters(); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->messages_manager_->on_update_dialog_filters(); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->messages_manager_->on_update_dialog_filters(); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { send_closure(G()->config_manager(), &ConfigManager::on_dc_options_update, DcOptions(update->dc_options_)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->inline_queries_manager_->on_new_query(update->query_id_, UserId(update->user_id_), Location(update->geo_), std::move(update->peer_type_), update->query_, update->offset_); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->inline_queries_manager_->on_chosen_result(UserId(update->user_id_), Location(update->geo_), update->query_, update->id_, std::move(update->msg_id_)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->callback_queries_manager_->on_new_query(update->flags_, update->query_id_, UserId(update->user_id_), DialogId(update->peer_), MessageId(ServerMessageId(update->msg_id_)), std::move(update->data_), update->chat_instance_, std::move(update->game_short_name_)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->callback_queries_manager_->on_new_inline_query(update->flags_, update->query_id_, UserId(update->user_id_), std::move(update->msg_id_), std::move(update->data_), update->chat_instance_, std::move(update->game_short_name_)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->stickers_manager_->reload_favorite_stickers(true); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->animations_manager_->reload_saved_animations(true); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { send_closure(td_->config_manager_, &ConfigManager::request_config); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { set_pts(std::numeric_limits::max(), "updatePtsChanged").set_value(Unit()); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { send_closure(td_->secret_chats_manager_, &SecretChatsManager::on_update_chat, std::move(update)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool force_apply) { +void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, + Promise &&promise) { if (force_apply) { - return process_qts_update(std::move(update), 0); + return process_qts_update(std::move(update), 0, std::move(promise)); } auto qts = update->qts_; - add_pending_qts_update(std::move(update), qts); + add_pending_qts_update(std::move(update), qts, std::move(promise)); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->messages_manager_->read_secret_chat_outbox(SecretChatId(update->chat_id_), update->max_date_, update->date_); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { send_closure(td_->privacy_manager_, &PrivacyManager::update_privacy, std::move(update)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->stickers_manager_->on_get_messages_sticker_set(StickerSetId(), std::move(update->stickerset_), true, "updateNewStickerSet"); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->stickers_manager_->on_update_sticker_sets(); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { bool is_masks = (update->flags_ & telegram_api::updateStickerSetsOrder::MASKS_MASK) != 0; td_->stickers_manager_->on_update_sticker_sets_order(is_masks, StickersManager::convert_sticker_set_ids(update->order_)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->stickers_manager_->reload_featured_sticker_sets(true); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->stickers_manager_->reload_recent_stickers(false, true); td_->stickers_manager_->reload_recent_stickers(true, true); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { UserId user_id(update->user_id_); if (!user_id.is_valid()) { LOG(ERROR) << "Receive shipping query from invalid " << user_id; - return; - } - CHECK(update->shipping_address_ != nullptr); + } else { + CHECK(update->shipping_address_ != nullptr); - send_closure(G()->td(), &Td::send_update, - make_tl_object( - update->query_id_, td_->contacts_manager_->get_user_id_object(user_id, "updateNewShippingQuery"), - update->payload_.as_slice().str(), - get_address_object(get_address(std::move(update->shipping_address_))))); // TODO use convert_address + send_closure( + G()->td(), &Td::send_update, + make_tl_object( + update->query_id_, td_->contacts_manager_->get_user_id_object(user_id, "updateNewShippingQuery"), + update->payload_.as_slice().str(), + get_address_object(get_address(std::move(update->shipping_address_))))); // TODO use convert_address + } + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { UserId user_id(update->user_id_); if (!user_id.is_valid()) { LOG(ERROR) << "Receive pre-checkout query from invalid " << user_id; - return; + } else { + send_closure( + G()->td(), &Td::send_update, + make_tl_object( + update->query_id_, td_->contacts_manager_->get_user_id_object(user_id, "updateNewPreCheckoutQuery"), + update->currency_, update->total_amount_, update->payload_.as_slice().str(), update->shipping_option_id_, + get_order_info_object(get_order_info(std::move(update->info_))))); } - - send_closure(G()->td(), &Td::send_update, - make_tl_object( - update->query_id_, td_->contacts_manager_->get_user_id_object(user_id, "updateNewPreCheckoutQuery"), - update->currency_, update->total_amount_, update->payload_.as_slice().str(), - update->shipping_option_id_, get_order_info_object(get_order_info(std::move(update->info_))))); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { send_closure(G()->td(), &Td::send_update, make_tl_object(update->data_->data_)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { send_closure(G()->td(), &Td::send_update, make_tl_object(update->query_id_, update->data_->data_, update->timeout_)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { send_closure(G()->call_manager(), &CallManager::update_call, std::move(update)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { send_closure(G()->call_manager(), &CallManager::update_call_signaling_data, update->phone_call_id_, update->data_.as_slice().str()); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { DialogId dialog_id(ChatId(update->chat_id_)); if (!td_->messages_manager_->have_dialog_force(dialog_id)) { dialog_id = DialogId(ChannelId(update->chat_id_)); @@ -2160,70 +2345,93 @@ void UpdatesManager::on_update(tl_object_ptr upda } } send_closure(G()->group_call_manager(), &GroupCallManager::on_update_group_call, std::move(update->call_), dialog_id); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { send_closure(G()->group_call_manager(), &GroupCallManager::on_update_group_call_participants, InputGroupCallId(update->call_), std::move(update->participants_), update->version_); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->contacts_manager_->on_update_contacts_reset(); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { send_closure(G()->language_pack_manager(), &LanguagePackManager::on_language_pack_too_long, std::move(update->lang_code_)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { send_closure(G()->language_pack_manager(), &LanguagePackManager::on_update_language_pack, std::move(update->difference_)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->messages_manager_->on_update_live_location_viewed( {DialogId(update->peer_), MessageId(ServerMessageId(update->msg_id_))}); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->poll_manager_->on_get_poll(PollId(update->poll_id_), std::move(update->poll_), std::move(update->results_)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->poll_manager_->on_get_poll_vote(PollId(update->poll_id_), UserId(update->user_id_), std::move(update->options_)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { td_->messages_manager_->on_get_message(std::move(update->message_), true, false, true, true, true, "updateNewScheduledMessage"); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, - bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { vector message_ids = transform(update->messages_, [](int32 scheduled_server_message_id) { return ScheduledServerMessageId(scheduled_server_message_id); }); td_->messages_manager_->on_update_delete_scheduled_messages(DialogId(update->peer_), std::move(message_ids)); + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { LOG(INFO) << "Ignore updateLoginToken after authorization"; + promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, bool force_apply) { +void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, + Promise &&promise) { if (force_apply) { - return process_qts_update(std::move(update), 0); + return process_qts_update(std::move(update), 0, std::move(promise)); } auto qts = update->qts_; - add_pending_qts_update(std::move(update), qts); + add_pending_qts_update(std::move(update), qts, std::move(promise)); } // unsupported updates -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise) { + promise.set_value(Unit()); } } // namespace td diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index 05fd0782a..6ed66e9c5 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -34,7 +34,7 @@ class UpdatesManager : public Actor { public: UpdatesManager(Td *td, ActorShared<> parent); - void on_get_updates(tl_object_ptr &&updates_ptr); + void on_get_updates(tl_object_ptr &&updates_ptr, Promise &&promise); void on_get_updates_state(tl_object_ptr &&state, const char *source); @@ -92,12 +92,20 @@ class UpdatesManager : public Actor { int32 seq_end; int32 date; vector> updates; + Promise promise; - PendingUpdates(int32 seq_begin, int32 seq_end, int32 date, vector> &&updates) - : seq_begin(seq_begin), seq_end(seq_end), date(date), updates(std::move(updates)) { + PendingUpdates(int32 seq_begin, int32 seq_end, int32 date, vector> &&updates, + Promise &&promise) + : seq_begin(seq_begin), seq_end(seq_end), date(date), updates(std::move(updates)), promise(std::move(promise)) { } }; + class PendingQtsUpdate { + public: + tl_object_ptr update; + Promise promise; + }; + Td *td_; ActorShared<> parent_; @@ -112,7 +120,7 @@ class UpdatesManager : public Actor { std::multimap postponed_updates_; // updates received during getDifference std::multimap pending_seq_updates_; // updates with too big seq - std::map> pending_qts_updates_; // updates with too big qts + std::map pending_qts_updates_; // updates with too big qts Timeout seq_gap_timeout_; @@ -142,18 +150,21 @@ class UpdatesManager : public Actor { vector> &&new_encrypted_messages, vector> &&other_updates); - void on_pending_update(tl_object_ptr update, int32 seq, const char *source); + void on_pending_update(tl_object_ptr update, int32 seq, Promise &&promise, + const char *source); - void add_pending_qts_update(tl_object_ptr &&update, int32 qts); + void add_pending_qts_update(tl_object_ptr &&update, int32 qts, Promise &&promise); void on_pending_updates(vector> &&updates, int32 seq_begin, int32 seq_end, - int32 date, const char *source); + int32 date, Promise &&promise, const char *source); - void process_updates(vector> &&updates, bool force_apply); + void process_updates(vector> &&updates, bool force_apply, + Promise &&promise); - void process_seq_updates(int32 seq_end, int32 date, vector> &&updates); + void process_seq_updates(int32 seq_end, int32 date, vector> &&updates, + Promise &&promise); - void process_qts_update(tl_object_ptr &&update_ptr, int32 qts); + void process_qts_update(tl_object_ptr &&update_ptr, int32 qts, Promise &&promise); void process_pending_seq_updates(); @@ -199,133 +210,185 @@ class UpdatesManager : public Actor { bool is_acceptable_update(const telegram_api::Update *update) const; - void on_update(tl_object_ptr update, bool force_apply); - void on_update(tl_object_ptr update, bool force_apply); - void on_update(tl_object_ptr update, bool force_apply); - void on_update(tl_object_ptr update, bool force_apply); - void on_update(tl_object_ptr update, bool force_apply); - void on_update(tl_object_ptr update, bool force_apply); - void on_update(tl_object_ptr update, bool force_apply); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool force_apply, Promise &&promise); + void on_update(tl_object_ptr update, bool force_apply, Promise &&promise); + void on_update(tl_object_ptr update, bool force_apply, + Promise &&promise); + void on_update(tl_object_ptr update, bool force_apply, Promise &&promise); + void on_update(tl_object_ptr update, bool force_apply, Promise &&promise); + void on_update(tl_object_ptr update, bool force_apply, Promise &&promise); + void on_update(tl_object_ptr update, bool force_apply, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); - void on_update(tl_object_ptr update, bool force_apply); - void on_update(tl_object_ptr update, bool force_apply); + void on_update(tl_object_ptr update, bool force_apply, Promise &&promise); + void on_update(tl_object_ptr update, bool force_apply, Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool force_apply); + void on_update(tl_object_ptr update, bool force_apply, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool force_apply); - void on_update(tl_object_ptr update, bool force_apply); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool force_apply, Promise &&promise); + void on_update(tl_object_ptr update, bool force_apply, Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool force_apply); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool force_apply, Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool force_apply); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); + void on_update(tl_object_ptr update, bool force_apply, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, + Promise &&promise); // unsupported updates - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise); }; } // namespace td