Use MessageSender as participant_alias.

This commit is contained in:
levlam 2021-03-08 18:08:41 +03:00
parent f24ca02f37
commit 574884510b
6 changed files with 58 additions and 21 deletions

View File

@ -894,8 +894,8 @@ chatPosition list:ChatList order:int64 is_pinned:Bool source:ChatSource = ChatPo
//@description Describes a voice chat
//@group_call_id Group call identifier of an active voice chat; 0 if none. Full informationa about the voice chat can be received through the method getGroupCall
//@has_participants True, if the voice chat has participants
//@default_join_as_chat_id Chat identifier of a chat, under which name to join voice chat by default; 0 if none or unknown
voiceChat group_call_id:int32 has_participants:Bool default_join_as_chat_id:int53 = VoiceChat;
//@default_participant_alias Default group call participant identifier to join the voice chat; may be null
voiceChat group_call_id:int32 has_participants:Bool default_participant_alias:MessageSender = VoiceChat;
//@description A chat. (Can be a private chat, basic group, supergroup, or secret chat)
@ -4559,8 +4559,13 @@ createVoiceChat chat_id:int53 = GroupCallId;
//@description Returns information about a group call @group_call_id Group call identifier
getGroupCall group_call_id:int32 = GroupCall;
//@description Joins a group call @group_call_id Group call identifier @as_chat_id If not 0, identifier of the chat, which will be used to join the call @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 as_chat_id:int53 payload:groupCallPayload source:int32 is_muted:Bool = GroupCallJoinResponse;
//@description Joins a group call
//@group_call_id Group call identifier
//@participant_alias Identifier of the group call participant, which will be used to join the call
//@payload Group join payload; received from tgcalls
//@source Caller synchronization source identifier; received from tgcalls
//@is_muted True, if the user's microphone is muted
joinGroupCall group_call_id:int32 participant_alias:MessageSender payload:groupCallPayload source:int32 is_muted:Bool = GroupCallJoinResponse;
//@description Sets group call title. Requires groupCall.can_be_managed group call flag @group_call_id Group call identifier @title New group call title; 1-128 characters
setGroupCallTitle group_call_id:int32 title:string = Ok;

View File

