From 4e9ca731b2f8098be87bc61c70fcff48ca09f066 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 14 Oct 2019 17:51:12 +0300 Subject: [PATCH] Allow to create location-based chats through createNewSupergroupChat. GitOrigin-RevId: 9f954674052a2710425555e9b517f06319eb949e --- td/generate/scheme/td_api.tl | 4 ++-- td/generate/scheme/td_api.tlo | Bin 161572 -> 161608 bytes td/telegram/MessagesManager.cpp | 18 ++++++++++++------ td/telegram/MessagesManager.h | 5 +++-- td/telegram/Td.cpp | 11 +++++++---- td/telegram/cli.cpp | 8 ++++++-- 6 files changed, 30 insertions(+), 16 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 2c478cadb..2ddb3c86c 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3392,8 +3392,8 @@ createSecretChat secret_chat_id:int32 = Chat; //@description Creates a new basic group and sends a corresponding messageBasicGroupChatCreate. Returns the newly created chat @user_ids Identifiers of users to be added to the basic group @title Title of the new basic group; 1-128 characters createNewBasicGroupChat user_ids:vector title:string = Chat; -//@description Creates a new supergroup or channel and sends a corresponding messageSupergroupChatCreate. Returns the newly created chat @title Title of the new chat; 1-128 characters @is_channel True, if a channel chat should be created @param_description Chat description; 0-255 characters -createNewSupergroupChat title:string is_channel:Bool description:string = Chat; +//@description Creates a new supergroup or channel and sends a corresponding messageSupergroupChatCreate. Returns the newly created chat @title Title of the new chat; 1-128 characters @is_channel True, if a channel chat should be created @param_description Chat description; 0-255 characters @location Chat location if a location-based supergroup is being created +createNewSupergroupChat title:string is_channel:Bool description:string location:chatLocation = Chat; //@description Creates a new secret chat. Returns the newly created chat @user_id Identifier of the target user createNewSecretChat user_id:int32 = Chat; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index ea7905752f3f8ad20d1952423958791a9aaeb380..99552a216261c616d8eed9adfeb555470ec0538c 100644 GIT binary patch delta 51 zcmV-30L=fS?g_~534pW#l;Q-fu6F;InBoB-0R)rrM<;wk=#zl67gqoP delta 41 zcmV+^0M`G=?g^ys34pW#l;Q;ZMVCyMnBoB-m-G|?D3{>k0YsCKGYGd(;{o`SsAdzI diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index e50a18f4a..c4942a666 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -591,17 +591,22 @@ class CreateChannelQuery : public Td::ResultHandler { explicit CreateChannelQuery(Promise &&promise) : promise_(std::move(promise)) { } - void send(const string &title, bool is_megagroup, const string &about, int64 random_id) { + void send(const string &title, bool is_megagroup, const string &about, const DialogLocation &location, + int64 random_id) { int32 flags = 0; 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; + } random_id_ = random_id; - send_query(G()->net_query_creator().create(create_storer(telegram_api::channels_createChannel( - flags, false /*ignored*/, false /*ignored*/, title, about, nullptr, string())))); + send_query(G()->net_query_creator().create( + create_storer(telegram_api::channels_createChannel(flags, false /*ignored*/, false /*ignored*/, title, about, + location.get_input_geo_point(), location.get_address())))); } void on_result(uint64 id, BufferSlice packet) override { @@ -13946,9 +13951,10 @@ DialogId MessagesManager::create_new_group_chat(const vector &user_ids, } DialogId MessagesManager::create_new_channel_chat(const string &title, bool is_megagroup, const string &description, - int64 &random_id, Promise &&promise) { + const DialogLocation &location, int64 &random_id, + Promise &&promise) { LOG(INFO) << "Trying to create " << (is_megagroup ? "supergroup" : "broadcast") << " with title \"" << title - << "\" and description \"" << description << "\""; + << "\", description \"" << description << "\" and " << location; if (random_id != 0) { // request has already been sent before @@ -13980,7 +13986,7 @@ DialogId MessagesManager::create_new_channel_chat(const string &title, bool is_m created_dialogs_[random_id]; // reserve place for result td_->create_handler(std::move(promise)) - ->send(new_title, is_megagroup, strip_empty_characters(description, MAX_DESCRIPTION_LENGTH), random_id); + ->send(new_title, is_megagroup, strip_empty_characters(description, MAX_DESCRIPTION_LENGTH), location, random_id); return DialogId(); } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 212047592..521080f36 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -16,6 +16,7 @@ #include "td/telegram/DialogDate.h" #include "td/telegram/DialogDb.h" #include "td/telegram/DialogId.h" +#include "td/telegram/DialogLocation.h" #include "td/telegram/DialogParticipant.h" #include "td/telegram/files/FileId.h" #include "td/telegram/files/FileSourceId.h" @@ -545,8 +546,8 @@ class MessagesManager : public Actor { DialogId create_new_group_chat(const vector &user_ids, const string &title, int64 &random_id, Promise &&promise); - DialogId create_new_channel_chat(const string &title, bool is_megagroup, const string &description, int64 &random_id, - Promise &&promise); + DialogId create_new_channel_chat(const string &title, bool is_megagroup, const string &description, + const DialogLocation &location, int64 &random_id, Promise &&promise); void create_new_secret_chat(UserId user_id, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 8bb77d3e0..6b85db1b4 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -24,6 +24,7 @@ #include "td/telegram/ContactsManager.h" #include "td/telegram/DeviceTokenManager.h" #include "td/telegram/DialogId.h" +#include "td/telegram/DialogLocation.h" #include "td/telegram/DialogParticipant.h" #include "td/telegram/DocumentsManager.h" #include "td/telegram/FileReferenceManager.h" @@ -1833,13 +1834,14 @@ class CreateNewSupergroupChatRequest : public RequestActor<> { string title_; bool is_megagroup_; string description_; + DialogLocation location_; int64 random_id_; DialogId dialog_id_; void do_run(Promise &&promise) override { - dialog_id_ = td->messages_manager_->create_new_channel_chat(title_, is_megagroup_, description_, random_id_, - std::move(promise)); + dialog_id_ = td->messages_manager_->create_new_channel_chat(title_, is_megagroup_, description_, location_, + random_id_, std::move(promise)); } void do_send_result() override { @@ -1849,11 +1851,12 @@ class CreateNewSupergroupChatRequest : public RequestActor<> { public: CreateNewSupergroupChatRequest(ActorShared td, uint64 request_id, string title, bool is_megagroup, - string description) + string description, td_api::object_ptr &&location) : RequestActor(std::move(td), request_id) , title_(std::move(title)) , is_megagroup_(is_megagroup) , description_(std::move(description)) + , location_(std::move(location)) , random_id_(0) { } }; @@ -5911,7 +5914,7 @@ void Td::on_request(uint64 id, td_api::createNewSupergroupChat &request) { CLEAN_INPUT_STRING(request.title_); CLEAN_INPUT_STRING(request.description_); CREATE_REQUEST(CreateNewSupergroupChatRequest, std::move(request.title_), !request.is_channel_, - std::move(request.description_)); + std::move(request.description_), std::move(request.location_)); } void Td::on_request(uint64 id, td_api::createNewSecretChat &request) { CREATE_REQUEST(CreateNewSecretChatRequest, request.user_id_); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 6f15d52c5..e11414ed9 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3262,9 +3262,13 @@ class CliClient final : public Actor { send_request(td_api::make_object(as_user_ids(user_ids_string, ','), title)); } else if (op == "cnch") { - send_request(td_api::make_object(args, true, "Description")); + send_request(td_api::make_object(args, true, "Description", nullptr)); } else if (op == "cnsg") { - send_request(td_api::make_object(args, false, "Description")); + send_request(td_api::make_object(args, false, "Description", nullptr)); + } else if (op == "cngc") { + send_request(td_api::make_object( + args, false, "Description", + td_api::make_object(td_api::make_object(40.0, 60.0), "address"))); } else if (op == "UpgradeBasicGroupChatToSupergroupChat") { send_request(td_api::make_object(as_chat_id(args))); } else if (op == "DeleteSupergroup") {