From 4a0c42729b406773c0deebe8ab7229567354aef5 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 11 Dec 2020 19:39:27 +0300 Subject: [PATCH] Add td_api::loadGroupCallParticipants. --- td/generate/scheme/td_api.tl | 3 ++ td/generate/scheme/td_api.tlo | Bin 190784 -> 190924 bytes td/telegram/GroupCallManager.cpp | 68 +++++++++++++++++++++++++++++-- td/telegram/GroupCallManager.h | 6 ++- td/telegram/Td.cpp | 7 ++++ td/telegram/Td.h | 2 + td/telegram/cli.cpp | 6 +++ 7 files changed, 87 insertions(+), 5 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index f443c93d4..b5172937b 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4378,6 +4378,9 @@ toggleGroupCallParticipantIsMuted group_call_id:int32 user_id:int32 is_muted:Boo //@description Checks whether a group call is still joined. Should be called every 10 seconds when tgcalls notifies about lost connection with the server @group_call_id Group call identifier checkGroupCallIsJoined group_call_id:int32 = Ok; +//@description Loads more group call participants. The loaded participants will be received through updates @group_call_id Group call identifier @limit Maximum number of participants to load +loadGroupCallParticipants group_call_id:int32 limit:int32 = Ok; + //@description Leaves a group call @group_call_id Group call identifier leaveGroupCall group_call_id:int32 = Ok; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 536e4baff1a44e368d44a449bbb0754b5818464d..2f92af113ea53d09cbc9d783dfaa3fec548ee9ab 100644 GIT binary patch delta 78 zcmV-U0I~nT(hJPf3xI?Hv;qhr0g<-}Ap)atB+kC`HyLbiVPr>gZ*_1(VQg$rVRCe7 kV`*?group_call_manager_->on_get_group_call_participants(input_group_call_id_, result_ptr.move_as_ok(), false); + td->group_call_manager_->on_get_group_call_participants(input_group_call_id_, result_ptr.move_as_ok(), false, + string()); + + promise_.set_value(Unit()); + } + + void on_error(uint64 id, Status status) override { + promise_.set_error(std::move(status)); + } +}; + +class GetGroupCallParticipantsQuery : public Td::ResultHandler { + Promise promise_; + InputGroupCallId input_group_call_id_; + string offset_; + + public: + explicit GetGroupCallParticipantsQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(InputGroupCallId input_group_call_id, string offset, int32 limit) { + input_group_call_id_ = input_group_call_id; + offset_ = std::move(offset); + send_query(G()->net_query_creator().create(telegram_api::phone_getGroupParticipants( + input_group_call_id.get_input_group_call(), vector(), vector(), offset_, limit))); + } + + void on_result(uint64 id, BufferSlice packet) override { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(id, result_ptr.move_as_error()); + } + + td->group_call_manager_->on_get_group_call_participants(input_group_call_id_, result_ptr.move_as_ok(), true, + offset_); promise_.set_value(Unit()); } @@ -604,7 +638,7 @@ bool GroupCallManager::need_group_call_participants(InputGroupCallId input_group void GroupCallManager::on_get_group_call_participants( InputGroupCallId input_group_call_id, tl_object_ptr &&participants, - bool is_load) { + bool is_load, const string &offset) { LOG(INFO) << "Receive group call participants: " << to_string(participants); CHECK(participants != nullptr); @@ -615,7 +649,12 @@ void GroupCallManager::on_get_group_call_participants( on_receive_group_call_version(input_group_call_id, participants->version_); if (is_load) { - // TODO use count, next_offset + // TODO use count + auto participants_it = group_call_participants_.find(input_group_call_id); + if (participants_it != group_call_participants_.end() && participants_it->second->next_offset == offset) { + CHECK(participants_it->second != nullptr); + participants_it->second->next_offset = std::move(participants->next_offset_); + } } } @@ -1045,6 +1084,29 @@ void GroupCallManager::check_group_call_is_joined(GroupCallId group_call_id, Pro td_->create_handler(std::move(query_promise))->send(input_group_call_id, source); } +void GroupCallManager::load_group_call_participants(GroupCallId group_call_id, int32 limit, Promise &&promise) { + if (limit <= 0) { + return promise.set_error(Status::Error(400, "Parameter limit must be positive")); + } + + TRY_RESULT_PROMISE(promise, input_group_call_id, get_input_group_call_id(group_call_id)); + + if (!need_group_call_participants(input_group_call_id)) { + return promise.set_error(Status::Error(400, "Can't load group call participants")); + } + auto *group_call = get_group_call(input_group_call_id); + CHECK(group_call != nullptr && group_call->is_inited); + + string next_offset; + auto participants_it = group_call_participants_.find(input_group_call_id); + if (participants_it != group_call_participants_.end()) { + CHECK(participants_it->second != nullptr); + next_offset = participants_it->second->next_offset; + } + td_->create_handler(std::move(promise)) + ->send(input_group_call_id, std::move(next_offset), limit); +} + void GroupCallManager::leave_group_call(GroupCallId group_call_id, Promise &&promise) { TRY_RESULT_PROMISE(promise, input_group_call_id, get_input_group_call_id(group_call_id)); diff --git a/td/telegram/GroupCallManager.h b/td/telegram/GroupCallManager.h index e3d4f22fe..d4548ec8e 100644 --- a/td/telegram/GroupCallManager.h +++ b/td/telegram/GroupCallManager.h @@ -57,6 +57,8 @@ class GroupCallManager : public Actor { void check_group_call_is_joined(GroupCallId group_call_id, Promise &&promise); + void load_group_call_participants(GroupCallId group_call_id, int32 limit, Promise &&promise); + void leave_group_call(GroupCallId group_call_id, Promise &&promise); void discard_group_call(GroupCallId group_call_id, Promise &&promise); @@ -66,8 +68,8 @@ class GroupCallManager : public Actor { void on_user_speaking_in_group_call(GroupCallId group_call_id, UserId user_id, int32 date, bool recursive = false); void on_get_group_call_participants(InputGroupCallId input_group_call_id, - tl_object_ptr &&participants, - bool is_load); + tl_object_ptr &&participants, bool is_load, + const string &offset); void on_update_group_call_participants(InputGroupCallId input_group_call_id, vector> &&participants, diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 7b71448c2..b2bc6baba 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6091,6 +6091,13 @@ void Td::on_request(uint64 id, const td_api::checkGroupCallIsJoined &request) { group_call_manager_->check_group_call_is_joined(GroupCallId(request.group_call_id_), std::move(promise)); } +void Td::on_request(uint64 id, const td_api::loadGroupCallParticipants &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + group_call_manager_->load_group_call_participants(GroupCallId(request.group_call_id_), request.limit_, + std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::leaveGroupCall &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 415168ebc..da095a865 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -708,6 +708,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, const td_api::checkGroupCallIsJoined &request); + void on_request(uint64 id, const td_api::loadGroupCallParticipants &request); + void on_request(uint64 id, const td_api::leaveGroupCall &request); void on_request(uint64 id, const td_api::discardGroupCall &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index d69780458..0a0cc0f33 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2875,6 +2875,12 @@ class CliClient final : public Actor { as_group_call_id(group_call_id), as_user_id(user_id), as_bool(is_muted))); } else if (op == "cgcij") { send_request(td_api::make_object(as_group_call_id(args))); + } else if (op == "lgcp") { + string group_call_id; + string limit; + std::tie(group_call_id, limit) = split(args); + send_request(td_api::make_object(as_group_call_id(group_call_id), + to_integer(limit))); } else if (op == "lgc") { send_request(td_api::make_object(as_group_call_id(args))); } else if (op == "dgc") {