Add updateChatDefaultBannedRights support.

GitOrigin-RevId: 1e938066789b61f5f14003c268a62965fcc31a30
This commit is contained in:
levlam 2019-03-20 16:32:27 +03:00
parent 454d8d3987
commit e71b749a79
4 changed files with 89 additions and 6 deletions

View File

@ -8287,6 +8287,53 @@ void ContactsManager::on_update_chat_status(Chat *c, ChatId chat_id, DialogParti
} }
} }
void ContactsManager::on_update_chat_default_permissions(ChatId chat_id, RestrictedRights default_permissions,
int32 version) {
if (!chat_id.is_valid()) {
LOG(ERROR) << "Receive invalid " << chat_id;
return;
}
LOG(INFO) << "Receive updateChatDefaultBannedRights in " << chat_id << " with " << default_permissions
<< " and version " << version << ". Current version is " << version;
auto c = get_chat_force(chat_id);
if (c == nullptr) {
LOG(INFO) << "Ignoring update about unknown " << chat_id;
return;
}
if (c->status.is_left()) {
// possible if updates come out of order
LOG(WARNING) << "Receive updateChatDefaultBannedRights for left " << chat_id << ". Couldn't apply it";
repair_chat_participants(chat_id); // just in case
return;
}
if (version <= -1) {
LOG(ERROR) << "Receive wrong version " << version << " for " << chat_id;
return;
}
CHECK(c->version >= 0);
if (version > c->version) {
if (version != c->version + 1) {
LOG(WARNING) << "Default permissions of " << chat_id << " with version " << c->version
<< " has changed but new version is " << version;
repair_chat_participants(chat_id);
return;
}
LOG_IF(ERROR, default_permissions == c->default_permissions)
<< "Receive updateChatDefaultBannedRights in " << chat_id << " with version " << version
<< " and default_permissions = " << default_permissions
<< ", but default_permissions are not changed. Current version is " << c->version;
c->version = version;
c->is_changed = true;
on_update_chat_default_permissions(c, chat_id, default_permissions);
update_chat(c, chat_id);
}
}
void ContactsManager::on_update_chat_default_permissions(Chat *c, ChatId chat_id, void ContactsManager::on_update_chat_default_permissions(Chat *c, ChatId chat_id,
RestrictedRights default_permissions) { RestrictedRights default_permissions) {
if (c->default_permissions != default_permissions) { if (c->default_permissions != default_permissions) {
@ -8516,7 +8563,7 @@ void ContactsManager::on_update_channel_username(ChannelId channel_id, string &&
on_update_channel_username(c, channel_id, std::move(username)); on_update_channel_username(c, channel_id, std::move(username));
update_channel(c, channel_id); update_channel(c, channel_id);
} else { } else {
LOG(ERROR) << "Ignore update channel username about unknown " << channel_id; LOG(INFO) << "Ignore update channel username about unknown " << channel_id;
} }
} }
@ -8585,6 +8632,22 @@ void ContactsManager::on_update_channel_is_all_history_available(ChannelId chann
} }
} }
void ContactsManager::on_update_channel_default_permissions(ChannelId channel_id,
RestrictedRights default_permissions) {
if (!channel_id.is_valid()) {
LOG(ERROR) << "Receive invalid " << channel_id;
return;
}
Channel *c = get_channel_force(channel_id);
if (c != nullptr) {
on_update_channel_default_permissions(c, channel_id, std::move(default_permissions));
update_channel(c, channel_id);
} else {
LOG(INFO) << "Ignore update channel default permissions about unknown " << channel_id;
}
}
void ContactsManager::update_contacts_hints(const User *u, UserId user_id, bool from_database) { void ContactsManager::update_contacts_hints(const User *u, UserId user_id, bool from_database) {
bool is_contact = u->outbound == LinkState::Contact && user_id != get_my_id(); bool is_contact = u->outbound == LinkState::Contact && user_id != get_my_id();
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot()) {

View File

@ -171,11 +171,13 @@ class ContactsManager : public Actor {
void on_update_chat_description(ChatId chat_id, string &&description); void on_update_chat_description(ChatId chat_id, string &&description);
void on_update_chat_edit_administrator(ChatId chat_id, UserId user_id, bool is_administrator, int32 version); void on_update_chat_edit_administrator(ChatId chat_id, UserId user_id, bool is_administrator, int32 version);
void on_update_chat_delete_user(ChatId chat_id, UserId user_id, int32 version); void on_update_chat_delete_user(ChatId chat_id, UserId user_id, int32 version);
void on_update_chat_default_permissions(ChatId chat_id, RestrictedRights default_permissions, int32 version);
void on_update_channel_username(ChannelId channel_id, string &&username); void on_update_channel_username(ChannelId channel_id, string &&username);
void on_update_channel_description(ChannelId channel_id, string &&description); void on_update_channel_description(ChannelId channel_id, string &&description);
void on_update_channel_sticker_set(ChannelId channel_id, int64 sticker_set_id); void on_update_channel_sticker_set(ChannelId channel_id, int64 sticker_set_id);
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);
void on_update_channel_default_permissions(ChannelId channel_id, RestrictedRights default_permissions);
void on_update_dialog_administrators(DialogId dialog_id, vector<UserId> administrator_user_ids, bool have_access); void on_update_dialog_administrators(DialogId dialog_id, vector<UserId> administrator_user_ids, bool have_access);

View File

@ -1678,6 +1678,27 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChatParticipant
update->version_); update->version_);
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChatDefaultBannedRights> update,
bool /*force_apply*/) {
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::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);
}
}
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDraftMessage> update, bool /*force_apply*/) { void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDraftMessage> update, bool /*force_apply*/) {
td_->messages_manager_->on_update_dialog_draft_message(DialogId(update->peer_), std::move(update->draft_)); td_->messages_manager_->on_update_dialog_draft_message(DialogId(update->peer_), std::move(update->draft_));
} }
@ -1839,8 +1860,4 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateMessagePoll> up
// unsupported updates // unsupported updates
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChatDefaultBannedRights> update,
bool /*force_apply*/) {
}
} // namespace td } // namespace td

View File

@ -196,6 +196,8 @@ class UpdatesManager : public Actor {
void on_update(tl_object_ptr<telegram_api::updateChatParticipantAdmin> update, bool /*force_apply*/); void on_update(tl_object_ptr<telegram_api::updateChatParticipantAdmin> update, bool /*force_apply*/);
void on_update(tl_object_ptr<telegram_api::updateChatParticipantDelete> update, bool /*force_apply*/); void on_update(tl_object_ptr<telegram_api::updateChatParticipantDelete> update, bool /*force_apply*/);
void on_update(tl_object_ptr<telegram_api::updateChatDefaultBannedRights> update, bool /*force_apply*/);
void on_update(tl_object_ptr<telegram_api::updateServiceNotification> update, bool force_apply); void on_update(tl_object_ptr<telegram_api::updateServiceNotification> update, bool force_apply);
void on_update(tl_object_ptr<telegram_api::updateDcOptions> update, bool /*force_apply*/); void on_update(tl_object_ptr<telegram_api::updateDcOptions> update, bool /*force_apply*/);
@ -263,7 +265,6 @@ class UpdatesManager : public Actor {
void on_update(tl_object_ptr<telegram_api::updateMessagePoll> update, bool /*force_apply*/); void on_update(tl_object_ptr<telegram_api::updateMessagePoll> update, bool /*force_apply*/);
// unsupported updates // unsupported updates
void on_update(tl_object_ptr<telegram_api::updateChatDefaultBannedRights> update, bool /*force_apply*/);
}; };
} // namespace td } // namespace td