@ -1602,14 +1602,29 @@ void GroupCallManager::join_group_call(GroupCallId group_call_id, DialogId as_di
cancel_join_group_call_request(input_group_call_id);
if (as_dialog_id != DialogId()) {
if (!td_->messages_manager_->have_dialog_force(as_dialog_id)) {
return promise.set_error(Status::Error(400, "Chat not found"));
bool have_as_dialog_id = true;
{
auto my_dialog_id = DialogId(td_->contacts_manager_->get_my_id());
if (!as_dialog_id.is_valid()) {
as_dialog_id = my_dialog_id;
}
auto dialog_type = as_dialog_id.get_type();
if (dialog_type == DialogType::User) {
if (as_dialog_id != my_dialog_id) {
return promise.set_error(Status::Error(400, "Can't join voice chat as another user"));
}
if (!td_->contacts_manager_->have_user_force(as_dialog_id.get_user_id())) {
have_as_dialog_id = false;
}
} else {
if (!td_->messages_manager_->have_dialog_force(as_dialog_id)) {
return promise.set_error(Status::Error(400, "Alias 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 chat"));
return promise.set_error(Status::Error(400, "Can't access the alias participant"));
}
if (as_dialog_id.get_type() == DialogType::SecretChat) {
if (dialog_type == DialogType::SecretChat) {
return promise.set_error(Status::Error(400, "Can't join voice chat as a secret chat"));
}
}
@ -1676,16 +1691,15 @@ void GroupCallManager::join_group_call(GroupCallId group_call_id, DialogId as_di
request->query_ref = td_->create_handler<JoinGroupCallQuery>(std::move(query_promise))
->send(input_group_call_id, as_dialog_id, json_payload, is_muted, generation);
if (!as_dialog_id.is_valid()) {
as_dialog_id = DialogId(td_->contacts_manager_->get_my_id());
}
if (group_call->dialog_id.is_valid()) {
td_->messages_manager_->on_update_dialog_default_join_group_call_as_dialog_id(group_call->dialog_id, as_dialog_id,
true);
} else {
td_->messages_manager_->force_create_dialog(as_dialog_id, "join_group_call");
if (as_dialog_id.get_type() != DialogType::User) {
td_->messages_manager_->force_create_dialog(as_dialog_id, "join_group_call");
}
}
if (group_call->is_inited) {
if (group_call->is_inited && have_as_dialog_id) {
GroupCallParticipant group_call_participant;
group_call_participant.is_self = true;
group_call_participant.dialog_id = as_dialog_id;

View File

@ -6108,6 +6108,13 @@ td_api::object_ptr<td_api::MessageSender> MessagesManager::get_message_sender_ob
return get_message_sender_object_const(user_id, dialog_id);
}
td_api::object_ptr<td_api::MessageSender> MessagesManager::get_message_sender_object_const(DialogId dialog_id) const {
if (dialog_id.get_type() == DialogType::User) {
return get_message_sender_object_const(dialog_id.get_user_id(), DialogId());
}
return get_message_sender_object_const(UserId(), dialog_id);
}
td_api::object_ptr<td_api::MessageSender> MessagesManager::get_message_sender_object(DialogId dialog_id) {
if (dialog_id.get_type() == DialogType::User) {
return get_message_sender_object(dialog_id.get_user_id(), DialogId());
@ -19857,9 +19864,12 @@ td_api::object_ptr<td_api::ChatActionBar> MessagesManager::get_chat_action_bar_o
td_api::object_ptr<td_api::voiceChat> MessagesManager::get_voice_chat_object(const Dialog *d) const {
auto active_group_call_id = td_->group_call_manager_->get_group_call_id(d->active_group_call_id, d->dialog_id);
auto default_participant_alias = d->default_join_group_call_as_dialog_id.is_valid()
? get_message_sender_object_const(d->default_join_group_call_as_dialog_id)
: nullptr;
return make_tl_object<td_api::voiceChat>(active_group_call_id.get(),
active_group_call_id.is_valid() ? !d->is_group_call_empty : false,
d->default_join_group_call_as_dialog_id.get());
std::move(default_participant_alias));
}
td_api::object_ptr<td_api::chat> MessagesManager::get_chat_object(const Dialog *d) const {
@ -29806,7 +29816,12 @@ void MessagesManager::on_update_dialog_default_join_group_call_as_dialog_id(Dial
}
if (default_join_as_dialog_id.is_valid()) {
force_create_dialog(default_join_as_dialog_id, "on_update_dialog_default_join_group_call_as_dialog_id");
if (default_join_as_dialog_id.get_type() != DialogType::User) {
force_create_dialog(default_join_as_dialog_id, "on_update_dialog_default_join_group_call_as_dialog_id");
} else if (!td_->contacts_manager_->have_user_force(default_join_as_dialog_id.get_user_id()) ||
default_join_as_dialog_id != get_my_dialog_id()) {
default_join_as_dialog_id = DialogId();
}
}
if (d->default_join_group_call_as_dialog_id != default_join_as_dialog_id) {

View File

@ -147,6 +147,8 @@ class MessagesManager : public Actor {
td_api::object_ptr<td_api::MessageSender> get_message_sender_object(UserId user_id, DialogId dialog_id);
td_api::object_ptr<td_api::MessageSender> get_message_sender_object_const(DialogId dialog_id) const;
td_api::object_ptr<td_api::MessageSender> get_message_sender_object(DialogId dialog_id);
static vector<MessageId> get_message_ids(const vector<int64> &input_message_ids);

View File

@ -5985,7 +5985,8 @@ void Td::on_request(uint64 id, const td_api::getGroupCall &request) {
void Td::on_request(uint64 id, td_api::joinGroupCall &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
group_call_manager_->join_group_call(GroupCallId(request.group_call_id_), DialogId(request.as_chat_id_),
group_call_manager_->join_group_call(GroupCallId(request.group_call_id_),
group_call_manager_->get_group_call_participant_id(request.participant_alias_),
std::move(request.payload_), request.source_, request.is_muted_,
std::move(promise));
}

View File

@ -2671,17 +2671,17 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::getGroupCall>(as_group_call_id(args)));
} else if (op == "jgc") {
string group_call_id;
string chat_id;
get_args(args, group_call_id, chat_id);
string participant_alias;
get_args(args, group_call_id, participant_alias);
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_chat_id(chat_id),
as_group_call_id(group_call_id), as_message_sender(participant_alias),
td_api::make_object<td_api::groupCallPayload>("ufrag", "pwd", std::move(fingerprints)), group_call_source_,
true));
} else if (op == "jgcc") {
send_request(td_api::make_object<td_api::joinGroupCall>(as_group_call_id(args), 0, nullptr, 0, true));
send_request(td_api::make_object<td_api::joinGroupCall>(as_group_call_id(args), nullptr, nullptr, 0, true));
} else if (op == "sgct") {
string chat_id;
string title;