Add updateChannelParticipant processing.

GitOrigin-RevId: 5701dcbb068583266aaf00b3b4ed5c6336566e76
This commit is contained in:
levlam 2020-08-03 21:54:28 +03:00
parent 57f1ab4daf
commit 4bf3b013c7
4 changed files with 65 additions and 14 deletions

View File

@ -12127,6 +12127,43 @@ void ContactsManager::on_update_channel_default_permissions(ChannelId channel_id
}
}
void ContactsManager::on_update_channel_participant(ChannelId channel_id, UserId user_id, int32 date,
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;
}
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 << " for " << user_id << " at " << date
<< ": " << to_string(old_participant) << " -> " << to_string(new_participant);
return;
}
DialogParticipant old_dialog_participant;
DialogParticipant new_dialog_participant;
if (old_participant != nullptr) {
old_dialog_participant = get_dialog_participant(channel_id, std::move(old_participant));
if (new_participant == nullptr) {
new_dialog_participant = DialogParticipant::left(old_dialog_participant.user_id);
} else {
new_dialog_participant = get_dialog_participant(channel_id, std::move(new_participant));
}
} else {
new_dialog_participant = get_dialog_participant(channel_id, std::move(new_participant));
old_dialog_participant = DialogParticipant::left(new_dialog_participant.user_id);
}
if (old_dialog_participant.user_id != new_dialog_participant.user_id || !old_dialog_participant.is_valid() ||
!new_dialog_participant.is_valid()) {
LOG(ERROR) << "Receive wrong updateChannelParticipant: " << old_dialog_participant << " -> "
<< new_dialog_participant;
return;
}
// TODO send update
}
void ContactsManager::update_contacts_hints(const User *u, UserId user_id, bool from_database) {
bool is_contact = is_user_contact(u, user_id);
if (td_->auth_manager_->is_bot()) {

View File

@ -200,6 +200,9 @@ class ContactsManager : public Actor {
void on_update_channel_is_all_history_available(ChannelId channel_id, bool is_all_history_available);
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,
tl_object_ptr<telegram_api::ChannelParticipant> old_participant,
tl_object_ptr<telegram_api::ChannelParticipant> new_participant);
int32 on_update_peer_located(vector<tl_object_ptr<telegram_api::PeerLocated>> &&peers, bool from_update);

View File

@ -1464,17 +1464,22 @@ void UpdatesManager::process_seq_updates(int32 seq_end, int32 date,
}
}
void UpdatesManager::process_qts_update(tl_object_ptr<telegram_api::Update> &&update, int32 qts) {
LOG(DEBUG) << "Process " << to_string(update);
switch (update->get_id()) {
void UpdatesManager::process_qts_update(tl_object_ptr<telegram_api::Update> &&update_ptr, int32 qts) {
LOG(DEBUG) << "Process " << to_string(update_ptr);
switch (update_ptr->get_id()) {
case telegram_api::updateNewEncryptedMessage::ID: {
auto message = std::move(move_tl_object_as<telegram_api::updateNewEncryptedMessage>(update)->message_);
send_closure(td_->secret_chats_manager_, &SecretChatsManager::on_new_message, std::move(message), add_qts(qts));
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;
}
case telegram_api::updateChannelParticipant::ID:
// TODO
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->user_id_),
update->date_, std::move(update->prev_participant_),
std::move(update->new_participant_));
break;
}
default:
UNREACHABLE();
break;
@ -2152,7 +2157,16 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDeleteScheduled
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateLoginToken> update, bool /*force_apply*/) {
LOG(INFO) << "Receive updateLoginToken after authorization";
LOG(INFO) << "Ignore updateLoginToken after authorization";
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelParticipant> update, bool force_apply) {
if (force_apply) {
return process_qts_update(std::move(update), 0);
}
auto qts = update->qts_;
add_pending_qts_update(std::move(update), qts);
}
// unsupported updates
@ -2160,7 +2174,4 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateLoginToken> upd
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateTheme> update, bool /*force_apply*/) {
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelParticipant> update, bool /*force_apply*/) {
}
} // namespace td

View File

@ -154,7 +154,7 @@ class UpdatesManager : public Actor {
void process_seq_updates(int32 seq_end, int32 date, vector<tl_object_ptr<telegram_api::Update>> &&updates);
void process_qts_update(tl_object_ptr<telegram_api::Update> &&update, int32 qts);
void process_qts_update(tl_object_ptr<telegram_api::Update> &&update_ptr, int32 qts);
void process_pending_seq_updates();
@ -309,11 +309,11 @@ class UpdatesManager : public Actor {
void on_update(tl_object_ptr<telegram_api::updateLoginToken> update, bool /*force_apply*/);
void on_update(tl_object_ptr<telegram_api::updateChannelParticipant> update, bool /*force_apply*/);
// unsupported updates
void on_update(tl_object_ptr<telegram_api::updateTheme> update, bool /*force_apply*/);
void on_update(tl_object_ptr<telegram_api::updateChannelParticipant> update, bool /*force_apply*/);
};
} // namespace td