Move create_new_secret_chat to ContactsManager.
This commit is contained in:
parent
da031b3faa
commit
1bc8e90c10
@ -50,6 +50,7 @@
|
||||
#include "td/telegram/PremiumGiftOption.hpp"
|
||||
#include "td/telegram/ReactionManager.h"
|
||||
#include "td/telegram/SecretChatLayer.h"
|
||||
#include "td/telegram/SecretChatsManager.h"
|
||||
#include "td/telegram/ServerMessageId.h"
|
||||
#include "td/telegram/StickerPhotoSize.h"
|
||||
#include "td/telegram/StickersManager.h"
|
||||
@ -16488,6 +16489,33 @@ void ContactsManager::send_get_channel_full_query(ChannelFull *channel_full, Cha
|
||||
get_chat_full_queries_.add_query(DialogId(channel_id).get(), std::move(send_query), std::move(promise));
|
||||
}
|
||||
|
||||
void ContactsManager::create_new_secret_chat(UserId user_id, Promise<td_api::object_ptr<td_api::chat>> &&promise) {
|
||||
TRY_RESULT_PROMISE(promise, input_user, get_input_user(user_id));
|
||||
if (input_user->get_id() != telegram_api::inputUser::ID) {
|
||||
return promise.set_error(Status::Error(400, "Can't create secret chat with the user"));
|
||||
}
|
||||
auto user = static_cast<const telegram_api::inputUser *>(input_user.get());
|
||||
|
||||
send_closure(
|
||||
G()->secret_chats_manager(), &SecretChatsManager::create_chat, UserId(user->user_id_), user->access_hash_,
|
||||
PromiseCreator::lambda([actor_id = actor_id(this),
|
||||
promise = std::move(promise)](Result<SecretChatId> r_secret_chat_id) mutable {
|
||||
if (r_secret_chat_id.is_error()) {
|
||||
return promise.set_error(r_secret_chat_id.move_as_error());
|
||||
}
|
||||
send_closure(actor_id, &ContactsManager::on_create_new_secret_chat, r_secret_chat_id.ok(), std::move(promise));
|
||||
}));
|
||||
}
|
||||
|
||||
void ContactsManager::on_create_new_secret_chat(SecretChatId secret_chat_id,
|
||||
Promise<td_api::object_ptr<td_api::chat>> &&promise) {
|
||||
TRY_STATUS_PROMISE(promise, G()->close_status());
|
||||
CHECK(secret_chat_id.is_valid());
|
||||
DialogId dialog_id(secret_chat_id);
|
||||
td_->dialog_manager_->force_create_dialog(dialog_id, "on_create_new_secret_chat");
|
||||
promise.set_value(td_->messages_manager_->get_chat_object(dialog_id));
|
||||
}
|
||||
|
||||
bool ContactsManager::have_secret_chat(SecretChatId secret_chat_id) const {
|
||||
return secret_chats_.count(secret_chat_id) > 0;
|
||||
}
|
||||
|
@ -606,6 +606,8 @@ class ContactsManager final : public Actor {
|
||||
|
||||
bool is_channel_public(ChannelId channel_id) const;
|
||||
|
||||
void create_new_secret_chat(UserId user_id, Promise<td_api::object_ptr<td_api::chat>> &&promise);
|
||||
|
||||
bool have_secret_chat(SecretChatId secret_chat_id) const;
|
||||
bool have_secret_chat_force(SecretChatId secret_chat_id, const char *source);
|
||||
bool get_secret_chat(SecretChatId secret_chat_id, bool force, Promise<Unit> &&promise);
|
||||
@ -1346,6 +1348,8 @@ class ContactsManager final : public Actor {
|
||||
void send_get_channel_full_query(ChannelFull *channel_full, ChannelId channel_id, Promise<Unit> &&promise,
|
||||
const char *source);
|
||||
|
||||
void on_create_new_secret_chat(SecretChatId secret_chat_id, Promise<td_api::object_ptr<td_api::chat>> &&promise);
|
||||
|
||||
const SecretChat *get_secret_chat(SecretChatId secret_chat_id) const;
|
||||
SecretChat *get_secret_chat(SecretChatId secret_chat_id);
|
||||
SecretChat *get_secret_chat_force(SecretChatId secret_chat_id, const char *source);
|
||||
|
@ -18202,17 +18202,6 @@ DialogId MessagesManager::create_new_channel_chat(const string &title, bool is_f
|
||||
return DialogId();
|
||||
}
|
||||
|
||||
void MessagesManager::create_new_secret_chat(UserId user_id, Promise<SecretChatId> &&promise) {
|
||||
TRY_RESULT_PROMISE(promise, input_user, td_->contacts_manager_->get_input_user(user_id));
|
||||
if (input_user->get_id() != telegram_api::inputUser::ID) {
|
||||
return promise.set_error(Status::Error(400, "Can't create secret chat with the user"));
|
||||
}
|
||||
auto user = static_cast<const telegram_api::inputUser *>(input_user.get());
|
||||
|
||||
send_closure(G()->secret_chats_manager(), &SecretChatsManager::create_chat, UserId(user->user_id_),
|
||||
user->access_hash_, std::move(promise));
|
||||
}
|
||||
|
||||
DialogId MessagesManager::migrate_dialog_to_megagroup(DialogId dialog_id, Promise<Unit> &&promise) {
|
||||
LOG(INFO) << "Trying to convert " << dialog_id << " to supergroup";
|
||||
|
||||
|
@ -641,8 +641,6 @@ class MessagesManager final : public Actor {
|
||||
const DialogLocation &location, bool for_import, MessageTtl message_ttl,
|
||||
int64 &random_id, Promise<Unit> &&promise);
|
||||
|
||||
void create_new_secret_chat(UserId user_id, Promise<SecretChatId> &&promise);
|
||||
|
||||
DialogId migrate_dialog_to_megagroup(DialogId dialog_id, Promise<Unit> &&promise);
|
||||
|
||||
bool is_dialog_opened(DialogId dialog_id) const;
|
||||
|
@ -1680,41 +1680,6 @@ class CreateNewGroupChatRequest final : public RequestActor<> {
|
||||
}
|
||||
};
|
||||
|
||||
class CreateNewSecretChatRequest final : public RequestActor<SecretChatId> {
|
||||
UserId user_id_;
|
||||
SecretChatId secret_chat_id_;
|
||||
|
||||
void do_run(Promise<SecretChatId> &&promise) final {
|
||||
if (get_tries() < 2) {
|
||||
promise.set_value(std::move(secret_chat_id_));
|
||||
return;
|
||||
}
|
||||
td_->messages_manager_->create_new_secret_chat(user_id_, std::move(promise));
|
||||
}
|
||||
|
||||
void do_set_result(SecretChatId &&result) final {
|
||||
secret_chat_id_ = result;
|
||||
LOG(INFO) << "New " << secret_chat_id_ << " created";
|
||||
}
|
||||
|
||||
void do_send_result() final {
|
||||
CHECK(secret_chat_id_.is_valid());
|
||||
// SecretChatActor will send this update by itself
|
||||
// But since the update may still be on its way, we will update essential fields here.
|
||||
td_->contacts_manager_->on_update_secret_chat(
|
||||
secret_chat_id_, 0 /* no access_hash */, user_id_, SecretChatState::Unknown, true /* it is outbound chat */,
|
||||
-1 /* unknown TTL */, 0 /* unknown creation date */, "" /* no key_hash */, 0, FolderId());
|
||||
DialogId dialog_id(secret_chat_id_);
|
||||
td_->dialog_manager_->force_create_dialog(dialog_id, "create new secret chat", true);
|
||||
send_result(td_->messages_manager_->get_chat_object(dialog_id));
|
||||
}
|
||||
|
||||
public:
|
||||
CreateNewSecretChatRequest(ActorShared<Td> td, uint64 request_id, int64 user_id)
|
||||
: RequestActor(std::move(td), request_id), user_id_(user_id) {
|
||||
}
|
||||
};
|
||||
|
||||
class CreateNewSupergroupChatRequest final : public RequestActor<> {
|
||||
string title_;
|
||||
bool is_forum_;
|
||||
@ -6066,7 +6031,9 @@ void Td::on_request(uint64 id, td_api::createNewSupergroupChat &request) {
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::createNewSecretChat &request) {
|
||||
CREATE_REQUEST(CreateNewSecretChatRequest, request.user_id_);
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST_PROMISE();
|
||||
contacts_manager_->create_new_secret_chat(UserId(request.user_id_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::createCall &request) {
|
||||
|
Loading…
Reference in New Issue
Block a user