Move delete_dialog to DialogManager.

This commit is contained in:
levlam 2024-01-08 01:27:49 +03:00
parent 64c646b9de
commit b4ac2653cd
7 changed files with 32 additions and 38 deletions

View File

@ -48,7 +48,6 @@
#include "td/telegram/PremiumGiftOption.hpp" #include "td/telegram/PremiumGiftOption.hpp"
#include "td/telegram/ReactionManager.h" #include "td/telegram/ReactionManager.h"
#include "td/telegram/SecretChatLayer.h" #include "td/telegram/SecretChatLayer.h"
#include "td/telegram/SecretChatsManager.h"
#include "td/telegram/ServerMessageId.h" #include "td/telegram/ServerMessageId.h"
#include "td/telegram/StickerPhotoSize.h" #include "td/telegram/StickerPhotoSize.h"
#include "td/telegram/StickersManager.h" #include "td/telegram/StickersManager.h"
@ -8966,27 +8965,6 @@ void ContactsManager::delete_channel(ChannelId channel_id, Promise<Unit> &&promi
td_->create_handler<DeleteChannelQuery>(std::move(promise))->send(channel_id); td_->create_handler<DeleteChannelQuery>(std::move(promise))->send(channel_id);
} }
void ContactsManager::delete_dialog(DialogId dialog_id, Promise<Unit> &&promise) {
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "delete_dialog")) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
switch (dialog_id.get_type()) {
case DialogType::User:
return td_->messages_manager_->delete_dialog_history(dialog_id, true, true, std::move(promise));
case DialogType::Chat:
return delete_chat(dialog_id.get_chat_id(), std::move(promise));
case DialogType::Channel:
return delete_channel(dialog_id.get_channel_id(), std::move(promise));
case DialogType::SecretChat:
send_closure(td_->secret_chats_manager_, &SecretChatsManager::cancel_chat, dialog_id.get_secret_chat_id(), true,
std::move(promise));
return;
default:
UNREACHABLE();
}
}
void ContactsManager::send_update_add_chat_members_privacy_forbidden(DialogId dialog_id, vector<UserId> user_ids, void ContactsManager::send_update_add_chat_members_privacy_forbidden(DialogId dialog_id, vector<UserId> user_ids,
const char *source) { const char *source) {
td_->dialog_manager_->force_create_dialog(dialog_id, "send_update_add_chat_members_privacy_forbidden"); td_->dialog_manager_->force_create_dialog(dialog_id, "send_update_add_chat_members_privacy_forbidden");

View File

@ -521,7 +521,9 @@ class ContactsManager final : public Actor {
void report_channel_anti_spam_false_positive(ChannelId channel_id, MessageId message_id, Promise<Unit> &&promise); void report_channel_anti_spam_false_positive(ChannelId channel_id, MessageId message_id, Promise<Unit> &&promise);
void delete_dialog(DialogId dialog_id, Promise<Unit> &&promise); void delete_chat(ChatId chat_id, Promise<Unit> &&promise);
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 send_update_add_chat_members_privacy_forbidden(DialogId dialog_id, vector<UserId> user_ids, const char *source);
@ -1987,10 +1989,6 @@ class ContactsManager final : public Actor {
tl_object_ptr<telegram_api::InputCheckPasswordSRP> input_check_password, tl_object_ptr<telegram_api::InputCheckPasswordSRP> input_check_password,
Promise<Unit> &&promise); Promise<Unit> &&promise);
void delete_chat(ChatId chat_id, Promise<Unit> &&promise);
void delete_channel(ChannelId channel_id, Promise<Unit> &&promise);
void get_channel_statistics_dc_id_impl(ChannelId channel_id, bool for_full_statistics, Promise<DcId> &&promise); void get_channel_statistics_dc_id_impl(ChannelId channel_id, bool for_full_statistics, Promise<DcId> &&promise);
void on_get_support_user(UserId user_id, Promise<td_api::object_ptr<td_api::user>> &&promise); void on_get_support_user(UserId user_id, Promise<td_api::object_ptr<td_api::user>> &&promise);

View File

@ -19,6 +19,7 @@
#include "td/telegram/misc.h" #include "td/telegram/misc.h"
#include "td/telegram/ReportReason.h" #include "td/telegram/ReportReason.h"
#include "td/telegram/SecretChatId.h" #include "td/telegram/SecretChatId.h"
#include "td/telegram/SecretChatsManager.h"
#include "td/telegram/StickerPhotoSize.h" #include "td/telegram/StickerPhotoSize.h"
#include "td/telegram/Td.h" #include "td/telegram/Td.h"
#include "td/telegram/UpdatesManager.h" #include "td/telegram/UpdatesManager.h"
@ -849,6 +850,27 @@ bool DialogManager::on_get_dialog_error(DialogId dialog_id, const Status &status
return false; return false;
} }
void DialogManager::delete_dialog(DialogId dialog_id, Promise<Unit> &&promise) {
if (!have_dialog_force(dialog_id, "delete_dialog")) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
switch (dialog_id.get_type()) {
case DialogType::User:
return td_->messages_manager_->delete_dialog_history(dialog_id, true, true, std::move(promise));
case DialogType::Chat:
return td_->contacts_manager_->delete_chat(dialog_id.get_chat_id(), std::move(promise));
case DialogType::Channel:
return td_->contacts_manager_->delete_channel(dialog_id.get_channel_id(), std::move(promise));
case DialogType::SecretChat:
send_closure(td_->secret_chats_manager_, &SecretChatsManager::cancel_chat, dialog_id.get_secret_chat_id(), true,
std::move(promise));
return;
default:
UNREACHABLE();
}
}
string DialogManager::get_dialog_title(DialogId dialog_id) const { string DialogManager::get_dialog_title(DialogId dialog_id) const {
switch (dialog_id.get_type()) { switch (dialog_id.get_type()) {
case DialogType::User: case DialogType::User:

View File

@ -111,6 +111,8 @@ class DialogManager final : public Actor {
bool on_get_dialog_error(DialogId dialog_id, const Status &status, const char *source); bool on_get_dialog_error(DialogId dialog_id, const Status &status, const char *source);
void delete_dialog(DialogId dialog_id, Promise<Unit> &&promise);
string get_dialog_title(DialogId dialog_id) const; string get_dialog_title(DialogId dialog_id) const;
const DialogPhoto *get_dialog_photo(DialogId dialog_id) const; const DialogPhoto *get_dialog_photo(DialogId dialog_id) const;

View File

@ -18131,9 +18131,6 @@ DialogId MessagesManager::create_new_group_chat(const vector<UserId> &user_ids,
created_dialogs_.erase(it); created_dialogs_.erase(it);
// set default notification settings to newly created chat
on_update_dialog_notify_settings(dialog_id, nullptr, "create_new_group_chat");
promise.set_value(Unit()); promise.set_value(Unit());
return dialog_id; return dialog_id;
} }
@ -18181,9 +18178,6 @@ DialogId MessagesManager::create_new_channel_chat(const string &title, bool is_f
created_dialogs_.erase(it); created_dialogs_.erase(it);
// set default notification settings to newly created chat
on_update_dialog_notify_settings(dialog_id, nullptr, "create_new_channel_chat");
promise.set_value(Unit()); promise.set_value(Unit());
return dialog_id; return dialog_id;
} }

View File

@ -5374,7 +5374,7 @@ void Td::on_request(uint64 id, const td_api::deleteChat &request) {
send_closure(actor_id, &MessagesManager::on_dialog_deleted, dialog_id, std::move(promise)); send_closure(actor_id, &MessagesManager::on_dialog_deleted, dialog_id, std::move(promise));
} }
}; };
contacts_manager_->delete_dialog(dialog_id, std::move(query_promise)); dialog_manager_->delete_dialog(dialog_id, std::move(query_promise));
} }
void Td::on_request(uint64 id, const td_api::getMessageThreadHistory &request) { void Td::on_request(uint64 id, const td_api::getMessageThreadHistory &request) {
@ -6037,7 +6037,7 @@ void Td::on_request(uint64 id, const td_api::createSupergroupChat &request) {
CREATE_REQUEST(CreateChatRequest, DialogId(ChannelId(request.supergroup_id_)), request.force_); CREATE_REQUEST(CreateChatRequest, DialogId(ChannelId(request.supergroup_id_)), request.force_);
} }
void Td::on_request(uint64 id, td_api::createSecretChat &request) { void Td::on_request(uint64 id, const td_api::createSecretChat &request) {
CREATE_REQUEST(CreateChatRequest, DialogId(SecretChatId(request.secret_chat_id_)), true); CREATE_REQUEST(CreateChatRequest, DialogId(SecretChatId(request.secret_chat_id_)), true);
} }
@ -6057,7 +6057,7 @@ void Td::on_request(uint64 id, td_api::createNewSupergroupChat &request) {
request.message_auto_delete_time_); request.message_auto_delete_time_);
} }
void Td::on_request(uint64 id, td_api::createNewSecretChat &request) { void Td::on_request(uint64 id, const td_api::createNewSecretChat &request) {
CREATE_REQUEST(CreateNewSecretChatRequest, request.user_id_); CREATE_REQUEST(CreateNewSecretChatRequest, request.user_id_);
} }

View File

@ -896,13 +896,13 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::createSupergroupChat &request); void on_request(uint64 id, const td_api::createSupergroupChat &request);
void on_request(uint64 id, td_api::createSecretChat &request); void on_request(uint64 id, const td_api::createSecretChat &request);
void on_request(uint64 id, td_api::createNewBasicGroupChat &request); void on_request(uint64 id, td_api::createNewBasicGroupChat &request);
void on_request(uint64 id, td_api::createNewSupergroupChat &request); void on_request(uint64 id, td_api::createNewSupergroupChat &request);
void on_request(uint64 id, td_api::createNewSecretChat &request); void on_request(uint64 id, const td_api::createNewSecretChat &request);
void on_request(uint64 id, const td_api::createCall &request); void on_request(uint64 id, const td_api::createCall &request);