Add getGroupCallMediaChannelDescriptions method.

This commit is contained in:
levlam 2021-05-03 21:44:21 +03:00
parent 529213030c
commit 138bf15dec
6 changed files with 130 additions and 17 deletions

View File

@ -2170,14 +2170,14 @@ groupCallRecentSpeaker participant_id:MessageSender is_speaking:Bool = GroupCall
//@duration Call duration; for ended calls only
groupCall id:int32 title:string scheduled_start_date:int32 enabled_start_notification:Bool is_active:Bool is_joined:Bool need_rejoin:Bool can_be_managed:Bool participant_count:int32 loaded_all_participants:Bool recent_speakers:vector<groupCallRecentSpeaker> is_my_video_enabled:Bool can_start_video:Bool mute_new_participants:Bool can_change_mute_new_participants:Bool record_duration:int32 duration:int32 = GroupCall;
//@description Contains informatioan about a group call participant's video @sources List of video synchronization sources @endpoint_id Video endpoint identifier
groupCallParticipantVideoInfo sources:vector<int32> endpoint_id:string = GroupCallParticipantVideoInfo;
//@description Contains information about a group call participant's video channel @source_ids List of video channel synchronization source identifiers @endpoint_id Video endpoint identifier
groupCallParticipantVideoInfo source_ids:vector<int32> endpoint_id:string = GroupCallParticipantVideoInfo;
//@description Represents a group call participant
//@participant_id Identifier of the group call participant
//@audio_source User's audio synchronization source
//@video_info Information about user's video; may be null if there is no active video
//@screen_sharing_video_info Information about user's screen sharing video; may be null if there is no active screen sharing video
//@audio_source_id User's audio channel synchronization source identifier
//@video_info Information about user's video channel; may be null if there is no active video
//@screen_sharing_video_info Information about user's screen sharing video channel; may be null if there is no active screen sharing video
//@bio The participant user's bio or the participant chat's description
//@is_current_user True, if the participant is the current user
//@is_speaking True, if the participant is speaking as set by setGroupCallParticipantIsSpeaking
@ -2191,7 +2191,13 @@ groupCallParticipantVideoInfo sources:vector<int32> endpoint_id:string = GroupCa
//@can_unmute_self True, if the participant is muted for all users, but can unmute themself
//@volume_level Participant's volume level; 1-20000 in hundreds of percents
//@order User's order in the group call participant list. Orders must be compared lexicographically. The bigger is order, the higher is user in the list. If order is empty, the user must be removed from the participant list
groupCallParticipant participant_id:MessageSender audio_source:int32 video_info:groupCallParticipantVideoInfo screen_sharing_video_info:groupCallParticipantVideoInfo bio:string is_current_user:Bool is_speaking:Bool is_hand_raised:Bool can_be_muted_for_all_users:Bool can_be_unmuted_for_all_users:Bool can_be_muted_for_current_user:Bool can_be_unmuted_for_current_user:Bool is_muted_for_all_users:Bool is_muted_for_current_user:Bool can_unmute_self:Bool volume_level:int32 order:string = GroupCallParticipant;
groupCallParticipant participant_id:MessageSender audio_source_id:int32 video_info:groupCallParticipantVideoInfo screen_sharing_video_info:groupCallParticipantVideoInfo bio:string is_current_user:Bool is_speaking:Bool is_hand_raised:Bool can_be_muted_for_all_users:Bool can_be_unmuted_for_all_users:Bool can_be_muted_for_current_user:Bool can_be_unmuted_for_current_user:Bool is_muted_for_all_users:Bool is_muted_for_current_user:Bool can_unmute_self:Bool volume_level:int32 order:string = GroupCallParticipant;
//@description Describes a media channel in a group call @source_id Channel's synchronization source identifier @is_video True if the channel is a video channel @param_description Description of the channel
groupCallMediaChannelDescription source_id:int32 is_video:Bool description:string = GroupCallMediaChannelDescription;
//@description Represents a list of group call media channel description @descriptions List of descriptions
groupCallMediaChannelDescriptions descriptions:vector<groupCallMediaChannelDescription> = GroupCallMediaChannelDescriptions;
//@class CallProblem @description Describes the exact type of a problem with a call
@ -4618,12 +4624,12 @@ toggleGroupCallEnabledStartNotification group_call_id:int32 enabled_start_notifi
//@description Joins an active group call. Returns join response payload for tgcalls
//@group_call_id Group call identifier
//@participant_id Identifier of a group call participant, which will be used to join the call; voice chats only
//@audio_source Caller audio synchronization source identifier; received from tgcalls
//@audio_source_id Caller audio channel synchronization source identifier; received from tgcalls
//@payload Group call join payload; received from tgcalls
//@is_muted True, if the user's microphone is muted
//@is_my_video_enabled True, if the user's video is enabled
//@invite_hash If non-empty, invite hash to be used to join the group call without being muted by administrators
joinGroupCall group_call_id:int32 participant_id:MessageSender audio_source:int32 payload:string is_muted:Bool is_my_video_enabled:Bool invite_hash:string = Text;
joinGroupCall group_call_id:int32 participant_id:MessageSender audio_source_id:int32 payload:string is_muted:Bool is_my_video_enabled:Bool invite_hash:string = Text;
//@description Starts screen sharing in a joined group call. Returns join response payload for tgcalls @group_call_id Group call identifier @payload Group call join payload; received from tgcalls
startGroupCallScreenSharing group_call_id:int32 payload:string = Text;
@ -4659,6 +4665,9 @@ endGroupCallRecording group_call_id:int32 = Ok;
//@description Toggles whether current user's video is enabled @group_call_id Group call identifier @is_my_video_enabled Pass true if the current user's video is enabled
toggleGroupCallIsMyVideoEnabled group_call_id:int32 is_my_video_enabled:Bool = Ok;
//@description Returns information about group call media channels by their synchronization source identifiers @group_call_id Group call identifier @source_ids Synchronization source identifiers
getGroupCallMediaChannelDescriptions group_call_id:int32 source_ids:vector<int32> = GroupCallMediaChannelDescriptions;
//@description Informs TDLib that speaking state of a participant of an active group has changed @group_call_id Group call identifier
//@audio_source Group call participant's synchronization audio source identifier, or 0 for the current user @is_speaking True, if the user is speaking
setGroupCallParticipantIsSpeaking group_call_id:int32 audio_source:int32 is_speaking:Bool = Ok;

