Nullify pending_join_request_count if have no enough rights.
This commit is contained in:
parent
aee782562c
commit
0f6247f856
@ -9770,20 +9770,26 @@ void ContactsManager::update_chat(Chat *c, ChatId chat_id, bool from_binlog, boo
|
||||
if (c->is_photo_changed) {
|
||||
td_->messages_manager_->on_dialog_photo_updated(DialogId(chat_id));
|
||||
drop_chat_photos(chat_id, !c->photo.small_file_id.is_valid(), true, "update_chat");
|
||||
c->is_photo_changed = false;
|
||||
}
|
||||
if (c->is_title_changed) {
|
||||
td_->messages_manager_->on_dialog_title_updated(DialogId(chat_id));
|
||||
c->is_title_changed = false;
|
||||
}
|
||||
if (c->is_default_permissions_changed) {
|
||||
td_->messages_manager_->on_dialog_permissions_updated(DialogId(chat_id));
|
||||
c->is_default_permissions_changed = false;
|
||||
}
|
||||
if (c->is_is_active_changed) {
|
||||
update_dialogs_for_discussion(DialogId(chat_id), c->is_active && c->status.is_creator());
|
||||
c->is_is_active_changed = false;
|
||||
}
|
||||
if (c->is_status_changed) {
|
||||
if (!c->status.can_manage_invite_links()) {
|
||||
td_->messages_manager_->on_update_dialog_pending_join_request_count(DialogId(chat_id), 0);
|
||||
}
|
||||
c->is_status_changed = false;
|
||||
}
|
||||
c->is_photo_changed = false;
|
||||
c->is_title_changed = false;
|
||||
c->is_default_permissions_changed = false;
|
||||
c->is_is_active_changed = false;
|
||||
|
||||
LOG(DEBUG) << "Update " << chat_id << ": need_save_to_database = " << c->need_save_to_database
|
||||
<< ", is_changed = " << c->is_changed;
|
||||
@ -9819,9 +9825,11 @@ void ContactsManager::update_channel(Channel *c, ChannelId channel_id, bool from
|
||||
if (c->is_photo_changed) {
|
||||
td_->messages_manager_->on_dialog_photo_updated(DialogId(channel_id));
|
||||
drop_channel_photos(channel_id, !c->photo.small_file_id.is_valid(), true, "update_channel");
|
||||
c->is_photo_changed = false;
|
||||
}
|
||||
if (c->is_title_changed) {
|
||||
td_->messages_manager_->on_dialog_title_updated(DialogId(channel_id));
|
||||
c->is_title_changed = false;
|
||||
}
|
||||
if (c->is_status_changed) {
|
||||
c->status.update_restrictions();
|
||||
@ -9843,6 +9851,10 @@ void ContactsManager::update_channel(Channel *c, ChannelId channel_id, bool from
|
||||
if (!c->status.is_member()) {
|
||||
remove_inactive_channel(channel_id);
|
||||
}
|
||||
if (!c->status.can_manage_invite_links()) {
|
||||
td_->messages_manager_->on_update_dialog_pending_join_request_count(DialogId(channel_id), 0);
|
||||
}
|
||||
c->is_status_changed = false;
|
||||
}
|
||||
if (c->is_username_changed) {
|
||||
if (c->status.is_creator() && created_public_channels_inited_[0]) {
|
||||
@ -9854,6 +9866,7 @@ void ContactsManager::update_channel(Channel *c, ChannelId channel_id, bool from
|
||||
}
|
||||
}
|
||||
}
|
||||
c->is_username_changed = false;
|
||||
}
|
||||
if (c->is_default_permissions_changed) {
|
||||
td_->messages_manager_->on_dialog_permissions_updated(DialogId(channel_id));
|
||||
@ -9861,6 +9874,7 @@ void ContactsManager::update_channel(Channel *c, ChannelId channel_id, bool from
|
||||
RestrictedRights(false, false, false, false, false, false, false, false, false, false, false)) {
|
||||
remove_dialog_suggested_action(SuggestedAction{SuggestedAction::Type::ConvertToGigagroup, DialogId(channel_id)});
|
||||
}
|
||||
c->is_default_permissions_changed = false;
|
||||
}
|
||||
if (!td_->auth_manager_->is_bot()) {
|
||||
if (c->restriction_reasons.empty()) {
|
||||
@ -9870,12 +9884,6 @@ void ContactsManager::update_channel(Channel *c, ChannelId channel_id, bool from
|
||||
}
|
||||
}
|
||||
|
||||
c->is_photo_changed = false;
|
||||
c->is_title_changed = false;
|
||||
c->is_default_permissions_changed = false;
|
||||
c->is_status_changed = false;
|
||||
c->is_username_changed = false;
|
||||
|
||||
LOG(DEBUG) << "Update " << channel_id << ": need_save_to_database = " << c->need_save_to_database
|
||||
<< ", is_changed = " << c->is_changed;
|
||||
c->need_save_to_database |= c->is_changed;
|
||||
@ -12824,6 +12832,7 @@ void ContactsManager::on_update_chat_status(Chat *c, ChatId chat_id, DialogParti
|
||||
bool need_drop_invite_link = c->status.can_manage_invite_links() && !status.can_manage_invite_links();
|
||||
|
||||
c->status = std::move(status);
|
||||
c->is_status_changed = true;
|
||||
|
||||
if (c->status.is_left()) {
|
||||
c->participant_count = 0;
|
||||
|
@ -726,6 +726,7 @@ class ContactsManager final : public Actor {
|
||||
bool is_title_changed = true;
|
||||
bool is_photo_changed = true;
|
||||
bool is_default_permissions_changed = true;
|
||||
bool is_status_changed = true;
|
||||
bool is_is_active_changed = true;
|
||||
bool is_changed = true; // have new changes that need to be sent to the client and database
|
||||
bool need_save_to_database = true; // have new changes that need only to be saved to the database
|
||||
|
@ -20147,7 +20147,7 @@ td_api::object_ptr<td_api::chat> MessagesManager::get_chat_object(const Dialog *
|
||||
return make_tl_object<td_api::chat>(
|
||||
d->dialog_id.get(), get_chat_type_object(d->dialog_id), get_dialog_title(d->dialog_id),
|
||||
get_chat_photo_info_object(td_->file_manager_.get(), get_dialog_photo(d->dialog_id)),
|
||||
get_dialog_permissions(d->dialog_id).get_chat_permissions_object(),
|
||||
get_dialog_default_permissions(d->dialog_id).get_chat_permissions_object(),
|
||||
get_message_object(d->dialog_id, get_message(d, d->last_message_id), "get_chat_object"),
|
||||
get_chat_positions_object(d), d->is_marked_as_unread, d->is_blocked, get_dialog_has_scheduled_messages(d),
|
||||
can_delete_for_self, can_delete_for_all_users, can_report_dialog(d->dialog_id),
|
||||
@ -29904,6 +29904,36 @@ void MessagesManager::on_update_dialog_pending_join_request_count(DialogId dialo
|
||||
|
||||
void MessagesManager::set_dialog_pending_join_request_count(Dialog *d, int32 pending_join_request_count) {
|
||||
CHECK(d != nullptr);
|
||||
switch (d->dialog_id.get_type()) {
|
||||
case DialogType::User:
|
||||
case DialogType::SecretChat:
|
||||
pending_join_request_count = -1;
|
||||
break;
|
||||
case DialogType::Chat: {
|
||||
auto chat_id = d->dialog_id.get_chat_id();
|
||||
auto status = td_->contacts_manager_->get_chat_status(chat_id);
|
||||
if (!status.can_manage_invite_links()) {
|
||||
pending_join_request_count = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DialogType::Channel: {
|
||||
auto channel_id = d->dialog_id.get_channel_id();
|
||||
auto status = td_->contacts_manager_->get_channel_permissions(channel_id);
|
||||
if (!status.can_manage_invite_links()) {
|
||||
pending_join_request_count = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DialogType::None:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
if (pending_join_request_count < 0) {
|
||||
LOG(ERROR) << "Receive " << pending_join_request_count << " pending join requests in " << d->dialog_id;
|
||||
return;
|
||||
}
|
||||
|
||||
bool is_changed = d->pending_join_request_count != pending_join_request_count;
|
||||
if (!is_changed) {
|
||||
return;
|
||||
@ -30330,7 +30360,7 @@ void MessagesManager::on_dialog_permissions_updated(DialogId dialog_id) {
|
||||
if (d != nullptr && d->is_update_new_chat_sent) {
|
||||
send_closure(G()->td(), &Td::send_update,
|
||||
td_api::make_object<td_api::updateChatPermissions>(
|
||||
dialog_id.get(), get_dialog_permissions(dialog_id).get_chat_permissions_object()));
|
||||
dialog_id.get(), get_dialog_default_permissions(dialog_id).get_chat_permissions_object()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -30777,7 +30807,7 @@ string MessagesManager::get_dialog_username(DialogId dialog_id) const {
|
||||
}
|
||||
}
|
||||
|
||||
RestrictedRights MessagesManager::get_dialog_permissions(DialogId dialog_id) const {
|
||||
RestrictedRights MessagesManager::get_dialog_default_permissions(DialogId dialog_id) const {
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User:
|
||||
return td_->contacts_manager_->get_user_default_permissions(dialog_id.get_user_id());
|
||||
@ -31430,7 +31460,7 @@ void MessagesManager::set_dialog_permissions(DialogId dialog_id,
|
||||
auto new_permissions = get_restricted_rights(permissions);
|
||||
|
||||
// TODO this can be wrong if there was previous change permissions requests
|
||||
if (get_dialog_permissions(dialog_id) == new_permissions) {
|
||||
if (get_dialog_default_permissions(dialog_id) == new_permissions) {
|
||||
return promise.set_value(Unit());
|
||||
}
|
||||
|
||||
|
@ -2827,7 +2827,7 @@ class MessagesManager final : public Actor {
|
||||
|
||||
string get_dialog_username(DialogId dialog_id) const;
|
||||
|
||||
RestrictedRights get_dialog_permissions(DialogId dialog_id) const;
|
||||
RestrictedRights get_dialog_default_permissions(DialogId dialog_id) const;
|
||||
|
||||
bool get_dialog_has_scheduled_messages(const Dialog *d) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user