Add td_api::loadGroupCallParticipants.

This commit is contained in:
levlam 2020-12-11 19:39:27 +03:00
parent 76950e710f
commit 4a0c42729b
7 changed files with 87 additions and 5 deletions

View File

@ -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;

Binary file not shown.

View File

@ -118,7 +118,41 @@ class GetGroupCallParticipantQuery : public Td::ResultHandler {
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(), 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<Unit> promise_;
InputGroupCallId input_group_call_id_;
string offset_;
public:
explicit GetGroupCallParticipantsQuery(Promise<Unit> &&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<int32>(), vector<int32>(), offset_, limit)));
}
void on_result(uint64 id, BufferSlice packet) override {
auto result_ptr = fetch_result<telegram_api::phone_getGroupParticipants>(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<telegram_api::phone_groupParticipants> &&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<CheckGroupCallQuery>(std::move(query_promise))->send(input_group_call_id, source);
}
void GroupCallManager::load_group_call_participants(GroupCallId group_call_id, int32 limit, Promise<Unit> &&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<GetGroupCallParticipantsQuery>(std::move(promise))
->send(input_group_call_id, std::move(next_offset), limit);
}
void GroupCallManager::leave_group_call(GroupCallId group_call_id, Promise<Unit> &&promise) {
TRY_RESULT_PROMISE(promise, input_group_call_id, get_input_group_call_id(group_call_id));

View File

@ -57,6 +57,8 @@ class GroupCallManager : public Actor {
void check_group_call_is_joined(GroupCallId group_call_id, Promise<Unit> &&promise);
void load_group_call_participants(GroupCallId group_call_id, int32 limit, Promise<Unit> &&promise);
void leave_group_call(GroupCallId group_call_id, Promise<Unit> &&promise);
void discard_group_call(GroupCallId group_call_id, Promise<Unit> &&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<telegram_api::phone_groupParticipants> &&participants,
bool is_load);
tl_object_ptr<telegram_api::phone_groupParticipants> &&participants, bool is_load,
const string &offset);
void on_update_group_call_participants(InputGroupCallId input_group_call_id,
vector<tl_object_ptr<telegram_api::groupCallParticipant>> &&participants,

View File

@ -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();

View File

@ -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);

View File

@ -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<td_api::checkGroupCallIsJoined>(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<td_api::loadGroupCallParticipants>(as_group_call_id(group_call_id),
to_integer<int32>(limit)));
} else if (op == "lgc") {
send_request(td_api::make_object<td_api::leaveGroupCall>(as_group_call_id(args)));
} else if (op == "dgc") {