View File

@ -257,12 +257,11 @@ class GetGroupCallParticipantQuery : public Td::ResultHandler {
}
void send(InputGroupCallId input_group_call_id, vector<tl_object_ptr<telegram_api::InputPeer>> &&input_peers,
vector<int32> &&audio_sources) {
vector<int32> &&source_ids) {
input_group_call_id_ = input_group_call_id;
auto limit = narrow_cast<int32>(max(input_peers.size(), audio_sources.size()));
send_query(G()->net_query_creator().create(
telegram_api::phone_getGroupParticipants(input_group_call_id.get_input_group_call(), std::move(input_peers),
std::move(audio_sources), string(), limit)));
auto limit = narrow_cast<int32>(max(input_peers.size(), source_ids.size()));
send_query(G()->net_query_creator().create(telegram_api::phone_getGroupParticipants(
input_group_call_id.get_input_group_call(), std::move(input_peers), std::move(source_ids), string(), limit)));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -3257,6 +3256,92 @@ void GroupCallManager::on_toggle_group_call_recording(InputGroupCallId input_gro
}
}
void GroupCallManager::get_group_call_media_channel_descriptions(
GroupCallId group_call_id, vector<int32> source_ids,
Promise<td_api::object_ptr<td_api::groupCallMediaChannelDescriptions>> &&promise, bool is_recursive) {
if (G()->close_flag()) {
return promise.set_error(Status::Error(500, "Request aborted"));
}
TRY_RESULT_PROMISE(promise, input_group_call_id, get_input_group_call_id(group_call_id));
auto *group_call = get_group_call(input_group_call_id);
if (group_call == nullptr || !group_call->is_inited || !group_call->is_active) {
return promise.set_error(Status::Error(400, "GROUPCALL_JOIN_MISSING"));
}
if (!group_call->is_joined) {
if (is_group_call_being_joined(input_group_call_id) || group_call->need_rejoin) {
group_call->after_join.push_back(
PromiseCreator::lambda([actor_id = actor_id(this), group_call_id, source_ids = std::move(source_ids),
promise = std::move(promise), is_recursive](Result<Unit> &&result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
send_closure(actor_id, &GroupCallManager::get_group_call_media_channel_descriptions, group_call_id,
std::move(source_ids), std::move(promise), is_recursive);
}
}));
return;
}
return promise.set_error(Status::Error(400, "GROUPCALL_JOIN_MISSING"));
}
vector<td_api::object_ptr<td_api::groupCallMediaChannelDescription>> result;
std::unordered_set<int32> source_ids_set(source_ids.begin(), source_ids.end());
auto participants = add_group_call_participants(input_group_call_id);
for (auto &participant : participants->participants) {
if (source_ids_set.empty()) {
break;
}
if (source_ids_set.count(participant.audio_source)) {
source_ids_set.erase(participant.audio_source);
result.push_back(
td_api::make_object<td_api::groupCallMediaChannelDescription>(participant.audio_source, false, string()));
}
for (auto &source_id : participant.video_payload.sources) {
if (source_ids_set.count(source_id)) {
source_ids_set.erase(source_id);
result.push_back(td_api::make_object<td_api::groupCallMediaChannelDescription>(
source_id, true, participant.video_payload.json_payload));
}
}
for (auto &source_id : participant.presentation_payload.sources) {
if (source_ids_set.count(source_id)) {
source_ids_set.erase(source_id);
result.push_back(td_api::make_object<td_api::groupCallMediaChannelDescription>(
source_id, true, participant.presentation_payload.json_payload));
}
}
}
if (!source_ids_set.empty()) {
vector<int32> missing_source_ids(source_ids_set.begin(), source_ids_set.end());
if (!is_recursive) {
auto query_promise =
PromiseCreator::lambda([actor_id = actor_id(this), group_call_id, source_ids = std::move(source_ids),
promise = std::move(promise)](Result<Unit> &&result) mutable {
if (G()->close_flag()) {
return promise.set_error(Status::Error(500, "Request aborted"));
}
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
send_closure(actor_id, &GroupCallManager::get_group_call_media_channel_descriptions, group_call_id,
std::move(source_ids), std::move(promise), true);
}
});
td_->create_handler<GetGroupCallParticipantQuery>(std::move(query_promise))
->send(input_group_call_id, {}, std::move(missing_source_ids));
return;
} else {
LOG(INFO) << "Failed to find participants with sources " << missing_source_ids << " in " << group_call_id
<< " from " << group_call->dialog_id;
}
}
promise.set_value(td_api::make_object<td_api::groupCallMediaChannelDescriptions>(std::move(result)));
}
void GroupCallManager::set_group_call_participant_is_speaking(GroupCallId group_call_id, int32 audio_source,
bool is_speaking, Promise<Unit> &&promise, int32 date) {
if (G()->close_flag()) {

View File

@ -89,6 +89,10 @@ class GroupCallManager : public Actor {
void toggle_group_call_recording(GroupCallId group_call_id, bool is_enabled, string title, Promise<Unit> &&promise);
void get_group_call_media_channel_descriptions(
GroupCallId group_call_id, vector<int32> source_ids,
Promise<td_api::object_ptr<td_api::groupCallMediaChannelDescriptions>> &&promise, bool is_recursive = false);
void set_group_call_participant_is_speaking(GroupCallId group_call_id, int32 audio_source, bool is_speaking,
Promise<Unit> &&promise, int32 date = 0);

View File

@ -6031,7 +6031,7 @@ void Td::on_request(uint64 id, td_api::joinGroupCall &request) {
});
group_call_manager_->join_group_call(GroupCallId(request.group_call_id_),
group_call_manager_->get_group_call_participant_id(request.participant_id_),
request.audio_source_, std::move(request.payload_), request.is_muted_,
request.audio_source_id_, std::move(request.payload_), request.is_muted_,
request.is_my_video_enabled_, request.invite_hash_, std::move(query_promise));
}
@ -6120,6 +6120,13 @@ void Td::on_request(uint64 id, const td_api::toggleGroupCallIsMyVideoEnabled &re
request.is_my_video_enabled_, std::move(promise));
}
void Td::on_request(uint64 id, td_api::getGroupCallMediaChannelDescriptions &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
group_call_manager_->get_group_call_media_channel_descriptions(GroupCallId(request.group_call_id_),
std::move(request.source_ids_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::setGroupCallParticipantIsSpeaking &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();

View File

@ -735,6 +735,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, const td_api::toggleGroupCallIsMyVideoEnabled &request);
void on_request(uint64 id, td_api::getGroupCallMediaChannelDescriptions &request);
void on_request(uint64 id, const td_api::setGroupCallParticipantIsSpeaking &request);
void on_request(uint64 id, const td_api::toggleGroupCallParticipantIsMuted &request);

View File

@ -2738,13 +2738,19 @@ class CliClient final : public Actor {
get_args(args, group_call_id, is_my_video_enabled);
send_request(td_api::make_object<td_api::toggleGroupCallIsMyVideoEnabled>(as_group_call_id(group_call_id),
is_my_video_enabled));
} else if (op == "ggcmcd") {
string group_call_id;
string source_ids;
get_args(args, group_call_id, source_ids);
send_request(td_api::make_object<td_api::getGroupCallMediaChannelDescriptions>(as_group_call_id(group_call_id),
to_integers<int32>(source_ids)));
} else if (op == "sgcpis") {
string group_call_id;
int32 source;
int32 source_id;
bool is_speaking;
get_args(args, group_call_id, source, is_speaking);
get_args(args, group_call_id, source_id, is_speaking);
send_request(td_api::make_object<td_api::setGroupCallParticipantIsSpeaking>(as_group_call_id(group_call_id),
source, is_speaking));
source_id, is_speaking));
} else if (op == "igcp") {
string group_call_id;
string user_ids;