Add td_api::toggleGroupCallParticipantIsHandRaised.

This commit is contained in:
levlam 2021-03-15 01:56:59 +03:00
parent a4431b2604
commit e2ac80f2ba
6 changed files with 133 additions and 7 deletions

View File

@ -4616,6 +4616,11 @@ toggleGroupCallParticipantIsMuted group_call_id:int32 participant:MessageSender
//@group_call_id Group call identifier @participant Participant identifier @volume_level New participant's volume level; 1-20000 in hundreds of percents
setGroupCallParticipantVolumeLevel group_call_id:int32 participant:MessageSender volume_level:int32 = Ok;
//@description Toggles whether a group call participant hand is rased
//@group_call_id Group call identifier @participant Participant identifier
//@is_hand_raised Pass true if the user's hand should be raised. Only self hand can be raised. Requires groupCall.can_be_managed group call flag to lower other's hand
toggleGroupCallParticipantIsHandRaised group_call_id:int32 participant:MessageSender is_hand_raised:Bool = 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

View File

@ -497,12 +497,15 @@ class EditGroupCallParticipantQuery : public Td::ResultHandler {
explicit EditGroupCallParticipantQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(InputGroupCallId input_group_call_id, DialogId dialog_id, bool is_muted, int32 volume_level) {
void send(InputGroupCallId input_group_call_id, DialogId dialog_id, bool is_muted, int32 volume_level,
bool set_raise_hand, bool raise_hand) {
auto input_peer = MessagesManager::get_input_peer_force(dialog_id);
CHECK(input_peer != nullptr);
int32 flags = 0;
if (volume_level) {
if (set_raise_hand) {
flags |= telegram_api::phone_editGroupCallParticipant::RAISE_HAND_MASK;
} else if (volume_level) {
flags |= telegram_api::phone_editGroupCallParticipant::VOLUME_MASK;
} else if (is_muted) {
flags |= telegram_api::phone_editGroupCallParticipant::MUTED_MASK;
@ -510,7 +513,7 @@ class EditGroupCallParticipantQuery : public Td::ResultHandler {
send_query(G()->net_query_creator().create(telegram_api::phone_editGroupCallParticipant(
flags, false /*ignored*/, input_group_call_id.get_input_group_call(), std::move(input_peer), volume_level,
false)));
raise_hand)));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -2564,7 +2567,7 @@ void GroupCallManager::toggle_group_call_participant_is_muted(GroupCallId group_
generation, std::move(promise));
});
td_->create_handler<EditGroupCallParticipantQuery>(std::move(query_promise))
->send(input_group_call_id, dialog_id, is_muted, 0);
->send(input_group_call_id, dialog_id, is_muted, 0, false, false);
}
void GroupCallManager::on_toggle_group_call_participant_is_muted(InputGroupCallId input_group_call_id,
@ -2654,7 +2657,7 @@ void GroupCallManager::set_group_call_participant_volume_level(GroupCallId group
dialog_id, generation, std::move(promise));
});
td_->create_handler<EditGroupCallParticipantQuery>(std::move(query_promise))
->send(input_group_call_id, dialog_id, false, volume_level);
->send(input_group_call_id, dialog_id, false, volume_level, false, false);
}
void GroupCallManager::on_set_group_call_participant_volume_level(InputGroupCallId input_group_call_id,
@ -2687,6 +2690,99 @@ void GroupCallManager::on_set_group_call_participant_volume_level(InputGroupCall
promise.set_value(Unit());
}
void GroupCallManager::toggle_group_call_participant_is_hand_raised(GroupCallId group_call_id, DialogId dialog_id,
bool is_hand_raised, Promise<Unit> &&promise) {
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, dialog_id, is_hand_raised,
promise = std::move(promise)](Result<Unit> &&result) mutable {
if (result.is_error()) {
promise.set_error(Status::Error(400, "GROUPCALL_JOIN_MISSING"));
} else {
send_closure(actor_id, &GroupCallManager::toggle_group_call_participant_is_hand_raised, group_call_id,
dialog_id, is_hand_raised, std::move(promise));
}
}));
return;
}
return promise.set_error(Status::Error(400, "GROUPCALL_JOIN_MISSING"));
}
auto participants = add_group_call_participants(input_group_call_id);
auto participant = get_group_call_participant(participants, dialog_id);
if (participant == nullptr) {
return promise.set_error(Status::Error(400, "Can't find group call participant"));
}
if (is_hand_raised == participant->get_is_hand_raised()) {
return promise.set_value(Unit());
}
if (is_hand_raised) {
if (!participant->is_self) {
return promise.set_error(Status::Error(400, "Can't raise others hand"));
}
} else {
if (!can_manage_group_call(input_group_call_id)) {
return promise.set_error(Status::Error(400, "Have not enough rights in the group call"));
}
}
participant->have_pending_is_hand_raised = true;
participant->pending_is_hand_raised = is_hand_raised;
participant->pending_is_hand_raised_generation = ++toggle_is_hand_raised_generation_;
if (participant->order != 0) {
send_update_group_call_participant(input_group_call_id, *participant);
}
auto query_promise = PromiseCreator::lambda([actor_id = actor_id(this), input_group_call_id, dialog_id,
generation = participant->pending_is_hand_raised_generation,
promise = std::move(promise)](Result<Unit> &&result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
}
send_closure(actor_id, &GroupCallManager::on_toggle_group_call_participant_is_hand_raised, input_group_call_id,
dialog_id, generation, std::move(promise));
});
td_->create_handler<EditGroupCallParticipantQuery>(std::move(query_promise))
->send(input_group_call_id, dialog_id, false, 0, true, is_hand_raised);
}
void GroupCallManager::on_toggle_group_call_participant_is_hand_raised(InputGroupCallId input_group_call_id,
DialogId dialog_id, uint64 generation,
Promise<Unit> &&promise) {
if (G()->close_flag()) {
return promise.set_value(Unit());
}
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_value(Unit());
}
auto participant = get_group_call_participant(input_group_call_id, dialog_id);
if (participant == nullptr || participant->pending_is_hand_raised_generation != generation) {
return promise.set_value(Unit());
}
CHECK(participant->have_pending_is_hand_raised);
participant->have_pending_is_hand_raised = false;
if (participant->get_is_hand_raised() != participant->pending_is_hand_raised) {
LOG(ERROR) << "Failed to change raised hand state for " << dialog_id << " in " << input_group_call_id;
if (participant->order != 0) {
send_update_group_call_participant(input_group_call_id, *participant);
}
}
promise.set_value(Unit());
}
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"));

