From 2241058f852ddd593800bc22839cbc481c033ea3 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 6 Apr 2021 02:54:55 +0300 Subject: [PATCH] Allow to create scheduled voice chats. --- td/generate/scheme/td_api.tl | 6 ++++-- td/telegram/GroupCallManager.cpp | 12 ++++++++---- td/telegram/GroupCallManager.h | 2 +- td/telegram/Td.cpp | 2 +- td/telegram/cli.cpp | 5 +++-- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 1afa2fab0..3bd6f83ad 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4601,8 +4601,10 @@ sendCallDebugInformation call_id:int32 debug_information:string = Ok; getAvailableVoiceChatAliases chat_id:int53 = MessageSenders; //@description Creates a voice chat (a group call bound to a chat). Available only for basic groups, supergroups and channels; requires can_manage_voice_chats rights -//@chat_id Chat identifier @title Group call title; if empty, chat title will be used -createVoiceChat chat_id:int53 title:string = GroupCallId; +//@chat_id Chat identifier, in which the voice chat will be created +//@title Group call title; if empty, chat title will be used +//@start_date Point in time (Unix timestamp) when the group call will be started. Pass 0 to start the voice chat immediately +createVoiceChat chat_id:int53 title:string start_date:int32 = GroupCallId; //@description Returns information about a group call @group_call_id Group call identifier getGroupCall group_call_id:int32 = GroupCall; diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index 482ee3307..3d9d0f40a 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -131,7 +131,7 @@ class CreateGroupCallQuery : public Td::ResultHandler { explicit CreateGroupCallQuery(Promise &&promise) : promise_(std::move(promise)) { } - void send(DialogId dialog_id, const string &title) { + void send(DialogId dialog_id, const string &title, int32 start_date) { dialog_id_ = dialog_id; auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read); @@ -141,8 +141,11 @@ class CreateGroupCallQuery : public Td::ResultHandler { if (!title.empty()) { flags |= telegram_api::phone_createGroupCall::TITLE_MASK; } + if (start_date > 0) { + flags |= telegram_api::phone_createGroupCall::SCHEDULE_DATE_MASK; + } send_query(G()->net_query_creator().create( - telegram_api::phone_createGroupCall(flags, std::move(input_peer), Random::secure_int32(), title, 0))); + telegram_api::phone_createGroupCall(flags, std::move(input_peer), Random::secure_int32(), title, start_date))); } void on_result(uint64 id, BufferSlice packet) override { @@ -1039,7 +1042,8 @@ void GroupCallManager::get_group_call_join_as(DialogId dialog_id, td_->create_handler(std::move(promise))->send(dialog_id); } -void GroupCallManager::create_voice_chat(DialogId dialog_id, string title, Promise &&promise) { +void GroupCallManager::create_voice_chat(DialogId dialog_id, string title, int32 start_date, + Promise &&promise) { if (!dialog_id.is_valid()) { return promise.set_error(Status::Error(400, "Invalid chat identifier specified")); } @@ -1063,7 +1067,7 @@ void GroupCallManager::create_voice_chat(DialogId dialog_id, string title, Promi std::move(promise)); } }); - td_->create_handler(std::move(query_promise))->send(dialog_id, title); + td_->create_handler(std::move(query_promise))->send(dialog_id, title, start_date); } void GroupCallManager::on_voice_chat_created(DialogId dialog_id, InputGroupCallId input_group_call_id, diff --git a/td/telegram/GroupCallManager.h b/td/telegram/GroupCallManager.h index 13e27ff52..d4a751879 100644 --- a/td/telegram/GroupCallManager.h +++ b/td/telegram/GroupCallManager.h @@ -48,7 +48,7 @@ class GroupCallManager : public Actor { void get_group_call_join_as(DialogId dialog_id, Promise> &&promise); - void create_voice_chat(DialogId dialog_id, string title, Promise &&promise); + void create_voice_chat(DialogId dialog_id, string title, int32 start_date, Promise &&promise); void get_group_call(GroupCallId group_call_id, Promise> &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index cfceee249..0d8f846d1 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5985,7 +5985,7 @@ void Td::on_request(uint64 id, td_api::createVoiceChat &request) { promise.set_value(td_api::make_object(result.ok().get())); } }); - group_call_manager_->create_voice_chat(DialogId(request.chat_id_), std::move(request.title_), + group_call_manager_->create_voice_chat(DialogId(request.chat_id_), std::move(request.title_), request.start_date_, std::move(query_promise)); } diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index adcfb922c..5837c964d 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2675,8 +2675,9 @@ class CliClient final : public Actor { } else if (op == "cvc") { string chat_id; string title; - get_args(args, chat_id, title); - send_request(td_api::make_object(as_chat_id(chat_id), title)); + int32 start_date; + get_args(args, chat_id, title, start_date); + send_request(td_api::make_object(as_chat_id(chat_id), title, start_date)); } else if (op == "ggc") { send_request(td_api::make_object(as_group_call_id(args))); } else if (op == "ggcss") {