Add td_api::setVoiceChatDefaultParticipant.

This commit is contained in:
levlam 2021-04-07 16:25:29 +03:00
parent 4aa5df26bc
commit 37cee0d823
6 changed files with 99 additions and 5 deletions

View File

@ -4604,6 +4604,9 @@ sendCallDebugInformation call_id:int32 debug_information:string = Ok;
//@description Returns list of participant identifiers, which can be used to join voice chats in a chat @chat_id Chat identifier
getVoiceChatAvailableParticipants chat_id:int53 = MessageSenders;
//@description Changes default participant identifier, which can be used to join voice chats in a chat @chat_id Chat identifier @default_participant_id Default group call participant identifier to join the voice chats
setVoiceChatDefaultParticipant chat_id:int53 default_participant_id:MessageSender = Ok;
//@description Creates a voice chat (a group call bound to a chat). Available only for basic groups, supergroups and channels; requires can_manage_voice_chats rights
//@chat_id Chat identifier, in which the voice chat will be created
//@title Group call title; if empty, chat title will be used

View File

@ -123,6 +123,42 @@ class GetGroupCallJoinAsQuery : public Td::ResultHandler {
}
};
class SaveDefaultGroupCallJoinAsQuery : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit SaveDefaultGroupCallJoinAsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(DialogId dialog_id, DialogId as_dialog_id) {
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
CHECK(input_peer != nullptr);
auto as_input_peer = td->messages_manager_->get_input_peer(as_dialog_id, AccessRights::Read);
CHECK(as_input_peer != nullptr);
send_query(G()->net_query_creator().create(
telegram_api::phone_saveDefaultGroupCallJoinAs(std::move(input_peer), std::move(as_input_peer))));
}
void on_result(uint64 id, BufferSlice packet) override {
auto result_ptr = fetch_result<telegram_api::phone_saveDefaultGroupCallJoinAs>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
auto success = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for SaveDefaultGroupCallJoinAsQuery: " << success;
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) override {
// td->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetGroupCallJoinAsQuery");
promise_.set_error(std::move(status));
}
};
class CreateGroupCallQuery : public Td::ResultHandler {
Promise<InputGroupCallId> promise_;
DialogId dialog_id_;
@ -1112,6 +1148,43 @@ void GroupCallManager::get_group_call_join_as(DialogId dialog_id,
td_->create_handler<GetGroupCallJoinAsQuery>(std::move(promise))->send(dialog_id);
}
void GroupCallManager::set_group_call_default_join_as(DialogId dialog_id, DialogId as_dialog_id,
Promise<Unit> &&promise) {
if (!dialog_id.is_valid()) {
return promise.set_error(Status::Error(400, "Invalid chat identifier specified"));
}
if (!td_->messages_manager_->have_dialog_force(dialog_id)) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
if (!td_->messages_manager_->have_input_peer(dialog_id, AccessRights::Read)) {
return promise.set_error(Status::Error(400, "Can't access chat"));
}
switch (as_dialog_id.get_type()) {
case DialogType::User:
if (as_dialog_id != DialogId(td_->contacts_manager_->get_my_id())) {
return promise.set_error(Status::Error(400, "Can't join voice chat as another user"));
}
break;
case DialogType::Chat:
case DialogType::Channel:
if (!td_->messages_manager_->have_dialog_force(as_dialog_id)) {
return promise.set_error(Status::Error(400, "Participant chat not found"));
}
break;
case DialogType::SecretChat:
return promise.set_error(Status::Error(400, "Can't join voice chat as a secret chat"));
default:
return promise.set_error(Status::Error(400, "Invalid default participant identifier specified"));
}
if (!td_->messages_manager_->have_input_peer(as_dialog_id, AccessRights::Read)) {
return promise.set_error(Status::Error(400, "Can't access specified default participant chat"));
}
td_->create_handler<SaveDefaultGroupCallJoinAsQuery>(std::move(promise))->send(dialog_id, as_dialog_id);
td_->messages_manager_->on_update_dialog_default_join_group_call_as_dialog_id(dialog_id, as_dialog_id, true);
}
void GroupCallManager::create_voice_chat(DialogId dialog_id, string title, int32 start_date,
Promise<GroupCallId> &&promise) {
if (!dialog_id.is_valid()) {
@ -2213,11 +2286,11 @@ void GroupCallManager::join_group_call(GroupCallId group_call_id, DialogId as_di
}
} else {
if (!td_->messages_manager_->have_dialog_force(as_dialog_id, "join_group_call")) {
return promise.set_error(Status::Error(400, "Alias chat not found"));
return promise.set_error(Status::Error(400, "Join as chat not found"));
}
}
if (!td_->messages_manager_->have_input_peer(as_dialog_id, AccessRights::Read)) {
return promise.set_error(Status::Error(400, "Can't access the alias participant"));
return promise.set_error(Status::Error(400, "Can't access the join as participant"));
}
if (dialog_type == DialogType::SecretChat) {
return promise.set_error(Status::Error(400, "Can't join voice chat as a secret chat"));

View File

@ -48,6 +48,8 @@ class GroupCallManager : public Actor {
void get_group_call_join_as(DialogId dialog_id, Promise<td_api::object_ptr<td_api::messageSenders>> &&promise);
void set_group_call_default_join_as(DialogId dialog_id, DialogId as_dialog_id, Promise<Unit> &&promise);
void create_voice_chat(DialogId dialog_id, string title, int32 start_date, Promise<GroupCallId> &&promise);
void get_group_call(GroupCallId group_call_id, Promise<td_api::object_ptr<td_api::groupCall>> &&promise);

View File

@ -5974,6 +5974,14 @@ void Td::on_request(uint64 id, const td_api::getVoiceChatAvailableParticipants &
group_call_manager_->get_group_call_join_as(DialogId(request.chat_id_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::setVoiceChatDefaultParticipant &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
group_call_manager_->set_group_call_default_join_as(
DialogId(request.chat_id_), group_call_manager_->get_group_call_participant_id(request.default_participant_id_),
std::move(promise));
}
void Td::on_request(uint64 id, td_api::createVoiceChat &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.title_);

View File

@ -703,6 +703,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, const td_api::getVoiceChatAvailableParticipants &request);
void on_request(uint64 id, const td_api::setVoiceChatDefaultParticipant &request);
void on_request(uint64 id, td_api::createVoiceChat &request);
void on_request(uint64 id, const td_api::getGroupCall &request);

View File

@ -2672,6 +2672,12 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::sendCallDebugInformation>(as_call_id(args), "{}"));
} else if (op == "gvcap") {
send_request(td_api::make_object<td_api::getVoiceChatAvailableParticipants>(as_chat_id(args)));
} else if (op == "svcdp") {
string group_call_id;
string participant_id;
get_args(args, group_call_id, participant_id);
send_request(td_api::make_object<td_api::setVoiceChatDefaultParticipant>(as_chat_id(args),
as_message_sender(participant_id)));
} else if (op == "cvc") {
string chat_id;
string title;
@ -2690,14 +2696,14 @@ class CliClient final : public Actor {
op == "tgcesne"));
} else if (op == "jgc") {
string group_call_id;
string participant_alias;
string participant_id;
string invite_hash;
get_args(args, group_call_id, participant_alias, invite_hash);
get_args(args, group_call_id, participant_id, invite_hash);
vector<td_api::object_ptr<td_api::groupCallPayloadFingerprint>> fingerprints;
fingerprints.push_back(td_api::make_object<td_api::groupCallPayloadFingerprint>("hash", "setup", "fingerprint"));
fingerprints.push_back(td_api::make_object<td_api::groupCallPayloadFingerprint>("h2", "s2", "fingerprint2"));
send_request(td_api::make_object<td_api::joinGroupCall>(
as_group_call_id(group_call_id), as_message_sender(participant_alias),
as_group_call_id(group_call_id), as_message_sender(participant_id),
td_api::make_object<td_api::groupCallPayload>("ufrag", "pwd", std::move(fingerprints)), group_call_source_,
true, invite_hash));
} else if (op == "sgct") {