Move send_update_add_chat_members_privacy_forbidden to DialogParticipantManager.

This commit is contained in:
levlam 2024-01-08 18:57:44 +03:00
parent 127b7ad086
commit 466c841b4e
7 changed files with 37 additions and 24 deletions

View File

@ -2196,8 +2196,8 @@ class AddChatUserQuery final : public Td::ResultHandler {
void on_error(Status status) final {
if (!td_->auth_manager_->is_bot() && status.message() == "USER_PRIVACY_RESTRICTED") {
td_->contacts_manager_->send_update_add_chat_members_privacy_forbidden(DialogId(chat_id_), {user_id_},
"AddChatUserQuery");
td_->dialog_participant_manager_->send_update_add_chat_members_privacy_forbidden(DialogId(chat_id_), {user_id_},
"AddChatUserQuery");
return promise_.set_error(Status::Error(406, "USER_PRIVACY_RESTRICTED"));
}
promise_.set_error(std::move(status));
@ -2240,8 +2240,8 @@ class EditChatAdminQuery final : public Td::ResultHandler {
void on_error(Status status) final {
if (!td_->auth_manager_->is_bot() && status.message() == "USER_PRIVACY_RESTRICTED") {
// impossible now, because the user must be in the chat already
td_->contacts_manager_->send_update_add_chat_members_privacy_forbidden(DialogId(chat_id_), {user_id_},
"EditChatAdminQuery");
td_->dialog_participant_manager_->send_update_add_chat_members_privacy_forbidden(DialogId(chat_id_), {user_id_},
"EditChatAdminQuery");
return promise_.set_error(Status::Error(406, "USER_PRIVACY_RESTRICTED"));
}
promise_.set_error(std::move(status));
@ -2349,8 +2349,8 @@ class EditChannelCreatorQuery final : public Td::ResultHandler {
void on_error(Status status) final {
if (!td_->auth_manager_->is_bot() && status.message() == "USER_PRIVACY_RESTRICTED") {
td_->contacts_manager_->send_update_add_chat_members_privacy_forbidden(DialogId(channel_id_), {user_id_},
"EditChannelCreatorQuery");
td_->dialog_participant_manager_->send_update_add_chat_members_privacy_forbidden(
DialogId(channel_id_), {user_id_}, "EditChannelCreatorQuery");
return promise_.set_error(Status::Error(406, "USER_PRIVACY_RESTRICTED"));
}
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "EditChannelCreatorQuery");
@ -7786,15 +7786,6 @@ void ContactsManager::delete_channel(ChannelId channel_id, Promise<Unit> &&promi
td_->create_handler<DeleteChannelQuery>(std::move(promise))->send(channel_id);
}
void ContactsManager::send_update_add_chat_members_privacy_forbidden(DialogId dialog_id, vector<UserId> user_ids,
const char *source) {
td_->dialog_manager_->force_create_dialog(dialog_id, "send_update_add_chat_members_privacy_forbidden");
send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updateAddChatMembersPrivacyForbidden>(
td_->dialog_manager_->get_chat_id_object(dialog_id, "updateAddChatMembersPrivacyForbidden"),
get_user_ids_object(user_ids, source)));
}
void ContactsManager::add_chat_participant(ChatId chat_id, UserId user_id, int32 forward_limit,
Promise<Unit> &&promise) {
const Chat *c = get_chat(chat_id);

View File

@ -504,8 +504,6 @@ class ContactsManager final : public Actor {
void delete_channel(ChannelId channel_id, Promise<Unit> &&promise);
void send_update_add_chat_members_privacy_forbidden(DialogId dialog_id, vector<UserId> user_ids, const char *source);
void get_channel_statistics_dc_id(DialogId dialog_id, bool for_full_statistics, Promise<DcId> &&promise);
bool can_get_channel_message_statistics(DialogId dialog_id) const;

View File

@ -435,8 +435,9 @@ class InviteToChannelQuery final : public Td::ResultHandler {
}
promise.set_value(Unit());
if (!user_ids.empty()) {
send_closure(G()->contacts_manager(), &ContactsManager::send_update_add_chat_members_privacy_forbidden,
dialog_id, std::move(user_ids), "InviteToChannelQuery");
send_closure(G()->dialog_participant_manager(),
&DialogParticipantManager::send_update_add_chat_members_privacy_forbidden, dialog_id,
std::move(user_ids), "InviteToChannelQuery");
}
});
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise));
@ -444,7 +445,7 @@ class InviteToChannelQuery final : public Td::ResultHandler {
void on_error(Status status) final {
if (!td_->auth_manager_->is_bot() && status.message() == "USER_PRIVACY_RESTRICTED") {
td_->contacts_manager_->send_update_add_chat_members_privacy_forbidden(
td_->dialog_participant_manager_->send_update_add_chat_members_privacy_forbidden(
DialogId(channel_id_), std::move(user_ids_), "InviteToChannelQuery");
return promise_.set_error(Status::Error(406, "USER_PRIVACY_RESTRICTED"));
}
@ -490,8 +491,8 @@ class EditChannelAdminQuery final : public Td::ResultHandler {
void on_error(Status status) final {
if (!td_->auth_manager_->is_bot() && status.message() == "USER_PRIVACY_RESTRICTED") {
td_->contacts_manager_->send_update_add_chat_members_privacy_forbidden(DialogId(channel_id_), {user_id_},
"EditChannelAdminQuery");
td_->dialog_participant_manager_->send_update_add_chat_members_privacy_forbidden(
DialogId(channel_id_), {user_id_}, "EditChannelAdminQuery");
return promise_.set_error(Status::Error(406, "USER_PRIVACY_RESTRICTED"));
}
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "EditChannelAdminQuery");
@ -1855,6 +1856,16 @@ void DialogParticipantManager::speculative_add_channel_user(ChannelId channel_id
td_->contacts_manager_->speculative_add_channel_user(channel_id, user_id, new_status, old_status);
}
void DialogParticipantManager::send_update_add_chat_members_privacy_forbidden(DialogId dialog_id,
vector<UserId> user_ids,
const char *source) {
td_->dialog_manager_->force_create_dialog(dialog_id, source);
send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updateAddChatMembersPrivacyForbidden>(
td_->dialog_manager_->get_chat_id_object(dialog_id, "updateAddChatMembersPrivacyForbidden"),
td_->contacts_manager_->get_user_ids_object(user_ids, source)));
}
void DialogParticipantManager::on_channel_participant_cache_timeout_callback(void *dialog_participant_manager_ptr,
int64 channel_id_long) {
if (G()->close_flag()) {

View File

@ -101,6 +101,8 @@ class DialogParticipantManager final : public Actor {
void on_set_channel_participant_status(ChannelId channel_id, DialogId participant_dialog_id,
DialogParticipantStatus status);
void send_update_add_chat_members_privacy_forbidden(DialogId dialog_id, vector<UserId> user_ids, const char *source);
bool have_channel_participant_cache(ChannelId channel_id) const;
void add_channel_participant_to_cache(ChannelId channel_id, const DialogParticipant &dialog_participant,

View File

@ -45,6 +45,7 @@ class DialogActionManager;
class DialogFilterManager;
class DialogInviteLinkManager;
class DialogManager;
class DialogParticipantManager;
class DownloadManager;
class FileManager;
class FileReferenceManager;
@ -276,6 +277,13 @@ class Global final : public ActorContext {
dialog_manager_ = std::move(dialog_manager);
}
ActorId<DialogParticipantManager> dialog_participant_manager() const {
return dialog_participant_manager_;
}
void set_dialog_participant_manager(ActorId<DialogParticipantManager> dialog_participant_manager) {
dialog_participant_manager_ = std::move(dialog_participant_manager);
}
ActorId<DownloadManager> download_manager() const {
return download_manager_;
}
@ -582,6 +590,7 @@ class Global final : public ActorContext {
ActorId<DialogFilterManager> dialog_filter_manager_;
ActorId<DialogInviteLinkManager> dialog_invite_link_manager_;
ActorId<DialogManager> dialog_manager_;
ActorId<DialogParticipantManager> dialog_participant_manager_;
ActorId<DownloadManager> download_manager_;
ActorId<FileManager> file_manager_;
ActorId<FileReferenceManager> file_reference_manager_;

View File

@ -30536,8 +30536,9 @@ void MessagesManager::on_create_new_dialog_success(int64 random_id, tl_object_pt
}
promise.set_value(Unit());
if (!user_ids.empty()) {
send_closure(G()->contacts_manager(), &ContactsManager::send_update_add_chat_members_privacy_forbidden,
dialog_id, std::move(user_ids), "on_create_new_dialog_success");
send_closure(G()->dialog_participant_manager(),
&DialogParticipantManager::send_update_add_chat_members_privacy_forbidden, dialog_id,
std::move(user_ids), "on_create_new_dialog_success");
}
});
pending_created_dialogs_.emplace(dialog_id, std::move(new_promise));

View File

@ -4033,6 +4033,7 @@ void Td::init_managers() {
G()->set_dialog_manager(dialog_manager_actor_.get());
dialog_participant_manager_ = make_unique<DialogParticipantManager>(this, create_reference());
dialog_participant_manager_actor_ = register_actor("DialogParticipantManager", dialog_participant_manager_.get());
G()->set_dialog_participant_manager(dialog_participant_manager_actor_.get());
download_manager_ = DownloadManager::create(td::make_unique<DownloadManagerCallback>(this, create_reference()));
download_manager_actor_ = register_actor("DownloadManager", download_manager_.get());
G()->set_download_manager(download_manager_actor_.get());