Improve get_message_sender_dialog_id.
This commit is contained in:
parent
21c8c752be
commit
1a291847d7
@ -1069,32 +1069,6 @@ void GroupCallManager::on_sync_participants_timeout(GroupCallId group_call_id) {
|
||||
sync_group_call_participants(input_group_call_id);
|
||||
}
|
||||
|
||||
DialogId GroupCallManager::get_group_call_participant_id(
|
||||
const td_api::object_ptr<td_api::MessageSender> &message_sender) {
|
||||
if (message_sender == nullptr) {
|
||||
return DialogId();
|
||||
}
|
||||
switch (message_sender->get_id()) {
|
||||
case td_api::messageSenderUser::ID: {
|
||||
UserId user_id(static_cast<const td_api::messageSenderUser *>(message_sender.get())->user_id_);
|
||||
if (td_->contacts_manager_->have_user_force(user_id)) {
|
||||
return DialogId(user_id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case td_api::messageSenderChat::ID: {
|
||||
DialogId dialog_id(static_cast<const td_api::messageSenderChat *>(message_sender.get())->chat_id_);
|
||||
if (td_->messages_manager_->have_dialog_force(dialog_id, "get_group_call_participant_id")) {
|
||||
return dialog_id;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
return DialogId();
|
||||
}
|
||||
|
||||
bool GroupCallManager::is_group_call_being_joined(InputGroupCallId input_group_call_id) const {
|
||||
return pending_join_requests_.count(input_group_call_id) != 0;
|
||||
}
|
||||
|
@ -39,8 +39,6 @@ class GroupCallManager final : public Actor {
|
||||
GroupCallManager &operator=(GroupCallManager &&) = delete;
|
||||
~GroupCallManager() final;
|
||||
|
||||
DialogId get_group_call_participant_id(const td_api::object_ptr<td_api::MessageSender> &message_sender);
|
||||
|
||||
bool is_group_call_being_joined(InputGroupCallId input_group_call_id) const;
|
||||
|
||||
bool is_group_call_joined(InputGroupCallId input_group_call_id) const;
|
||||
|
@ -95,23 +95,40 @@ td_api::object_ptr<td_api::messageSenders> convert_message_senders_object(
|
||||
return td_api::make_object<td_api::messageSenders>(narrow_cast<int32>(dialog_ids.size()), std::move(message_senders));
|
||||
}
|
||||
|
||||
Result<DialogId> get_message_sender_dialog_id(const td_api::object_ptr<td_api::MessageSender> &message_sender_id) {
|
||||
Result<DialogId> get_message_sender_dialog_id(Td *td,
|
||||
const td_api::object_ptr<td_api::MessageSender> &message_sender_id,
|
||||
bool check_access, bool allow_empty) {
|
||||
if (message_sender_id == nullptr) {
|
||||
if (allow_empty) {
|
||||
return DialogId();
|
||||
}
|
||||
return Status::Error(400, "Member identifier is not specified");
|
||||
}
|
||||
switch (message_sender_id->get_id()) {
|
||||
case td_api::messageSenderUser::ID: {
|
||||
auto user_id = UserId(static_cast<const td_api::messageSenderUser *>(message_sender_id.get())->user_id_);
|
||||
if (!user_id.is_valid()) {
|
||||
if (allow_empty && user_id == UserId()) {
|
||||
return DialogId();
|
||||
}
|
||||
return Status::Error(400, "Invalid user identifier specified");
|
||||
}
|
||||
if (check_access && !td->contacts_manager_->have_user_force(user_id)) {
|
||||
return Status::Error(400, "Unknown user identifier specified");
|
||||
}
|
||||
return DialogId(user_id);
|
||||
}
|
||||
case td_api::messageSenderChat::ID: {
|
||||
auto dialog_id = DialogId(static_cast<const td_api::messageSenderChat *>(message_sender_id.get())->chat_id_);
|
||||
if (!dialog_id.is_valid()) {
|
||||
if (allow_empty && dialog_id == DialogId()) {
|
||||
return DialogId();
|
||||
}
|
||||
return Status::Error(400, "Invalid chat identifier specified");
|
||||
}
|
||||
if (check_access && !td->messages_manager_->have_dialog_force(dialog_id, "get_message_sender_dialog_id")) {
|
||||
return Status::Error(400, "Unknown chat identifier specified");
|
||||
}
|
||||
return dialog_id;
|
||||
}
|
||||
default:
|
||||
|
@ -34,6 +34,8 @@ vector<DialogId> get_message_sender_dialog_ids(Td *td,
|
||||
td_api::object_ptr<td_api::messageSenders> convert_message_senders_object(
|
||||
Td *td, const vector<telegram_api::object_ptr<telegram_api::Peer>> &peers);
|
||||
|
||||
Result<DialogId> get_message_sender_dialog_id(const td_api::object_ptr<td_api::MessageSender> &message_sender_id);
|
||||
Result<DialogId> get_message_sender_dialog_id(Td *td,
|
||||
const td_api::object_ptr<td_api::MessageSender> &message_sender_id,
|
||||
bool check_access, bool allow_empty);
|
||||
|
||||
} // namespace td
|
||||
|
@ -5800,9 +5800,10 @@ void Td::on_request(uint64 id, const td_api::getVideoChatAvailableParticipants &
|
||||
void Td::on_request(uint64 id, const td_api::setVideoChatDefaultParticipant &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));
|
||||
TRY_RESULT_PROMISE(promise, default_join_as_dialog_id,
|
||||
get_message_sender_dialog_id(this, request.default_participant_id_, true, false));
|
||||
group_call_manager_->set_group_call_default_join_as(DialogId(request.chat_id_), default_join_as_dialog_id,
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::createVideoChat &request) {
|
||||
@ -5844,6 +5845,8 @@ void Td::on_request(uint64 id, td_api::joinGroupCall &request) {
|
||||
CLEAN_INPUT_STRING(request.invite_hash_);
|
||||
CLEAN_INPUT_STRING(request.payload_);
|
||||
CREATE_REQUEST_PROMISE();
|
||||
TRY_RESULT_PROMISE(promise, join_as_dialog_id,
|
||||
get_message_sender_dialog_id(this, request.participant_id_, true, true));
|
||||
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<string> result) mutable {
|
||||
if (result.is_error()) {
|
||||
promise.set_error(result.move_as_error());
|
||||
@ -5851,10 +5854,9 @@ void Td::on_request(uint64 id, td_api::joinGroupCall &request) {
|
||||
promise.set_value(make_tl_object<td_api::text>(result.move_as_ok()));
|
||||
}
|
||||
});
|
||||
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_id_, std::move(request.payload_), request.is_muted_,
|
||||
request.is_my_video_enabled_, request.invite_hash_, std::move(query_promise));
|
||||
group_call_manager_->join_group_call(GroupCallId(request.group_call_id_), join_as_dialog_id, request.audio_source_id_,
|
||||
std::move(request.payload_), request.is_muted_, request.is_my_video_enabled_,
|
||||
request.invite_hash_, std::move(query_promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::startGroupCallScreenSharing &request) {
|
||||
@ -5967,25 +5969,28 @@ void Td::on_request(uint64 id, const td_api::setGroupCallParticipantIsSpeaking &
|
||||
void Td::on_request(uint64 id, const td_api::toggleGroupCallParticipantIsMuted &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
TRY_RESULT_PROMISE(promise, participant_dialog_id,
|
||||
get_message_sender_dialog_id(this, request.participant_id_, true, false));
|
||||
group_call_manager_->toggle_group_call_participant_is_muted(
|
||||
GroupCallId(request.group_call_id_), group_call_manager_->get_group_call_participant_id(request.participant_id_),
|
||||
request.is_muted_, std::move(promise));
|
||||
GroupCallId(request.group_call_id_), participant_dialog_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();
|
||||
TRY_RESULT_PROMISE(promise, participant_dialog_id,
|
||||
get_message_sender_dialog_id(this, request.participant_id_, true, false));
|
||||
group_call_manager_->set_group_call_participant_volume_level(
|
||||
GroupCallId(request.group_call_id_), group_call_manager_->get_group_call_participant_id(request.participant_id_),
|
||||
request.volume_level_, std::move(promise));
|
||||
GroupCallId(request.group_call_id_), participant_dialog_id, request.volume_level_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::toggleGroupCallParticipantIsHandRaised &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
TRY_RESULT_PROMISE(promise, participant_dialog_id,
|
||||
get_message_sender_dialog_id(this, request.participant_id_, true, false));
|
||||
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_id_),
|
||||
request.is_hand_raised_, std::move(promise));
|
||||
GroupCallId(request.group_call_id_), participant_dialog_id, request.is_hand_raised_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::loadGroupCallParticipants &request) {
|
||||
@ -6248,14 +6253,16 @@ void Td::on_request(uint64 id, const td_api::addChatMembers &request) {
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::setChatMemberStatus &request) {
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
TRY_RESULT_PROMISE(promise, participant_dialog_id, get_message_sender_dialog_id(request.member_id_));
|
||||
TRY_RESULT_PROMISE(promise, participant_dialog_id,
|
||||
get_message_sender_dialog_id(this, request.member_id_, false, false));
|
||||
contacts_manager_->set_dialog_participant_status(DialogId(request.chat_id_), participant_dialog_id, request.status_,
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::banChatMember &request) {
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
TRY_RESULT_PROMISE(promise, participant_dialog_id, get_message_sender_dialog_id(request.member_id_));
|
||||
TRY_RESULT_PROMISE(promise, participant_dialog_id,
|
||||
get_message_sender_dialog_id(this, request.member_id_, false, false));
|
||||
contacts_manager_->ban_dialog_participant(DialogId(request.chat_id_), participant_dialog_id,
|
||||
request.banned_until_date_, request.revoke_messages_, std::move(promise));
|
||||
}
|
||||
@ -6284,7 +6291,8 @@ void Td::on_request(uint64 id, td_api::transferChatOwnership &request) {
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getChatMember &request) {
|
||||
CREATE_REQUEST_PROMISE();
|
||||
TRY_RESULT_PROMISE(promise, participant_dialog_id, get_message_sender_dialog_id(request.member_id_));
|
||||
TRY_RESULT_PROMISE(promise, participant_dialog_id,
|
||||
get_message_sender_dialog_id(this, request.member_id_, false, false));
|
||||
contacts_manager_->get_dialog_participant(DialogId(request.chat_id_), participant_dialog_id, std::move(promise));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user