Allow to create location-based chats through createNewSupergroupChat.

GitOrigin-RevId: 9f954674052a2710425555e9b517f06319eb949e
This commit is contained in:
levlam 2019-10-14 17:51:12 +03:00
parent 41662e7048
commit 4e9ca731b2
6 changed files with 30 additions and 16 deletions

View File

@ -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 //@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<int32> title:string = Chat; createNewBasicGroupChat user_ids:vector<int32> 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 //@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 = Chat; 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 //@description Creates a new secret chat. Returns the newly created chat @user_id Identifier of the target user
createNewSecretChat user_id:int32 = Chat; createNewSecretChat user_id:int32 = Chat;

Binary file not shown.

View File

@ -591,17 +591,22 @@ class CreateChannelQuery : public Td::ResultHandler {
explicit CreateChannelQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) { explicit CreateChannelQuery(Promise<Unit> &&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; int32 flags = 0;
if (is_megagroup) { if (is_megagroup) {
flags |= telegram_api::channels_createChannel::MEGAGROUP_MASK; flags |= telegram_api::channels_createChannel::MEGAGROUP_MASK;
} else { } else {
flags |= telegram_api::channels_createChannel::BROADCAST_MASK; flags |= telegram_api::channels_createChannel::BROADCAST_MASK;
} }
if (!location.empty()) {
flags |= telegram_api::channels_createChannel::GEO_POINT_MASK;
}
random_id_ = random_id; random_id_ = random_id;
send_query(G()->net_query_creator().create(create_storer(telegram_api::channels_createChannel( send_query(G()->net_query_creator().create(
flags, false /*ignored*/, false /*ignored*/, title, about, nullptr, string())))); 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 { void on_result(uint64 id, BufferSlice packet) override {
@ -13946,9 +13951,10 @@ DialogId MessagesManager::create_new_group_chat(const vector<UserId> &user_ids,
} }
DialogId MessagesManager::create_new_channel_chat(const string &title, bool is_megagroup, const string &description, DialogId MessagesManager::create_new_channel_chat(const string &title, bool is_megagroup, const string &description,
int64 &random_id, Promise<Unit> &&promise) { const DialogLocation &location, int64 &random_id,
Promise<Unit> &&promise) {
LOG(INFO) << "Trying to create " << (is_megagroup ? "supergroup" : "broadcast") << " with title \"" << title LOG(INFO) << "Trying to create " << (is_megagroup ? "supergroup" : "broadcast") << " with title \"" << title
<< "\" and description \"" << description << "\""; << "\", description \"" << description << "\" and " << location;
if (random_id != 0) { if (random_id != 0) {
// request has already been sent before // 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 created_dialogs_[random_id]; // reserve place for result
td_->create_handler<CreateChannelQuery>(std::move(promise)) td_->create_handler<CreateChannelQuery>(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(); return DialogId();
} }

View File

@ -16,6 +16,7 @@
#include "td/telegram/DialogDate.h" #include "td/telegram/DialogDate.h"
#include "td/telegram/DialogDb.h" #include "td/telegram/DialogDb.h"
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
#include "td/telegram/DialogLocation.h"
#include "td/telegram/DialogParticipant.h" #include "td/telegram/DialogParticipant.h"
#include "td/telegram/files/FileId.h" #include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileSourceId.h" #include "td/telegram/files/FileSourceId.h"
@ -545,8 +546,8 @@ class MessagesManager : public Actor {
DialogId create_new_group_chat(const vector<UserId> &user_ids, const string &title, int64 &random_id, DialogId create_new_group_chat(const vector<UserId> &user_ids, const string &title, int64 &random_id,
Promise<Unit> &&promise); Promise<Unit> &&promise);
DialogId create_new_channel_chat(const string &title, bool is_megagroup, const string &description, int64 &random_id, DialogId create_new_channel_chat(const string &title, bool is_megagroup, const string &description,
Promise<Unit> &&promise); const DialogLocation &location, int64 &random_id, Promise<Unit> &&promise);
void create_new_secret_chat(UserId user_id, Promise<SecretChatId> &&promise); void create_new_secret_chat(UserId user_id, Promise<SecretChatId> &&promise);

View File

@ -24,6 +24,7 @@
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/DeviceTokenManager.h" #include "td/telegram/DeviceTokenManager.h"
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
#include "td/telegram/DialogLocation.h"
#include "td/telegram/DialogParticipant.h" #include "td/telegram/DialogParticipant.h"
#include "td/telegram/DocumentsManager.h" #include "td/telegram/DocumentsManager.h"
#include "td/telegram/FileReferenceManager.h" #include "td/telegram/FileReferenceManager.h"
@ -1833,13 +1834,14 @@ class CreateNewSupergroupChatRequest : public RequestActor<> {
string title_; string title_;
bool is_megagroup_; bool is_megagroup_;
string description_; string description_;
DialogLocation location_;
int64 random_id_; int64 random_id_;
DialogId dialog_id_; DialogId dialog_id_;
void do_run(Promise<Unit> &&promise) override { void do_run(Promise<Unit> &&promise) override {
dialog_id_ = td->messages_manager_->create_new_channel_chat(title_, is_megagroup_, description_, random_id_, dialog_id_ = td->messages_manager_->create_new_channel_chat(title_, is_megagroup_, description_, location_,
std::move(promise)); random_id_, std::move(promise));
} }
void do_send_result() override { void do_send_result() override {
@ -1849,11 +1851,12 @@ class CreateNewSupergroupChatRequest : public RequestActor<> {
public: public:
CreateNewSupergroupChatRequest(ActorShared<Td> td, uint64 request_id, string title, bool is_megagroup, CreateNewSupergroupChatRequest(ActorShared<Td> td, uint64 request_id, string title, bool is_megagroup,
string description) string description, td_api::object_ptr<td_api::chatLocation> &&location)
: RequestActor(std::move(td), request_id) : RequestActor(std::move(td), request_id)
, title_(std::move(title)) , title_(std::move(title))
, is_megagroup_(is_megagroup) , is_megagroup_(is_megagroup)
, description_(std::move(description)) , description_(std::move(description))
, location_(std::move(location))
, random_id_(0) { , 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.title_);
CLEAN_INPUT_STRING(request.description_); CLEAN_INPUT_STRING(request.description_);
CREATE_REQUEST(CreateNewSupergroupChatRequest, std::move(request.title_), !request.is_channel_, 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) { void Td::on_request(uint64 id, td_api::createNewSecretChat &request) {
CREATE_REQUEST(CreateNewSecretChatRequest, request.user_id_); CREATE_REQUEST(CreateNewSecretChatRequest, request.user_id_);

View File

@ -3262,9 +3262,13 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::createNewBasicGroupChat>(as_user_ids(user_ids_string, ','), title)); send_request(td_api::make_object<td_api::createNewBasicGroupChat>(as_user_ids(user_ids_string, ','), title));
} else if (op == "cnch") { } else if (op == "cnch") {
send_request(td_api::make_object<td_api::createNewSupergroupChat>(args, true, "Description")); send_request(td_api::make_object<td_api::createNewSupergroupChat>(args, true, "Description", nullptr));
} else if (op == "cnsg") { } else if (op == "cnsg") {
send_request(td_api::make_object<td_api::createNewSupergroupChat>(args, false, "Description")); send_request(td_api::make_object<td_api::createNewSupergroupChat>(args, false, "Description", nullptr));
} else if (op == "cngc") {
send_request(td_api::make_object<td_api::createNewSupergroupChat>(
args, false, "Description",
td_api::make_object<td_api::chatLocation>(td_api::make_object<td_api::location>(40.0, 60.0), "address")));
} else if (op == "UpgradeBasicGroupChatToSupergroupChat") { } else if (op == "UpgradeBasicGroupChatToSupergroupChat") {
send_request(td_api::make_object<td_api::upgradeBasicGroupChatToSupergroupChat>(as_chat_id(args))); send_request(td_api::make_object<td_api::upgradeBasicGroupChatToSupergroupChat>(as_chat_id(args)));
} else if (op == "DeleteSupergroup") { } else if (op == "DeleteSupergroup") {