From 4d51b2c875fe49af1e2e9e4e47f81cd84a5c692c Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 10 Jan 2024 17:09:09 +0300 Subject: [PATCH] Move create_new_chat/create_new_channel to ContactsManager. --- td/telegram/ContactsManager.cpp | 102 +++++++++++++ td/telegram/ContactsManager.h | 9 ++ td/telegram/MessagesManager.cpp | 245 +++++--------------------------- td/telegram/MessagesManager.h | 23 +-- td/telegram/Td.cpp | 81 ++--------- 5 files changed, 158 insertions(+), 302 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 2b34205bf..63f72447a 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -1092,6 +1092,76 @@ class UpdateEmojiStatusQuery final : public Td::ResultHandler { } }; +class CreateChatQuery final : public Td::ResultHandler { + Promise> promise_; + + public: + explicit CreateChatQuery(Promise> &&promise) : promise_(std::move(promise)) { + } + + void send(vector> &&input_users, const string &title, MessageTtl message_ttl) { + int32 flags = telegram_api::messages_createChat::TTL_PERIOD_MASK; + send_query(G()->net_query_creator().create( + telegram_api::messages_createChat(flags, std::move(input_users), title, message_ttl.get_input_ttl_period()))); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + td_->messages_manager_->on_create_new_dialog(result_ptr.move_as_ok(), DialogType::Chat, std::move(promise_)); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + +class CreateChannelQuery final : public Td::ResultHandler { + Promise> promise_; + + public: + explicit CreateChannelQuery(Promise> &&promise) : promise_(std::move(promise)) { + } + + void send(const string &title, bool is_forum, bool is_megagroup, const string &about, const DialogLocation &location, + bool for_import, MessageTtl message_ttl) { + int32 flags = telegram_api::channels_createChannel::TTL_PERIOD_MASK; + if (is_forum) { + flags |= telegram_api::channels_createChannel::FORUM_MASK; + } else if (is_megagroup) { + flags |= telegram_api::channels_createChannel::MEGAGROUP_MASK; + } else { + flags |= telegram_api::channels_createChannel::BROADCAST_MASK; + } + if (!location.empty()) { + flags |= telegram_api::channels_createChannel::GEO_POINT_MASK; + } + if (for_import) { + flags |= telegram_api::channels_createChannel::FOR_IMPORT_MASK; + } + + send_query(G()->net_query_creator().create(telegram_api::channels_createChannel( + flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, title, about, + location.get_input_geo_point(), location.get_address(), message_ttl.get_input_ttl_period()))); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + td_->messages_manager_->on_create_new_dialog(result_ptr.move_as_ok(), DialogType::Channel, std::move(promise_)); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class UpdateChannelUsernameQuery final : public Td::ResultHandler { Promise promise_; ChannelId channel_id_; @@ -15920,6 +15990,38 @@ FileSourceId ContactsManager::get_channel_full_file_source_id(ChannelId channel_ return source_id; } +void ContactsManager::create_new_chat(const vector &user_ids, const string &title, MessageTtl message_ttl, + Promise> &&promise) { + auto new_title = clean_name(title, MAX_TITLE_LENGTH); + if (new_title.empty()) { + return promise.set_error(Status::Error(400, "Title must be non-empty")); + } + + vector> input_users; + for (auto user_id : user_ids) { + auto r_input_user = td_->contacts_manager_->get_input_user(user_id); + if (r_input_user.is_error()) { + return promise.set_error(r_input_user.move_as_error()); + } + input_users.push_back(r_input_user.move_as_ok()); + } + + td_->create_handler(std::move(promise))->send(std::move(input_users), new_title, message_ttl); +} + +void ContactsManager::create_new_channel(const string &title, bool is_forum, bool is_megagroup, + const string &description, const DialogLocation &location, bool for_import, + MessageTtl message_ttl, Promise> &&promise) { + auto new_title = clean_name(title, MAX_TITLE_LENGTH); + if (new_title.empty()) { + return promise.set_error(Status::Error(400, "Title must be non-empty")); + } + + td_->create_handler(std::move(promise)) + ->send(new_title, is_forum, is_megagroup, strip_empty_characters(description, MAX_DESCRIPTION_LENGTH), location, + for_import, message_ttl); +} + bool ContactsManager::have_chat(ChatId chat_id) const { return chats_.count(chat_id) > 0; } diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 3a6f8f94b..c8c616dfc 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -27,6 +27,7 @@ #include "td/telegram/Location.h" #include "td/telegram/MessageFullId.h" #include "td/telegram/MessageId.h" +#include "td/telegram/MessageTtl.h" #include "td/telegram/net/DcId.h" #include "td/telegram/Photo.h" #include "td/telegram/PremiumGiftOption.h" @@ -576,6 +577,9 @@ class ContactsManager final : public Actor { void reload_user_profile_photo(UserId user_id, int64 photo_id, Promise &&promise); FileSourceId get_user_profile_photo_file_source_id(UserId user_id, int64 photo_id); + void create_new_chat(const vector &user_ids, const string &title, MessageTtl message_ttl, + Promise> &&promise); + bool have_chat(ChatId chat_id) const; bool have_chat_force(ChatId chat_id, const char *source); bool get_chat(ChatId chat_id, int left_tries, Promise &&promise); @@ -592,6 +596,10 @@ class ContactsManager final : public Actor { DialogParticipantStatus get_chat_permissions(ChatId chat_id) const; bool is_appointed_chat_administrator(ChatId chat_id) const; + void create_new_channel(const string &title, bool is_forum, bool is_megagroup, const string &description, + const DialogLocation &location, bool for_import, MessageTtl message_ttl, + Promise> &&promise); + bool have_min_channel(ChannelId channel_id) const; const MinChannel *get_min_channel(ChannelId channel_id) const; void add_min_channel(ChannelId channel_id, const MinChannel &min_channel); @@ -1153,6 +1161,7 @@ class ContactsManager final : public Actor { static constexpr int32 MAX_GET_PROFILE_PHOTOS = 100; // server side limit static constexpr size_t MAX_NAME_LENGTH = 64; // server side limit for first/last name + static constexpr size_t MAX_TITLE_LENGTH = 128; // server side limit for chat title static constexpr size_t MAX_DESCRIPTION_LENGTH = 255; // server side limit for chat/channel description static constexpr int32 MAX_GET_CHANNEL_PARTICIPANTS = 200; // server side limit diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index eec286b0f..1a8feaf48 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -22,7 +22,6 @@ #include "td/telegram/DialogDb.h" #include "td/telegram/DialogFilter.h" #include "td/telegram/DialogFilterManager.h" -#include "td/telegram/DialogLocation.h" #include "td/telegram/DialogManager.h" #include "td/telegram/DialogNotificationSettings.hpp" #include "td/telegram/DialogParticipantManager.h" @@ -729,87 +728,6 @@ class GetBlockedDialogsQuery final : public Td::ResultHandler { } }; -class CreateChatQuery final : public Td::ResultHandler { - Promise promise_; - int64 random_id_; - - public: - explicit CreateChatQuery(Promise &&promise) : promise_(std::move(promise)) { - } - - void send(vector> &&input_users, const string &title, MessageTtl message_ttl, - int64 random_id) { - random_id_ = random_id; - int32 flags = telegram_api::messages_createChat::TTL_PERIOD_MASK; - send_query(G()->net_query_creator().create( - telegram_api::messages_createChat(flags, std::move(input_users), title, message_ttl.get_input_ttl_period()))); - } - - void on_result(BufferSlice packet) final { - auto result_ptr = fetch_result(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 CreateChatQuery: " << to_string(ptr); - td_->messages_manager_->on_create_new_dialog_success(random_id_, std::move(ptr), DialogType::Chat, - std::move(promise_)); - } - - void on_error(Status status) final { - td_->messages_manager_->on_create_new_dialog_fail(random_id_, std::move(status), std::move(promise_)); - } -}; - -class CreateChannelQuery final : public Td::ResultHandler { - Promise promise_; - int64 random_id_; - - public: - explicit CreateChannelQuery(Promise &&promise) : promise_(std::move(promise)) { - } - - void send(const string &title, bool is_forum, bool is_megagroup, const string &about, const DialogLocation &location, - bool for_import, MessageTtl message_ttl, int64 random_id) { - int32 flags = telegram_api::channels_createChannel::TTL_PERIOD_MASK; - if (is_forum) { - flags |= telegram_api::channels_createChannel::FORUM_MASK; - } else if (is_megagroup) { - flags |= telegram_api::channels_createChannel::MEGAGROUP_MASK; - } else { - flags |= telegram_api::channels_createChannel::BROADCAST_MASK; - } - if (!location.empty()) { - flags |= telegram_api::channels_createChannel::GEO_POINT_MASK; - } - if (for_import) { - flags |= telegram_api::channels_createChannel::FOR_IMPORT_MASK; - } - - random_id_ = random_id; - send_query(G()->net_query_creator().create(telegram_api::channels_createChannel( - flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, title, about, - location.get_input_geo_point(), location.get_address(), message_ttl.get_input_ttl_period()))); - } - - void on_result(BufferSlice packet) final { - auto result_ptr = fetch_result(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 CreateChannelQuery: " << to_string(ptr); - td_->messages_manager_->on_create_new_dialog_success(random_id_, std::move(ptr), DialogType::Channel, - std::move(promise_)); - } - - void on_error(Status status) final { - td_->messages_manager_->on_create_new_dialog_fail(random_id_, std::move(status), std::move(promise_)); - } -}; - class SetChatAvailableReactionsQuery final : public Td::ResultHandler { Promise promise_; DialogId dialog_id_; @@ -13377,13 +13295,6 @@ MessageFullId MessagesManager::on_get_message(MessageInfo &&message_info, const return MessageFullId(); } - auto pcc_it = pending_created_dialogs_.find(dialog_id); - if (from_update && pcc_it != pending_created_dialogs_.end()) { - pcc_it->second.set_value(Unit()); - - pending_created_dialogs_.erase(pcc_it); - } - if (need_update) { send_update_new_message(d, m); } @@ -13424,6 +13335,21 @@ MessageFullId MessagesManager::on_get_message(MessageInfo &&message_info, const set_dialog_reply_markup(d, message_id); } + if (from_update) { + auto it = pending_created_dialogs_.find(dialog_id); + if (it != pending_created_dialogs_.end()) { + auto pending_created_dialog = std::move(it->second); + pending_created_dialogs_.erase(it); + + pending_created_dialog.promise_.set_value(get_chat_object(d)); + if (!pending_created_dialog.group_invite_privacy_forbidden_user_ids_.empty()) { + send_closure(G()->dialog_participant_manager(), + &DialogParticipantManager::send_update_add_chat_members_privacy_forbidden, dialog_id, + std::move(pending_created_dialog.group_invite_privacy_forbidden_user_ids_), "on_get_message"); + } + } + } + return MessageFullId(dialog_id, message_id); } @@ -18120,88 +18046,6 @@ void MessagesManager::create_dialog(DialogId dialog_id, bool force, Promise &user_ids, const string &title, - MessageTtl message_ttl, int64 &random_id, Promise &&promise) { - LOG(INFO) << "Trying to create group chat \"" << title << "\" with members " << format::as_array(user_ids); - - if (random_id != 0) { - // request has already been sent before - auto it = created_dialogs_.find(random_id); - CHECK(it != created_dialogs_.end()); - auto dialog_id = it->second; - CHECK(dialog_id.get_type() == DialogType::Chat); - CHECK(have_dialog(dialog_id)); - - created_dialogs_.erase(it); - - promise.set_value(Unit()); - return dialog_id; - } - - auto new_title = clean_name(title, MAX_TITLE_LENGTH); - if (new_title.empty()) { - promise.set_error(Status::Error(400, "Title must be non-empty")); - return DialogId(); - } - - vector> input_users; - for (auto user_id : user_ids) { - auto r_input_user = td_->contacts_manager_->get_input_user(user_id); - if (r_input_user.is_error()) { - promise.set_error(r_input_user.move_as_error()); - return DialogId(); - } - input_users.push_back(r_input_user.move_as_ok()); - } - - do { - random_id = Random::secure_int64(); - } while (random_id == 0 || created_dialogs_.count(random_id) > 0); - created_dialogs_[random_id]; // reserve place for result - - td_->create_handler(std::move(promise)) - ->send(std::move(input_users), new_title, message_ttl, random_id); - return DialogId(); -} - -DialogId MessagesManager::create_new_channel_chat(const string &title, bool is_forum, bool is_megagroup, - const string &description, const DialogLocation &location, - bool for_import, MessageTtl message_ttl, int64 &random_id, - Promise &&promise) { - LOG(INFO) << "Trying to create " << (is_megagroup ? "supergroup" : "broadcast") << " with title \"" << title - << "\", description \"" << description << "\" and " << location; - - if (random_id != 0) { - // request has already been sent before - auto it = created_dialogs_.find(random_id); - CHECK(it != created_dialogs_.end()); - auto dialog_id = it->second; - CHECK(dialog_id.get_type() == DialogType::Channel); - CHECK(have_dialog(dialog_id)); - - created_dialogs_.erase(it); - - promise.set_value(Unit()); - return dialog_id; - } - - auto new_title = clean_name(title, MAX_TITLE_LENGTH); - if (new_title.empty()) { - promise.set_error(Status::Error(400, "Title must be non-empty")); - return DialogId(); - } - - do { - random_id = Random::secure_int64(); - } while (random_id == 0 || created_dialogs_.count(random_id) > 0); - created_dialogs_[random_id]; // reserve place for result - - td_->create_handler(std::move(promise)) - ->send(new_title, is_forum, is_megagroup, strip_empty_characters(description, MAX_DESCRIPTION_LENGTH), location, - for_import, message_ttl, random_id); - return DialogId(); -} - bool MessagesManager::is_dialog_opened(DialogId dialog_id) const { const Dialog *d = get_dialog(dialog_id); return d != nullptr && d->open_count > 0; @@ -30440,13 +30284,16 @@ void MessagesManager::set_dialog_message_ttl(Dialog *d, MessageTtl message_ttl) } } -void MessagesManager::on_create_new_dialog_success(int64 random_id, tl_object_ptr &&updates, - DialogType expected_type, Promise &&promise) { +void MessagesManager::on_create_new_dialog(telegram_api::object_ptr &&updates, + DialogType expected_type, + Promise> &&promise) { + LOG(INFO) << "Receive result for creation of a chat: " << to_string(updates); + auto sent_messages = UpdatesManager::get_new_messages(updates.get()); auto sent_messages_random_ids = UpdatesManager::get_sent_messages_random_ids(updates.get()); if (sent_messages.size() != 1u || sent_messages_random_ids.size() != 1u) { LOG(ERROR) << "Receive wrong result for create group or channel chat " << oneline(to_string(updates)); - return on_create_new_dialog_fail(random_id, Status::Error(500, "Unsupported server response"), std::move(promise)); + return promise.set_error(Status::Error(500, "Unsupported server response")); } auto *message = sent_messages.begin()->first; @@ -30454,72 +30301,44 @@ void MessagesManager::on_create_new_dialog_success(int64 random_id, tl_object_pt // TODO check that message_random_id equals random_id after messages_createChat will be updated if (sent_messages.begin()->second) { - return on_create_new_dialog_fail(random_id, Status::Error(500, "Scheduled message received"), std::move(promise)); + return promise.set_error(Status::Error(500, "Scheduled message received")); } auto dialog_id = DialogId::get_message_dialog_id(message); if (dialog_id.get_type() != expected_type) { - return on_create_new_dialog_fail(random_id, Status::Error(500, "Chat of wrong type has been created"), - std::move(promise)); + return promise.set_error(Status::Error(500, "Chat of wrong type has been created")); } if (message->get_id() != telegram_api::messageService::ID) { - return on_create_new_dialog_fail(random_id, Status::Error(500, "Invalid message received"), std::move(promise)); + return promise.set_error(Status::Error(500, "Invalid message received")); } auto action_id = static_cast(message)->action_->get_id(); if (action_id != telegram_api::messageActionChatCreate::ID && action_id != telegram_api::messageActionChannelCreate::ID) { - return on_create_new_dialog_fail(random_id, Status::Error(500, "Invalid service message received"), - std::move(promise)); + return promise.set_error(Status::Error(500, "Invalid service message received")); } - auto it = created_dialogs_.find(random_id); - CHECK(it != created_dialogs_.end()); - CHECK(it->second == DialogId()); - - it->second = dialog_id; - const Dialog *d = get_dialog(dialog_id); if (d != nullptr && d->last_new_message_id.is_valid()) { // dialog have been already created and at least one non-temporary message was added, // i.e. we are not interested in the creation of dialog by searchMessages // then messages have already been added, so just set promise - return promise.set_value(Unit()); + return promise.set_value(get_chat_object(d)); } if (pending_created_dialogs_.count(dialog_id) == 0) { - auto user_ids = td_->updates_manager_->extract_group_invite_privacy_forbidden_updates(updates); - auto new_promise = PromiseCreator::lambda( - [dialog_id, user_ids = std::move(user_ids), promise = std::move(promise)](Result &&result) mutable { - if (result.is_error()) { - return promise.set_error(result.move_as_error()); - } - promise.set_value(Unit()); - if (!user_ids.empty()) { - 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)); + PendingCreatedDialog pending_created_dialog; + pending_created_dialog.promise_ = std::move(promise); + pending_created_dialog.group_invite_privacy_forbidden_user_ids_ = + td_->updates_manager_->extract_group_invite_privacy_forbidden_updates(updates); + pending_created_dialogs_.emplace(dialog_id, std::move(pending_created_dialog)); } else { LOG(ERROR) << "Receive twice " << dialog_id << " as result of chat creation"; - return on_create_new_dialog_fail(random_id, Status::Error(500, "Chat was created earlier"), std::move(promise)); + return promise.set_error(Status::Error(500, "Chat was created earlier")); } td_->updates_manager_->on_get_updates(std::move(updates), Promise()); } -void MessagesManager::on_create_new_dialog_fail(int64 random_id, Status error, Promise &&promise) { - LOG(INFO) << "Clean up creation of group or channel chat"; - auto it = created_dialogs_.find(random_id); - CHECK(it != created_dialogs_.end()); - CHECK(it->second == DialogId()); - created_dialogs_.erase(it); - - CHECK(error.is_error()); - promise.set_error(std::move(error)); -} - void MessagesManager::on_dialog_bots_updated(DialogId dialog_id, vector bot_user_ids, bool from_database) { if (td_->auth_manager_->is_bot()) { return; diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index d4065e9d9..2d1787e37 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -16,7 +16,6 @@ #include "td/telegram/DialogFilterId.h" #include "td/telegram/DialogId.h" #include "td/telegram/DialogListId.h" -#include "td/telegram/DialogLocation.h" #include "td/telegram/DialogNotificationSettings.h" #include "td/telegram/DialogParticipant.h" #include "td/telegram/DialogSource.h" @@ -634,13 +633,6 @@ class MessagesManager final : public Actor { void create_dialog(DialogId dialog_id, bool force, Promise &&promise); - DialogId create_new_group_chat(const vector &user_ids, const string &title, MessageTtl message_ttl, - int64 &random_id, Promise &&promise); - - DialogId create_new_channel_chat(const string &title, bool is_forum, bool is_megagroup, const string &description, - const DialogLocation &location, bool for_import, MessageTtl message_ttl, - int64 &random_id, Promise &&promise); - bool is_dialog_opened(DialogId dialog_id) const; Status open_dialog(DialogId dialog_id) TD_WARN_UNUSED_RESULT; @@ -857,10 +849,8 @@ class MessagesManager final : public Actor { void on_upload_message_media_fail(DialogId dialog_id, MessageId message_id, Status error); - void on_create_new_dialog_success(int64 random_id, tl_object_ptr &&updates, - DialogType expected_type, Promise &&promise); - - void on_create_new_dialog_fail(int64 random_id, Status error, Promise &&promise); + void on_create_new_dialog(telegram_api::object_ptr &&updates, DialogType expected_type, + Promise> &&promise); void on_get_channel_difference(DialogId dialog_id, int32 request_pts, int32 request_limit, tl_object_ptr &&difference_ptr, @@ -1584,8 +1574,6 @@ class MessagesManager final : public Actor { static constexpr int32 MAX_CHANNEL_DIFFERENCE = 100; static constexpr int32 MAX_BOT_CHANNEL_DIFFERENCE = 100000; // server side limit static constexpr int32 MAX_RECENT_DIALOGS = 50; // some reasonable value - static constexpr size_t MAX_TITLE_LENGTH = 128; // server side limit for chat title - static constexpr size_t MAX_DESCRIPTION_LENGTH = 255; // server side limit for chat description static constexpr size_t MIN_DELETED_ASYNCHRONOUSLY_MESSAGES = 2; static constexpr size_t MAX_UNLOADED_MESSAGES = 5000; @@ -3189,8 +3177,11 @@ class MessagesManager final : public Actor { bool created_public_broadcasts_inited_ = false; vector created_public_broadcasts_; - FlatHashMap created_dialogs_; // random_id -> dialog_id - FlatHashMap, DialogIdHash> pending_created_dialogs_; // dialog_id -> promise + struct PendingCreatedDialog { + Promise> promise_; + vector group_invite_privacy_forbidden_user_ids_; + }; + FlatHashMap pending_created_dialogs_; bool running_get_difference_ = false; // true after before_get_difference and false after after_get_difference diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 82f8508f5..a267a39e0 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -1651,74 +1651,6 @@ class CreateChatRequest final : public RequestActor<> { } }; -class CreateNewGroupChatRequest final : public RequestActor<> { - vector user_ids_; - string title_; - MessageTtl message_ttl_; - int64 random_id_; - - DialogId dialog_id_; - - void do_run(Promise &&promise) final { - dialog_id_ = - td_->messages_manager_->create_new_group_chat(user_ids_, title_, message_ttl_, random_id_, std::move(promise)); - } - - void do_send_result() final { - CHECK(dialog_id_.is_valid()); - send_result(td_->messages_manager_->get_chat_object(dialog_id_)); - } - - public: - CreateNewGroupChatRequest(ActorShared td, uint64 request_id, vector user_ids, string title, - int32 message_ttl) - : RequestActor(std::move(td), request_id) - , user_ids_(std::move(user_ids)) - , title_(std::move(title)) - , message_ttl_(message_ttl) - , random_id_(0) { - } -}; - -class CreateNewSupergroupChatRequest final : public RequestActor<> { - string title_; - bool is_forum_; - bool is_megagroup_; - string description_; - DialogLocation location_; - bool for_import_; - MessageTtl message_ttl_; - int64 random_id_; - - DialogId dialog_id_; - - void do_run(Promise &&promise) final { - dialog_id_ = - td_->messages_manager_->create_new_channel_chat(title_, is_forum_, is_megagroup_, description_, location_, - for_import_, message_ttl_, random_id_, std::move(promise)); - } - - void do_send_result() final { - CHECK(dialog_id_.is_valid()); - send_result(td_->messages_manager_->get_chat_object(dialog_id_)); - } - - public: - CreateNewSupergroupChatRequest(ActorShared td, uint64 request_id, string title, bool is_forum, bool is_megagroup, - string description, td_api::object_ptr &&location, - bool for_import, int32 message_ttl) - : RequestActor(std::move(td), request_id) - , title_(std::move(title)) - , is_forum_(is_forum) - , is_megagroup_(is_megagroup) - , description_(std::move(description)) - , location_(std::move(location)) - , for_import_(for_import) - , message_ttl_(message_ttl) - , random_id_(0) { - } -}; - class CheckChatInviteLinkRequest final : public RequestActor<> { string invite_link_; @@ -5996,17 +5928,20 @@ void Td::on_request(uint64 id, const td_api::createSecretChat &request) { void Td::on_request(uint64 id, td_api::createNewBasicGroupChat &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.title_); - CREATE_REQUEST(CreateNewGroupChatRequest, UserId::get_user_ids(request.user_ids_), std::move(request.title_), - request.message_auto_delete_time_); + CREATE_REQUEST_PROMISE(); + contacts_manager_->create_new_chat(UserId::get_user_ids(request.user_ids_), std::move(request.title_), + MessageTtl(request.message_auto_delete_time_), std::move(promise)); } void Td::on_request(uint64 id, td_api::createNewSupergroupChat &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.title_); CLEAN_INPUT_STRING(request.description_); - CREATE_REQUEST(CreateNewSupergroupChatRequest, std::move(request.title_), request.is_forum_, !request.is_channel_, - std::move(request.description_), std::move(request.location_), request.for_import_, - request.message_auto_delete_time_); + CREATE_REQUEST_PROMISE(); + contacts_manager_->create_new_channel(std::move(request.title_), request.is_forum_, !request.is_channel_, + std::move(request.description_), DialogLocation(std::move(request.location_)), + request.for_import_, MessageTtl(request.message_auto_delete_time_), + std::move(promise)); } void Td::on_request(uint64 id, const td_api::createNewSecretChat &request) {