Process updateChatParticipant and updateBotStopped.
This commit is contained in:
parent
ad43c83bce
commit
fd190bc9bd
@ -12832,6 +12832,72 @@ void ContactsManager::on_update_channel_default_permissions(ChannelId channel_id
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::on_update_bot_stopped(UserId user_id, int32 date, bool is_stopped) {
|
||||
if (!td_->auth_manager_->is_bot()) {
|
||||
LOG(ERROR) << "Receive updateBotStopped by non-bot";
|
||||
return;
|
||||
}
|
||||
if (!user_id.is_valid() || date <= 0) {
|
||||
LOG(ERROR) << "Receive invalid updateBotStopped by " << user_id << " at " << date;
|
||||
return;
|
||||
}
|
||||
if (!have_user_force(user_id)) {
|
||||
LOG(ERROR) << "Receive updateBotStopped by unknown " << user_id;
|
||||
return;
|
||||
}
|
||||
|
||||
DialogParticipant old_dialog_participant(get_my_id(), user_id, date, DialogParticipantStatus::Banned(0));
|
||||
DialogParticipant new_dialog_participant(get_my_id(), user_id, date, DialogParticipantStatus::Member());
|
||||
if (is_stopped) {
|
||||
std::swap(old_dialog_participant.status, new_dialog_participant.status);
|
||||
}
|
||||
|
||||
// TODO send update
|
||||
}
|
||||
|
||||
void ContactsManager::on_update_chat_participant(ChatId chat_id, UserId user_id, int32 date,
|
||||
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;
|
||||
}
|
||||
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 << " for " << user_id << " at " << date << ": "
|
||||
<< to_string(old_participant) << " -> " << to_string(new_participant);
|
||||
return;
|
||||
}
|
||||
|
||||
const Chat *c = get_chat(chat_id);
|
||||
if (c == nullptr) {
|
||||
LOG(ERROR) << "Receive updateChatParticipant in unknown " << chat_id;
|
||||
return;
|
||||
}
|
||||
|
||||
DialogParticipant old_dialog_participant;
|
||||
DialogParticipant new_dialog_participant;
|
||||
if (old_participant != nullptr) {
|
||||
old_dialog_participant = DialogParticipant(std::move(old_participant), c->date, c->status.is_creator());
|
||||
if (new_participant == nullptr) {
|
||||
new_dialog_participant = DialogParticipant::left(old_dialog_participant.user_id);
|
||||
} else {
|
||||
new_dialog_participant = DialogParticipant(std::move(new_participant), c->date, c->status.is_creator());
|
||||
}
|
||||
} else {
|
||||
new_dialog_participant = DialogParticipant(std::move(new_participant), c->date, c->status.is_creator());
|
||||
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::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) {
|
||||
|
@ -210,6 +210,11 @@ class ContactsManager : public Actor {
|
||||
Promise<Unit> &&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_bot_stopped(UserId user_id, int32 date, bool is_stopped);
|
||||
void on_update_chat_participant(ChatId chat_id, UserId user_id, int32 date,
|
||||
tl_object_ptr<telegram_api::ChatParticipant> old_participant,
|
||||
tl_object_ptr<telegram_api::ChatParticipant> new_participant);
|
||||
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);
|
||||
|
@ -1954,6 +1954,19 @@ void UpdatesManager::process_qts_update(tl_object_ptr<telegram_api::Update> &&up
|
||||
add_qts(qts));
|
||||
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_,
|
||||
std::move(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->user_id_),
|
||||
update->date_, 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->user_id_),
|
||||
@ -2453,6 +2466,8 @@ int32 UpdatesManager::get_update_pts(const telegram_api::Update *update) {
|
||||
bool UpdatesManager::is_qts_update(const telegram_api::Update *update) {
|
||||
switch (update->get_id()) {
|
||||
case telegram_api::updateNewEncryptedMessage::ID:
|
||||
case telegram_api::updateBotStopped::ID:
|
||||
case telegram_api::updateChatParticipant::ID:
|
||||
case telegram_api::updateChannelParticipant::ID:
|
||||
return true;
|
||||
default:
|
||||
@ -2464,6 +2479,10 @@ int32 UpdatesManager::get_update_qts(const telegram_api::Update *update) {
|
||||
switch (update->get_id()) {
|
||||
case telegram_api::updateNewEncryptedMessage::ID:
|
||||
return static_cast<const telegram_api::updateNewEncryptedMessage *>(update)->qts_;
|
||||
case telegram_api::updateBotStopped::ID:
|
||||
return static_cast<const telegram_api::updateBotStopped *>(update)->qts_;
|
||||
case telegram_api::updateChatParticipant::ID:
|
||||
return static_cast<const telegram_api::updateChatParticipant *>(update)->qts_;
|
||||
case telegram_api::updateChannelParticipant::ID:
|
||||
return static_cast<const telegram_api::updateChannelParticipant *>(update)->qts_;
|
||||
default:
|
||||
@ -2850,6 +2869,16 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateLoginToken> upd
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
|
||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotStopped> update, Promise<Unit> &&promise) {
|
||||
auto qts = update->qts_;
|
||||
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
||||
}
|
||||
|
||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChatParticipant> update, Promise<Unit> &&promise) {
|
||||
auto qts = update->qts_;
|
||||
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
||||
}
|
||||
|
||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelParticipant> update, Promise<Unit> &&promise) {
|
||||
auto qts = update->qts_;
|
||||
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
||||
@ -2857,14 +2886,6 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelParticip
|
||||
|
||||
// unsupported updates
|
||||
|
||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotStopped> update, Promise<Unit> &&promise) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
|
||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChatParticipant> update, Promise<Unit> &&promise) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
|
||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateTheme> update, Promise<Unit> &&promise) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
|
@ -452,14 +452,12 @@ class UpdatesManager : public Actor {
|
||||
|
||||
void on_update(tl_object_ptr<telegram_api::updateLoginToken> update, Promise<Unit> &&promise);
|
||||
|
||||
void on_update(tl_object_ptr<telegram_api::updateBotStopped> update, Promise<Unit> &&promise);
|
||||
void on_update(tl_object_ptr<telegram_api::updateChatParticipant> update, Promise<Unit> &&promise);
|
||||
void on_update(tl_object_ptr<telegram_api::updateChannelParticipant> update, Promise<Unit> &&promise);
|
||||
|
||||
// unsupported updates
|
||||
|
||||
void on_update(tl_object_ptr<telegram_api::updateBotStopped> update, Promise<Unit> &&promise);
|
||||
|
||||
void on_update(tl_object_ptr<telegram_api::updateChatParticipant> update, Promise<Unit> &&promise);
|
||||
|
||||
void on_update(tl_object_ptr<telegram_api::updateTheme> update, Promise<Unit> &&promise);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user