From e4942d9cf7de37851336b3b952a06d3afdbf2e38 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 22 Mar 2023 15:36:45 +0300 Subject: [PATCH] Add GroupCallManager::can_join_group_calls. --- td/telegram/GroupCallManager.cpp | 45 +++++++++++++++++++------------- td/telegram/GroupCallManager.h | 2 ++ 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index 5769cda34..d617cb9c4 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -1217,6 +1217,31 @@ GroupCallManager::GroupCall *GroupCallManager::get_group_call(InputGroupCallId i } } +Status GroupCallManager::can_join_group_calls(DialogId dialog_id) const { + if (!dialog_id.is_valid()) { + return Status::Error(400, "Invalid chat identifier specified"); + } + if (!td_->messages_manager_->have_dialog_force(dialog_id, "get_group_call_join_as")) { + return Status::Error(400, "Chat not found"); + } + if (!td_->messages_manager_->have_input_peer(dialog_id, AccessRights::Read)) { + return Status::Error(400, "Can't access chat"); + } + switch (dialog_id.get_type()) { + case DialogType::Chat: + case DialogType::Channel: + break; + case DialogType::User: + case DialogType::SecretChat: + return Status::Error(400, "Chat can't have a voice chat"); + case DialogType::None: + default: + UNREACHABLE(); + break; + } + return Status::OK(); +} + Status GroupCallManager::can_manage_group_calls(DialogId dialog_id) const { switch (dialog_id.get_type()) { case DialogType::Chat: { @@ -1267,30 +1292,14 @@ bool GroupCallManager::get_group_call_joined_date_asc(InputGroupCallId input_gro void GroupCallManager::get_group_call_join_as(DialogId dialog_id, Promise> &&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, "get_group_call_join_as")) { - 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")); - } + TRY_STATUS_PROMISE(promise, can_join_group_calls(dialog_id)); td_->create_handler(std::move(promise))->send(dialog_id); } void GroupCallManager::set_group_call_default_join_as(DialogId dialog_id, DialogId as_dialog_id, Promise &&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, "set_group_call_default_join_as")) { - 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")); - } + TRY_STATUS_PROMISE(promise, can_join_group_calls(dialog_id)); switch (as_dialog_id.get_type()) { case DialogType::User: diff --git a/td/telegram/GroupCallManager.h b/td/telegram/GroupCallManager.h index 9307c9b1f..a08379561 100644 --- a/td/telegram/GroupCallManager.h +++ b/td/telegram/GroupCallManager.h @@ -188,6 +188,8 @@ class GroupCallManager final : public Actor { const GroupCall *get_group_call(InputGroupCallId input_group_call_id) const; GroupCall *get_group_call(InputGroupCallId input_group_call_id); + Status can_join_group_calls(DialogId dialog_id) const; + Status can_manage_group_calls(DialogId dialog_id) const; bool can_manage_group_call(InputGroupCallId input_group_call_id) const;