From 16b33f67c7505a96bd259eea90ac0348a93fbbbc Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 16 Aug 2018 20:09:23 +0300 Subject: [PATCH] Add shorthand requests getContacts, joinChat and leaveChat. GitOrigin-RevId: 95ce6e52aaefafd8bb1c7a70fd096b2156d1a164 --- td/generate/scheme/td_api.tl | 9 +++++++++ td/generate/scheme/td_api.tlo | Bin 133196 -> 133416 bytes td/telegram/Td.cpp | 19 +++++++++++++++++++ td/telegram/Td.h | 6 ++++++ td/telegram/cli.cpp | 17 ++++++++++------- 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index cedc7f3c..caea9b68 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2766,6 +2766,12 @@ toggleChatDefaultDisableNotification chat_id:int53 default_disable_notification: //@description Changes client data associated with a chat @chat_id Chat identifier @client_data New value of client_data setChatClientData chat_id:int53 client_data:string = Ok; +//@description Adds current user as a new member to a chat. Private and secret chats can't be joined using this method @chat_id Chat identifier +joinChat chat_id:int53 = Ok; + +//@description Removes current user from chat members. Private and secret chats can't be left using this method @chat_id Chat identifier +leaveChat chat_id:int53 = Ok; + //@description Adds a new member to a chat. Members can't be added to private or secret chats. Members will not be added until the chat state has been synchronized with the server //@chat_id Chat identifier @user_id Identifier of the user @forward_limit The number of earlier messages from the chat to be forwarded to the new member; up to 300. Ignored for supergroups and channels addChatMember chat_id:int53 user_id:int32 forward_limit:int32 = Ok; @@ -2877,6 +2883,9 @@ getBlockedUsers offset:int32 limit:int32 = Users; //@description Adds new contacts or edits existing contacts; contacts' user identifiers are ignored @contacts The list of contacts to import or edit, contact's vCard are ignored and are not imported importContacts contacts:vector = ImportedContacts; +//@description Returns all user contacts +getContacts = Users; + //@description Searches for the specified query in the first names, last names and usernames of the known user contacts @query Query to search for; can be empty to return all contacts @limit Maximum number of users to be returned searchContacts query:string limit:int32 = Users; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 36278f27619a36498fe019a45c9130c8f74896f1..1339cf0d5375046c8403fb42efa33efe597f3077 100644 GIT binary patch delta 83 zcmV-Z0IdJakO-)f2!ON!;B)~ix8ZaFA2$wgM1QLbXJvFlZ*Fv9W0y|40Vbxb0U8OR p8hR55YHw+7mkoLWOP0m~WC>wset_dialog_client_data(DialogId(request.chat_id_), std::move(request.client_data_))); } +void Td::on_request(uint64 id, const td_api::joinChat &request) { + CREATE_OK_REQUEST_PROMISE(); + messages_manager_->set_dialog_participant_status(DialogId(request.chat_id_), contacts_manager_->get_my_id("joinChat"), + td_api::make_object(), + std::move(promise)); +} + +void Td::on_request(uint64 id, const td_api::leaveChat &request) { + CREATE_OK_REQUEST_PROMISE(); + messages_manager_->set_dialog_participant_status( + DialogId(request.chat_id_), contacts_manager_->get_my_id("leaveChat"), + td_api::make_object(), std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::addChatMember &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); @@ -5624,6 +5638,11 @@ void Td::on_request(uint64 id, td_api::importContacts &request) { CREATE_REQUEST(ImportContactsRequest, std::move(request.contacts_)); } +void Td::on_request(uint64 id, const td_api::getContacts &request) { + CHECK_IS_USER(); + CREATE_REQUEST(SearchContactsRequest, string(), 1000000); +} + void Td::on_request(uint64 id, td_api::searchContacts &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.query_); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 0913766a..de4c699b 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -589,6 +589,10 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, td_api::setChatClientData &request); + void on_request(uint64 id, const td_api::joinChat &request); + + void on_request(uint64 id, const td_api::leaveChat &request); + void on_request(uint64 id, const td_api::addChatMember &request); void on_request(uint64 id, const td_api::addChatMembers &request); @@ -633,6 +637,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, td_api::importContacts &request); + void on_request(uint64 id, const td_api::getContacts &request); + void on_request(uint64 id, td_api::searchContacts &request); void on_request(uint64 id, td_api::removeContacts &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index decf4154..70dde59f 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -118,8 +118,7 @@ static void reactivate_readline() { } static char *command_generator(const char *text, int state) { - static const vector commands{"GetContacts", - "GetChats", + static const vector commands{"GetChats", "GetHistory", "SetVerbosity", "SendVideo", @@ -1454,12 +1453,12 @@ class CliClient final : public Actor { send_request(make_tl_object(args)); } else if (op == "rcpc" || op == "ResendChangePhoneCode") { send_request(make_tl_object()); - } else if (op == "GetContacts") { - auto limit = to_integer(args); - if (limit == 0) { - limit = 10000; + } else if (op == "gco") { + if (args.empty()) { + send_request(make_tl_object()); + } else { + send_request(make_tl_object("", to_integer(args))); } - send_request(make_tl_object("", limit)); } else if (op == "ImportContacts" || op == "cic") { vector contacts_str = full_split(args, ';'); vector> contacts; @@ -3049,6 +3048,10 @@ class CliClient final : public Actor { std::tie(chat_id, limit) = split(args); send_request(make_tl_object(as_chat_id(chat_id), "", 0, to_integer(limit), nullptr, vector())); + } else if (op == "join") { + send_request(make_tl_object(as_chat_id(args))); + } else if (op == "leave") { + send_request(make_tl_object(as_chat_id(args))); } else if (op == "dcm") { string chat_id; string user_id_str;