Add setGroupCallParticipantVolumeLevel.

This commit is contained in:
levlam 2021-01-02 22:59:48 +03:00
parent 6b66cd8716
commit 6bba5a568a
9 changed files with 58 additions and 7 deletions

View File

@ -4385,7 +4385,7 @@ getGroupCall group_call_id:int32 = GroupCall;
//@description Joins a group call @group_call_id Group call identifier @payload Group join payload, received from tgcalls. Use null to cancel previous joinGroupCall request @source Caller synchronization source identifier; received from tgcalls @is_muted True, if the user's microphone is muted
joinGroupCall group_call_id:int32 payload:groupCallPayload source:int32 is_muted:Bool = GroupCallJoinResponse;
//@description Toggles whether new participants of a group call can be unmuted only by administrators of the group call. Requires can_manage_voice_chats rights in the corresponding chat and allowed_change_mute_mew_participants group call flag
//@description Toggles whether new participants of a group call can be unmuted only by administrators of the group call. Requires groupCall.can_be_managed and allowed_change_mute_mew_participants group call flag
//@group_call_id Group call identifier @mute_new_participants New value of the mute_new_participants setting
toggleGroupCallMuteNewParticipants group_call_id:int32 mute_new_participants:Bool = Ok;
@ -4401,6 +4401,10 @@ setGroupCallParticipantIsSpeaking group_call_id:int32 source:int32 is_speaking:B
//@group_call_id Group call identifier @user_id User identifier @is_muted Pass true if the user must be muted and false otherwise
toggleGroupCallParticipantIsMuted group_call_id:int32 user_id:int32 is_muted:Bool = Ok;
//@description Changes a group call participant's volume level. If the current user can manage the group call, then the participant's volume level will be changed for all users with default volume level
//@group_call_id Group call identifier @user_id User identifier @volume_level New participant's volume level; 1-20000 in hundreds of percents
setGroupCallParticipantVolumeLevel group_call_id:int32 user_id:int32 volume_level:int32 = Ok;
//@description Loads more group call participants. The loaded participants will be received through updates. Use the field groupCall.loaded_all_participants to check whether all participants has already been loaded
//@group_call_id Group call identifier. The group call must be previously received through getGroupCall and must be joined or being joined
//@limit Maximum number of participants to load
@ -4409,7 +4413,7 @@ 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;
//@description Discards a group call. Requires can_manage_voice_chats rights in the corresponding chat @group_call_id Group call identifier
//@description Discards a group call. Requires groupCall.can_be_managed @group_call_id Group call identifier
discardGroupCall group_call_id:int32 = Ok;

Binary file not shown.

View File

