Simplify QTS update processing.

This commit is contained in:
levlam 2023-12-14 23:27:46 +03:00
parent 0072ff225b
commit 53ee8caf37
4 changed files with 60 additions and 74 deletions

View File

@ -452,10 +452,7 @@ void BoostManager::get_user_dialog_boosts(DialogId dialog_id, UserId user_id,
}
void BoostManager::on_update_dialog_boost(DialogId dialog_id, telegram_api::object_ptr<telegram_api::boost> &&boost) {
if (!td_->auth_manager_->is_bot()) {
LOG(ERROR) << "Receive updateBotChatBoost by a non-bot";
return;
}
CHECK(td_->auth_manager_->is_bot());
if (!dialog_id.is_valid() || !td_->messages_manager_->have_dialog_info_force(dialog_id, "on_update_dialog_boost")) {
LOG(ERROR) << "Receive updateBotChatBoost in " << dialog_id;
return;

View File

@ -17331,10 +17331,7 @@ void ContactsManager::send_update_chat_member(DialogId dialog_id, UserId agent_u
}
void ContactsManager::on_update_bot_stopped(UserId user_id, int32 date, bool is_stopped, bool force) {
if (!td_->auth_manager_->is_bot()) {
LOG(ERROR) << "Receive updateBotStopped by non-bot";
return;
}
CHECK(td_->auth_manager_->is_bot());
if (date <= 0 || !have_user_force(user_id, "on_update_bot_stopped")) {
LOG(ERROR) << "Receive invalid updateBotStopped by " << user_id << " at " << date;
return;
@ -17366,10 +17363,7 @@ void ContactsManager::on_update_chat_participant(ChatId chat_id, UserId user_id,
DialogInviteLink invite_link,
tl_object_ptr<telegram_api::ChatParticipant> old_participant,
tl_object_ptr<telegram_api::ChatParticipant> new_participant) {
if (!td_->auth_manager_->is_bot()) {
LOG(ERROR) << "Receive updateChatParticipant by non-bot";
return;
}
CHECK(td_->auth_manager_->is_bot());
if (!chat_id.is_valid() || !user_id.is_valid() || date <= 0 ||
(old_participant == nullptr && new_participant == nullptr)) {
LOG(ERROR) << "Receive invalid updateChatParticipant in " << chat_id << " by " << user_id << " at " << date << ": "
@ -17416,10 +17410,7 @@ void ContactsManager::on_update_channel_participant(ChannelId channel_id, UserId
DialogInviteLink invite_link, bool via_dialog_filter_invite_link,
tl_object_ptr<telegram_api::ChannelParticipant> old_participant,
tl_object_ptr<telegram_api::ChannelParticipant> new_participant) {
if (!td_->auth_manager_->is_bot()) {
LOG(ERROR) << "Receive updateChannelParticipant by non-bot";
return;
}
CHECK(td_->auth_manager_->is_bot());
if (!channel_id.is_valid() || !user_id.is_valid() || date <= 0 ||
(old_participant == nullptr && new_participant == nullptr)) {
LOG(ERROR) << "Receive invalid updateChannelParticipant in " << channel_id << " by " << user_id << " at " << date
@ -17473,7 +17464,8 @@ void ContactsManager::on_update_channel_participant(ChannelId channel_id, UserId
void ContactsManager::on_update_chat_invite_requester(DialogId dialog_id, UserId user_id, string about, int32 date,
DialogInviteLink invite_link) {
if (!td_->auth_manager_->is_bot() || date <= 0 || !have_user_force(user_id, "on_update_chat_invite_requester") ||
CHECK(td_->auth_manager_->is_bot());
if (date <= 0 || !have_user_force(user_id, "on_update_chat_invite_requester") ||
!td_->messages_manager_->have_dialog_info_force(dialog_id, "on_update_chat_invite_requester")) {
LOG(ERROR) << "Receive invalid updateBotChatInviteRequester by " << user_id << " in " << dialog_id << " at "
<< date;

View File

@ -1893,9 +1893,7 @@ void PollManager::on_get_poll_vote(PollId poll_id, DialogId dialog_id, vector<Bu
LOG(ERROR) << "Receive updateMessagePollVote from invalid " << dialog_id;
return;
}
if (!td_->auth_manager_->is_bot()) {
return;
}
CHECK(td_->auth_manager_->is_bot());
vector<int32> option_ids;
for (auto &option : options) {

View File

@ -2945,61 +2945,60 @@ void UpdatesManager::process_qts_update(tl_object_ptr<telegram_api::Update> &&up
qts_gap_ = 0;
qts_diff_ = 0;
}
switch (update_ptr->get_id()) {
case telegram_api::updateNewEncryptedMessage::ID: {
auto update = move_tl_object_as<telegram_api::updateNewEncryptedMessage>(update_ptr);
send_closure(td_->secret_chats_manager_, &SecretChatsManager::on_new_message, std::move(update->message_),
add_qts(qts));
break;
auto constructor_id = update_ptr->get_id();
if (constructor_id == telegram_api::updateNewEncryptedMessage::ID) {
auto update = move_tl_object_as<telegram_api::updateNewEncryptedMessage>(update_ptr);
send_closure(td_->secret_chats_manager_, &SecretChatsManager::on_new_message, std::move(update->message_),
add_qts(qts));
} else if (td_->auth_manager_->is_bot()) {
switch (constructor_id) {
case telegram_api::updateMessagePollVote::ID: {
auto update = move_tl_object_as<telegram_api::updateMessagePollVote>(update_ptr);
td_->poll_manager_->on_get_poll_vote(PollId(update->poll_id_), DialogId(update->peer_),
std::move(update->options_));
break;
}
case telegram_api::updateBotStopped::ID: {
auto update = move_tl_object_as<telegram_api::updateBotStopped>(update_ptr);
td_->contacts_manager_->on_update_bot_stopped(UserId(update->user_id_), update->date_, update->stopped_);
break;
}
case telegram_api::updateChatParticipant::ID: {
auto update = move_tl_object_as<telegram_api::updateChatParticipant>(update_ptr);
td_->contacts_manager_->on_update_chat_participant(
ChatId(update->chat_id_), UserId(update->actor_id_), update->date_,
DialogInviteLink(std::move(update->invite_), true, "updateChatParticipant"),
std::move(update->prev_participant_), std::move(update->new_participant_));
break;
}
case telegram_api::updateChannelParticipant::ID: {
auto update = move_tl_object_as<telegram_api::updateChannelParticipant>(update_ptr);
td_->contacts_manager_->on_update_channel_participant(
ChannelId(update->channel_id_), UserId(update->actor_id_), update->date_,
DialogInviteLink(std::move(update->invite_), true, "updateChannelParticipant"), update->via_chatlist_,
std::move(update->prev_participant_), std::move(update->new_participant_));
break;
}
case telegram_api::updateBotChatInviteRequester::ID: {
auto update = move_tl_object_as<telegram_api::updateBotChatInviteRequester>(update_ptr);
td_->contacts_manager_->on_update_chat_invite_requester(
DialogId(update->peer_), UserId(update->user_id_), std::move(update->about_), update->date_,
DialogInviteLink(std::move(update->invite_), true, "updateBotChatInviteRequester"));
break;
}
case telegram_api::updateBotChatBoost::ID: {
auto update = move_tl_object_as<telegram_api::updateBotChatBoost>(update_ptr);
td_->boost_manager_->on_update_dialog_boost(DialogId(update->peer_), std::move(update->boost_));
break;
}
default:
UNREACHABLE();
break;
}
case telegram_api::updateMessagePollVote::ID: {
auto update = move_tl_object_as<telegram_api::updateMessagePollVote>(update_ptr);
DialogId dialog_id(update->peer_);
td_->poll_manager_->on_get_poll_vote(PollId(update->poll_id_), dialog_id, std::move(update->options_));
add_qts(qts).set_value(Unit());
break;
}
case telegram_api::updateBotStopped::ID: {
auto update = move_tl_object_as<telegram_api::updateBotStopped>(update_ptr);
td_->contacts_manager_->on_update_bot_stopped(UserId(update->user_id_), update->date_, update->stopped_);
add_qts(qts).set_value(Unit());
break;
}
case telegram_api::updateChatParticipant::ID: {
auto update = move_tl_object_as<telegram_api::updateChatParticipant>(update_ptr);
td_->contacts_manager_->on_update_chat_participant(
ChatId(update->chat_id_), UserId(update->actor_id_), update->date_,
DialogInviteLink(std::move(update->invite_), true, "updateChatParticipant"),
std::move(update->prev_participant_), std::move(update->new_participant_));
add_qts(qts).set_value(Unit());
break;
}
case telegram_api::updateChannelParticipant::ID: {
auto update = move_tl_object_as<telegram_api::updateChannelParticipant>(update_ptr);
td_->contacts_manager_->on_update_channel_participant(
ChannelId(update->channel_id_), UserId(update->actor_id_), update->date_,
DialogInviteLink(std::move(update->invite_), true, "updateChannelParticipant"), update->via_chatlist_,
std::move(update->prev_participant_), std::move(update->new_participant_));
add_qts(qts).set_value(Unit());
break;
}
case telegram_api::updateBotChatInviteRequester::ID: {
auto update = move_tl_object_as<telegram_api::updateBotChatInviteRequester>(update_ptr);
td_->contacts_manager_->on_update_chat_invite_requester(
DialogId(update->peer_), UserId(update->user_id_), std::move(update->about_), update->date_,
DialogInviteLink(std::move(update->invite_), true, "updateBotChatInviteRequester"));
add_qts(qts).set_value(Unit());
break;
}
case telegram_api::updateBotChatBoost::ID: {
auto update = move_tl_object_as<telegram_api::updateBotChatBoost>(update_ptr);
td_->boost_manager_->on_update_dialog_boost(DialogId(update->peer_), std::move(update->boost_));
add_qts(qts).set_value(Unit());
break;
}
default:
UNREACHABLE();
break;
add_qts(qts).set_value(Unit());
} else {
add_qts(qts).set_value(Unit());
LOG(ERROR) << "Receive " << to_string(update_ptr);
}
promise.set_value(Unit());
}