View File

@ -85,6 +85,9 @@ class GroupCallManager : public Actor {
void set_group_call_participant_volume_level(GroupCallId group_call_id, DialogId dialog_id, int32 volume_level,
Promise<Unit> &&promise);
void toggle_group_call_participant_is_hand_raised(GroupCallId group_call_id, DialogId dialog_id, bool is_hand_raised,
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);
@ -117,7 +120,7 @@ class GroupCallManager : public Actor {
static constexpr int32 RECENT_SPEAKER_TIMEOUT = 60 * 60;
static constexpr int32 CHECK_GROUP_CALL_IS_JOINED_TIMEOUT = 10;
static constexpr size_t MAX_TITLE_LENGTH = 64; // server side limit for group call title length
static constexpr size_t MAX_TITLE_LENGTH = 64; // server side limit for group call title length
static constexpr size_t MAX_RECORD_TITLE_LENGTH = 128; // server side limit for group call record title length
void tear_down() override;
@ -235,6 +238,9 @@ class GroupCallManager : public Actor {
void on_set_group_call_participant_volume_level(InputGroupCallId input_group_call_id, DialogId dialog_id,
uint64 generation, Promise<Unit> &&promise);
void on_toggle_group_call_participant_is_hand_raised(InputGroupCallId input_group_call_id, DialogId dialog_id,
uint64 generation, Promise<Unit> &&promise);
void on_group_call_left(InputGroupCallId input_group_call_id, int32 audio_source, bool need_rejoin);
void on_group_call_left_impl(GroupCall *group_call, bool need_rejoin);
@ -302,9 +308,11 @@ class GroupCallManager : public Actor {
uint64 toggle_recording_generation_ = 0;
uint64 toggle_is_muted_generation_ = 0;
uint64 set_volume_level_generation_ = 0;
uint64 toggle_is_muted_generation_ = 0;
uint64 toggle_is_hand_raised_generation_ = 0;
MultiTimeout check_group_call_is_joined_timeout_{"CheckGroupCallIsJoinedTimeout"};
MultiTimeout pending_send_speaking_action_timeout_{"PendingSendSpeakingActionTimeout"};

View File

@ -6082,6 +6082,14 @@ void Td::on_request(uint64 id, const td_api::setGroupCallParticipantVolumeLevel
request.volume_level_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::toggleGroupCallParticipantIsHandRaised &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
group_call_manager_->toggle_group_call_participant_is_hand_raised(
GroupCallId(request.group_call_id_), group_call_manager_->get_group_call_participant_id(request.participant_),
request.is_hand_raised_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::loadGroupCallParticipants &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();

View File

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

View File

@ -2737,6 +2737,13 @@ class CliClient final : public Actor {
get_args(args, group_call_id, participant_id, volume_level);
send_request(td_api::make_object<td_api::setGroupCallParticipantVolumeLevel>(
as_group_call_id(group_call_id), as_message_sender(participant_id), volume_level));
} else if (op == "tgcpihr") {
string group_call_id;
string participant_id;
bool is_hand_raised;
get_args(args, group_call_id, participant_id, is_hand_raised);
send_request(td_api::make_object<td_api::toggleGroupCallParticipantIsHandRaised>(
as_group_call_id(group_call_id), as_message_sender(participant_id), is_hand_raised));
} else if (op == "lgcp") {
string group_call_id;
string limit;