@ -281,17 +281,19 @@ class EditGroupCallMemberQuery : public Td::ResultHandler {
explicit EditGroupCallMemberQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(InputGroupCallId input_group_call_id, UserId user_id, bool is_muted) {
void send(InputGroupCallId input_group_call_id, UserId user_id, bool is_muted, int32 volume_level) {
auto input_user = td->contacts_manager_->get_input_user(user_id);
CHECK(input_user != nullptr);
int32 flags = 0;
if (is_muted) {
if (volume_level) {
flags |= telegram_api::phone_editGroupCallMember::VOLUME_MASK;
} else if (is_muted) {
flags |= telegram_api::phone_editGroupCallMember::MUTED_MASK;
}
send_query(G()->net_query_creator().create(telegram_api::phone_editGroupCallMember(
flags, false /*ignored*/, input_group_call_id.get_input_group_call(), std::move(input_user), 0)));
flags, false /*ignored*/, input_group_call_id.get_input_group_call(), std::move(input_user), volume_level)));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -1772,7 +1774,30 @@ void GroupCallManager::toggle_group_call_participant_is_muted(GroupCallId group_
return promise.set_error(Status::Error(400, "Can't unmute self"));
}
td_->create_handler<EditGroupCallMemberQuery>(std::move(promise))->send(input_group_call_id, user_id, is_muted);
td_->create_handler<EditGroupCallMemberQuery>(std::move(promise))->send(input_group_call_id, user_id, is_muted, 0);
}
void GroupCallManager::set_group_call_participant_volume_level(GroupCallId group_call_id, UserId user_id,
int32 volume_level, Promise<Unit> &&promise) {
TRY_RESULT_PROMISE(promise, input_group_call_id, get_input_group_call_id(group_call_id));
if (volume_level < GroupCallParticipant::MIN_VOLUME_LEVEL || volume_level > GroupCallParticipant::MAX_VOLUME_LEVEL) {
return promise.set_error(Status::Error(400, "Wrong volume level specified"));
}
auto *group_call = get_group_call(input_group_call_id);
if (group_call == nullptr || !group_call->is_inited || !group_call->is_active || !group_call->is_joined) {
return promise.set_error(Status::Error(400, "GROUP_CALL_JOIN_MISSING"));
}
if (!td_->contacts_manager_->have_input_user(user_id)) {
return promise.set_error(Status::Error(400, "Have no access to the user"));
}
if (user_id == td_->contacts_manager_->get_my_id()) {
return promise.set_error(Status::Error(400, "Can't change self volume level"));
}
td_->create_handler<EditGroupCallMemberQuery>(std::move(promise))
->send(input_group_call_id, user_id, false, volume_level);
}
void GroupCallManager::load_group_call_participants(GroupCallId group_call_id, int32 limit, Promise<Unit> &&promise) {

View File

@ -62,6 +62,9 @@ class GroupCallManager : public Actor {
void toggle_group_call_participant_is_muted(GroupCallId group_call_id, UserId user_id, bool is_muted,
Promise<Unit> &&promise);
void set_group_call_participant_volume_level(GroupCallId group_call_id, UserId user_id, int32 volume_level,
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);

View File

@ -28,7 +28,7 @@ GroupCallParticipant::GroupCallParticipant(const tl_object_ptr<telegram_api::gro
}
if ((participant->flags_ & telegram_api::groupCallParticipant::VOLUME_MASK) != 0) {
volume_level = participant->volume_;
if (volume_level <= 0 || volume_level > 20000) {
if (volume_level < MIN_VOLUME_LEVEL || volume_level > MAX_VOLUME_LEVEL) {
LOG(ERROR) << "Receive " << to_string(participant);
volume_level = 10000;
}

View File

@ -38,6 +38,9 @@ struct GroupCallParticipant {
int32 local_active_date = 0;
int64 order = 0;
static constexpr int32 MIN_VOLUME_LEVEL = 1;
static constexpr int32 MAX_VOLUME_LEVEL = 20000;
GroupCallParticipant() = default;
explicit GroupCallParticipant(const tl_object_ptr<telegram_api::groupCallParticipant> &participant);

View File

@ -6001,6 +6001,13 @@ void Td::on_request(uint64 id, const td_api::toggleGroupCallParticipantIsMuted &
GroupCallId(request.group_call_id_), UserId(request.user_id_), request.is_muted_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::setGroupCallParticipantVolumeLevel &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
group_call_manager_->set_group_call_participant_volume_level(
GroupCallId(request.group_call_id_), UserId(request.user_id_), request.volume_level_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::loadGroupCallParticipants &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();

View File

@ -706,6 +706,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, const td_api::toggleGroupCallParticipantIsMuted &request);
void on_request(uint64 id, const td_api::setGroupCallParticipantVolumeLevel &request);
void on_request(uint64 id, const td_api::loadGroupCallParticipants &request);
void on_request(uint64 id, const td_api::leaveGroupCall &request);

View File

@ -2665,6 +2665,13 @@ class CliClient final : public Actor {
get_args(args, group_call_id, user_id, is_muted);
send_request(td_api::make_object<td_api::toggleGroupCallParticipantIsMuted>(as_group_call_id(group_call_id),
as_user_id(user_id), is_muted));
} else if (op == "tgcpvl") {
string group_call_id;
string user_id;
int32 volume_level;
get_args(args, group_call_id, user_id, volume_level);
send_request(td_api::make_object<td_api::setGroupCallParticipantVolumeLevel>(as_group_call_id(group_call_id),
as_user_id(user_id), volume_level));
} else if (op == "lgcp") {
string group_call_id;
string limit;