Move migrate_dialog_to_megagroup to DialogManager.
This commit is contained in:
parent
723ec5a203
commit
5a00fb2ba3
@ -2238,33 +2238,6 @@ class DeleteChannelQuery final : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class MigrateChatQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit MigrateChatQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(ChatId chat_id) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_migrateChat(chat_id.get()), {{chat_id}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_migrateChat>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for MigrateChatQuery: " << to_string(ptr);
|
||||
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class GetCreatedPublicChannelsQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
PublicDialogType type_;
|
||||
@ -7153,58 +7126,6 @@ void ContactsManager::delete_channel(ChannelId channel_id, Promise<Unit> &&promi
|
||||
td_->create_handler<DeleteChannelQuery>(std::move(promise))->send(channel_id);
|
||||
}
|
||||
|
||||
void ContactsManager::migrate_dialog_to_megagroup(DialogId dialog_id,
|
||||
Promise<td_api::object_ptr<td_api::chat>> &&promise) {
|
||||
LOG(INFO) << "Trying to upgrade " << dialog_id << " to a supergroup";
|
||||
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "migrate_dialog_to_megagroup")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
if (dialog_id.get_type() != DialogType::Chat) {
|
||||
return promise.set_error(Status::Error(400, "Only basic group chats can be converted to supergroup"));
|
||||
}
|
||||
|
||||
auto chat_id = dialog_id.get_chat_id();
|
||||
auto c = get_chat(chat_id);
|
||||
if (c == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Chat info not found"));
|
||||
}
|
||||
if (!c->status.is_creator()) {
|
||||
return promise.set_error(Status::Error(400, "Need creator rights in the chat"));
|
||||
}
|
||||
if (c->migrated_to_channel_id.is_valid()) {
|
||||
return on_migrate_chat_to_megagroup(chat_id, std::move(promise));
|
||||
}
|
||||
|
||||
auto query_promise = PromiseCreator::lambda(
|
||||
[actor_id = actor_id(this), chat_id, promise = std::move(promise)](Result<Unit> &&result) mutable {
|
||||
if (result.is_error()) {
|
||||
return promise.set_error(result.move_as_error());
|
||||
}
|
||||
send_closure(actor_id, &ContactsManager::on_migrate_chat_to_megagroup, chat_id, std::move(promise));
|
||||
});
|
||||
td_->create_handler<MigrateChatQuery>(std::move(query_promise))->send(chat_id);
|
||||
}
|
||||
|
||||
void ContactsManager::on_migrate_chat_to_megagroup(ChatId chat_id,
|
||||
Promise<td_api::object_ptr<td_api::chat>> &&promise) {
|
||||
auto c = get_chat(chat_id);
|
||||
CHECK(c != nullptr);
|
||||
if (!c->migrated_to_channel_id.is_valid()) {
|
||||
LOG(ERROR) << "Can't find the supergroup to which the basic group has migrated";
|
||||
return promise.set_error(Status::Error(500, "Supergroup not found"));
|
||||
}
|
||||
auto channel_id = c->migrated_to_channel_id;
|
||||
if (!have_channel(channel_id)) {
|
||||
LOG(ERROR) << "Can't find info about the supergroup to which the basic group has migrated";
|
||||
return promise.set_error(Status::Error(500, "Supergroup info is not found"));
|
||||
}
|
||||
|
||||
auto dialog_id = DialogId(channel_id);
|
||||
td_->dialog_manager_->force_create_dialog(dialog_id, "on_migrate_chat_to_megagroup");
|
||||
promise.set_value(td_->messages_manager_->get_chat_object(dialog_id));
|
||||
}
|
||||
|
||||
vector<ChannelId> ContactsManager::get_channel_ids(vector<tl_object_ptr<telegram_api::Chat>> &&chats,
|
||||
const char *source) {
|
||||
vector<ChannelId> channel_ids;
|
||||
|
@ -526,8 +526,6 @@ class ContactsManager final : public Actor {
|
||||
|
||||
bool can_get_channel_story_statistics(DialogId dialog_id) const;
|
||||
|
||||
void migrate_dialog_to_megagroup(DialogId dialog_id, Promise<td_api::object_ptr<td_api::chat>> &&promise);
|
||||
|
||||
void get_created_public_dialogs(PublicDialogType type, Promise<td_api::object_ptr<td_api::chats>> &&promise,
|
||||
bool from_binlog);
|
||||
|
||||
@ -1306,8 +1304,6 @@ class ContactsManager final : public Actor {
|
||||
|
||||
void send_get_chat_full_query(ChatId chat_id, Promise<Unit> &&promise, const char *source);
|
||||
|
||||
void on_migrate_chat_to_megagroup(ChatId chat_id, Promise<td_api::object_ptr<td_api::chat>> &&promise);
|
||||
|
||||
const Channel *get_channel(ChannelId channel_id) const;
|
||||
Channel *get_channel(ChannelId channel_id);
|
||||
Channel *get_channel_force(ChannelId channel_id, const char *source);
|
||||
|
@ -134,6 +134,33 @@ class ResolveUsernameQuery final : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class MigrateChatQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit MigrateChatQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(ChatId chat_id) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_migrateChat(chat_id.get()), {{chat_id}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_migrateChat>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for MigrateChatQuery: " << to_string(ptr);
|
||||
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class EditDialogTitleQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
DialogId dialog_id_;
|
||||
@ -857,6 +884,49 @@ NotificationSettingsScope DialogManager::get_dialog_notification_setting_scope(D
|
||||
}
|
||||
}
|
||||
|
||||
void DialogManager::migrate_dialog_to_megagroup(DialogId dialog_id,
|
||||
Promise<td_api::object_ptr<td_api::chat>> &&promise) {
|
||||
if (!have_dialog_force(dialog_id, "migrate_dialog_to_megagroup")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
if (dialog_id.get_type() != DialogType::Chat) {
|
||||
return promise.set_error(Status::Error(400, "Only basic group chats can be converted to supergroup"));
|
||||
}
|
||||
|
||||
auto chat_id = dialog_id.get_chat_id();
|
||||
if (!td_->contacts_manager_->get_chat_status(chat_id).is_creator()) {
|
||||
return promise.set_error(Status::Error(400, "Need creator rights in the chat"));
|
||||
}
|
||||
if (td_->contacts_manager_->get_chat_migrated_to_channel_id(chat_id).is_valid()) {
|
||||
return on_migrate_chat_to_megagroup(chat_id, std::move(promise));
|
||||
}
|
||||
|
||||
auto query_promise = PromiseCreator::lambda(
|
||||
[actor_id = actor_id(this), chat_id, promise = std::move(promise)](Result<Unit> &&result) mutable {
|
||||
if (result.is_error()) {
|
||||
return promise.set_error(result.move_as_error());
|
||||
}
|
||||
send_closure(actor_id, &DialogManager::on_migrate_chat_to_megagroup, chat_id, std::move(promise));
|
||||
});
|
||||
td_->create_handler<MigrateChatQuery>(std::move(query_promise))->send(chat_id);
|
||||
}
|
||||
|
||||
void DialogManager::on_migrate_chat_to_megagroup(ChatId chat_id, Promise<td_api::object_ptr<td_api::chat>> &&promise) {
|
||||
auto channel_id = td_->contacts_manager_->get_chat_migrated_to_channel_id(chat_id);
|
||||
if (!channel_id.is_valid()) {
|
||||
LOG(ERROR) << "Can't find the supergroup to which the basic group has migrated";
|
||||
return promise.set_error(Status::Error(500, "Supergroup not found"));
|
||||
}
|
||||
if (!td_->contacts_manager_->have_channel(channel_id)) {
|
||||
LOG(ERROR) << "Can't find info about the supergroup to which the basic group has migrated";
|
||||
return promise.set_error(Status::Error(500, "Supergroup info is not found"));
|
||||
}
|
||||
|
||||
auto dialog_id = DialogId(channel_id);
|
||||
force_create_dialog(dialog_id, "on_migrate_chat_to_megagroup");
|
||||
promise.set_value(td_->messages_manager_->get_chat_object(dialog_id));
|
||||
}
|
||||
|
||||
bool DialogManager::is_anonymous_administrator(DialogId dialog_id, string *author_signature) const {
|
||||
CHECK(dialog_id.is_valid());
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "td/telegram/AccentColorId.h"
|
||||
#include "td/telegram/AccessRights.h"
|
||||
#include "td/telegram/ChannelId.h"
|
||||
#include "td/telegram/ChatId.h"
|
||||
#include "td/telegram/CustomEmojiId.h"
|
||||
#include "td/telegram/DialogId.h"
|
||||
#include "td/telegram/DialogLocation.h"
|
||||
@ -108,6 +109,8 @@ class DialogManager final : public Actor {
|
||||
|
||||
NotificationSettingsScope get_dialog_notification_setting_scope(DialogId dialog_id) const;
|
||||
|
||||
void migrate_dialog_to_megagroup(DialogId dialog_id, Promise<td_api::object_ptr<td_api::chat>> &&promise);
|
||||
|
||||
bool is_anonymous_administrator(DialogId dialog_id, string *author_signature) const;
|
||||
|
||||
bool is_group_dialog(DialogId dialog_id) const;
|
||||
@ -219,6 +222,8 @@ class DialogManager final : public Actor {
|
||||
|
||||
void tear_down() final;
|
||||
|
||||
void on_migrate_chat_to_megagroup(ChatId chat_id, Promise<td_api::object_ptr<td_api::chat>> &&promise);
|
||||
|
||||
void on_upload_dialog_photo(FileId file_id, telegram_api::object_ptr<telegram_api::InputFile> input_file);
|
||||
|
||||
void on_upload_dialog_photo_error(FileId file_id, Status status);
|
||||
|
@ -6428,7 +6428,7 @@ void Td::on_request(uint64 id, td_api::getGroupCallStreamSegment &request) {
|
||||
void Td::on_request(uint64 id, const td_api::upgradeBasicGroupChatToSupergroupChat &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST_PROMISE();
|
||||
contacts_manager_->migrate_dialog_to_megagroup(DialogId(request.chat_id_), std::move(promise));
|
||||
dialog_manager_->migrate_dialog_to_megagroup(DialogId(request.chat_id_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getChatListsToAddChat &request) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user