More check_dialog_access usages.
This commit is contained in:
parent
3477fb715e
commit
b04e7fc89e
@ -77,12 +77,7 @@ class SaveAutoSaveSettingsQuery final : public Td::ResultHandler {
|
||||
} else {
|
||||
flags |= telegram_api::account_saveAutoSaveSettings::PEER_MASK;
|
||||
input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Read);
|
||||
if (input_peer == nullptr) {
|
||||
if (dialog_id.get_type() == DialogType::SecretChat) {
|
||||
return on_error(Status::Error(400, "Can't set autosave settings for secret chats"));
|
||||
}
|
||||
return on_error(Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
CHECK(input_peer != nullptr);
|
||||
}
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::account_saveAutoSaveSettings(flags, false /*ignored*/, false /*ignored*/, false /*ignored*/,
|
||||
@ -483,9 +478,8 @@ void AutosaveManager::set_autosave_settings(td_api::object_ptr<td_api::AutosaveS
|
||||
break;
|
||||
case td_api::autosaveSettingsScopeChat::ID:
|
||||
dialog_id = DialogId(static_cast<const td_api::autosaveSettingsScopeChat *>(scope.get())->chat_id_);
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "set_autosave_settings")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
TRY_STATUS_PROMISE(promise, td_->dialog_manager_->check_dialog_access(dialog_id, false, AccessRights::Read,
|
||||
"set_autosave_settings"));
|
||||
old_settings = &settings_.exceptions_[dialog_id];
|
||||
break;
|
||||
default:
|
||||
|
@ -126,9 +126,7 @@ class ToggleConnectedBotPausedQuery final : public Td::ResultHandler {
|
||||
void send(DialogId dialog_id, bool is_paused) {
|
||||
dialog_id_ = dialog_id;
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
if (input_peer == nullptr) {
|
||||
return on_error(Status::Error(400, "Have no write access to the chat"));
|
||||
}
|
||||
CHECK(input_peer != nullptr);
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::account_toggleConnectedBotPaused(std::move(input_peer), is_paused), {{"me"}, {dialog_id}}));
|
||||
}
|
||||
@ -162,9 +160,7 @@ class DisablePeerConnectedBotQuery final : public Td::ResultHandler {
|
||||
void send(DialogId dialog_id) {
|
||||
dialog_id_ = dialog_id;
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
if (input_peer == nullptr) {
|
||||
return on_error(Status::Error(400, "Have no write access to the chat"));
|
||||
}
|
||||
CHECK(input_peer != nullptr);
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_disablePeerConnectedBot(std::move(input_peer)),
|
||||
{{"me"}, {dialog_id}}));
|
||||
}
|
||||
@ -329,7 +325,8 @@ class ResolveBusinessChatLinkQuery final : public Td::ResultHandler {
|
||||
td_->user_manager_->on_get_users(std::move(ptr->users_), "ResolveBusinessChatLinkQuery");
|
||||
td_->chat_manager_->on_get_chats(std::move(ptr->chats_), "ResolveBusinessChatLinkQuery");
|
||||
|
||||
auto text = get_message_text(td_->user_manager_.get(), std::move(ptr->message_), std::move(ptr->entities_), true, true, 0, false, "ResolveBusinessChatLinkQuery");
|
||||
auto text = get_message_text(td_->user_manager_.get(), std::move(ptr->message_), std::move(ptr->entities_), true,
|
||||
true, 0, false, "ResolveBusinessChatLinkQuery");
|
||||
if (text.text[0] == '@') {
|
||||
text.text = ' ' + text.text;
|
||||
for (auto &entity : text.entities) {
|
||||
@ -559,9 +556,9 @@ void BusinessManager::delete_business_connected_bot(UserId bot_user_id, Promise<
|
||||
|
||||
void BusinessManager::toggle_business_connected_bot_dialog_is_paused(DialogId dialog_id, bool is_paused,
|
||||
Promise<Unit> &&promise) {
|
||||
if (!td_->messages_manager_->have_dialog_force(dialog_id, "toggle_business_connected_bot_dialog_is_paused")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
TRY_STATUS_PROMISE(promise,
|
||||
td_->dialog_manager_->check_dialog_access(dialog_id, false, AccessRights::Write,
|
||||
"toggle_business_connected_bot_dialog_is_paused"));
|
||||
if (dialog_id.get_type() != DialogType::User) {
|
||||
return promise.set_error(Status::Error(400, "The chat has no connected bot"));
|
||||
}
|
||||
@ -570,9 +567,8 @@ void BusinessManager::toggle_business_connected_bot_dialog_is_paused(DialogId di
|
||||
}
|
||||
|
||||
void BusinessManager::remove_business_connected_bot_from_dialog(DialogId dialog_id, Promise<Unit> &&promise) {
|
||||
if (!td_->messages_manager_->have_dialog_force(dialog_id, "remove_business_connected_bot_from_dialog")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
TRY_STATUS_PROMISE(promise, td_->dialog_manager_->check_dialog_access(dialog_id, false, AccessRights::Write,
|
||||
"remove_business_connected_bot_from_dialog"));
|
||||
if (dialog_id.get_type() != DialogType::User) {
|
||||
return promise.set_error(Status::Error(400, "The chat has no connected bot"));
|
||||
}
|
||||
|
@ -114,9 +114,7 @@ class ExportChatInviteQuery final : public Td::ResultHandler {
|
||||
bool is_permanent) {
|
||||
dialog_id_ = dialog_id;
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
if (input_peer == nullptr) {
|
||||
return on_error(Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
int32 flags = 0;
|
||||
if (expire_date > 0) {
|
||||
@ -180,9 +178,7 @@ class EditChatInviteLinkQuery final : public Td::ResultHandler {
|
||||
bool creates_join_request) {
|
||||
dialog_id_ = dialog_id;
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
if (input_peer == nullptr) {
|
||||
return on_error(Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
int32 flags = telegram_api::messages_editExportedChatInvite::EXPIRE_DATE_MASK |
|
||||
telegram_api::messages_editExportedChatInvite::USAGE_LIMIT_MASK |
|
||||
@ -235,9 +231,7 @@ class GetExportedChatInviteQuery final : public Td::ResultHandler {
|
||||
void send(DialogId dialog_id, const string &invite_link) {
|
||||
dialog_id_ = dialog_id;
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
if (input_peer == nullptr) {
|
||||
return on_error(Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::messages_getExportedChatInvite(std::move(input_peer), invite_link)));
|
||||
@ -286,9 +280,7 @@ class GetExportedChatInvitesQuery final : public Td::ResultHandler {
|
||||
const string &offset_invite_link, int32 limit) {
|
||||
dialog_id_ = dialog_id;
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
if (input_peer == nullptr) {
|
||||
return on_error(Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
int32 flags = 0;
|
||||
if (!offset_invite_link.empty() || offset_date != 0) {
|
||||
@ -350,9 +342,7 @@ class GetChatAdminWithInvitesQuery final : public Td::ResultHandler {
|
||||
void send(DialogId dialog_id) {
|
||||
dialog_id_ = dialog_id;
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
if (input_peer == nullptr) {
|
||||
return on_error(Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_getAdminsWithInvites(std::move(input_peer))));
|
||||
}
|
||||
@ -400,9 +390,7 @@ class GetChatInviteImportersQuery final : public Td::ResultHandler {
|
||||
void send(DialogId dialog_id, const string &invite_link, int32 offset_date, UserId offset_user_id, int32 limit) {
|
||||
dialog_id_ = dialog_id;
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
if (input_peer == nullptr) {
|
||||
return on_error(Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
auto r_input_user = td_->user_manager_->get_input_user(offset_user_id);
|
||||
if (r_input_user.is_error()) {
|
||||
@ -466,9 +454,7 @@ class RevokeChatInviteLinkQuery final : public Td::ResultHandler {
|
||||
void send(DialogId dialog_id, const string &invite_link) {
|
||||
dialog_id_ = dialog_id;
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
if (input_peer == nullptr) {
|
||||
return on_error(Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
int32 flags = telegram_api::messages_editExportedChatInvite::REVOKED_MASK;
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_editExportedChatInvite(
|
||||
@ -541,9 +527,7 @@ class DeleteExportedChatInviteQuery final : public Td::ResultHandler {
|
||||
void send(DialogId dialog_id, const string &invite_link) {
|
||||
dialog_id_ = dialog_id;
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
if (input_peer == nullptr) {
|
||||
return on_error(Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::messages_deleteExportedChatInvite(std::move(input_peer), invite_link)));
|
||||
@ -575,9 +559,7 @@ class DeleteRevokedExportedChatInvitesQuery final : public Td::ResultHandler {
|
||||
void send(DialogId dialog_id, tl_object_ptr<telegram_api::InputUser> &&input_user) {
|
||||
dialog_id_ = dialog_id;
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
if (input_peer == nullptr) {
|
||||
return on_error(Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::messages_deleteRevokedExportedChatInvites(std::move(input_peer), std::move(input_user))));
|
||||
@ -923,9 +905,8 @@ void DialogInviteLinkManager::remove_dialog_access_by_invite_link(DialogId dialo
|
||||
}
|
||||
|
||||
Status DialogInviteLinkManager::can_manage_dialog_invite_links(DialogId dialog_id, bool creator_only) {
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "can_manage_dialog_invite_links")) {
|
||||
return Status::Error(400, "Chat not found");
|
||||
}
|
||||
TRY_STATUS(td_->dialog_manager_->check_dialog_access(dialog_id, false, AccessRights::Write,
|
||||
"can_manage_dialog_invite_links"));
|
||||
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User:
|
||||
|
@ -97,9 +97,7 @@ class GetChatJoinRequestsQuery final : public Td::ResultHandler {
|
||||
invite_link.empty() && query.empty() && offset_date == 0 && !offset_user_id.is_valid() && limit >= 3;
|
||||
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
if (input_peer == nullptr) {
|
||||
return on_error(Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
auto r_input_user = td_->user_manager_->get_input_user(offset_user_id);
|
||||
if (r_input_user.is_error()) {
|
||||
@ -174,9 +172,7 @@ class HideChatJoinRequestQuery final : public Td::ResultHandler {
|
||||
void send(DialogId dialog_id, UserId user_id, bool approve) {
|
||||
dialog_id_ = dialog_id;
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
if (input_peer == nullptr) {
|
||||
return on_error(Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
TRY_RESULT_PROMISE(promise_, input_user, td_->user_manager_->get_input_user(user_id));
|
||||
|
||||
@ -216,9 +212,7 @@ class HideAllChatJoinRequestsQuery final : public Td::ResultHandler {
|
||||
void send(DialogId dialog_id, const string &invite_link, bool approve) {
|
||||
dialog_id_ = dialog_id;
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
if (input_peer == nullptr) {
|
||||
return on_error(Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
int32 flags = 0;
|
||||
if (approve) {
|
||||
@ -1063,9 +1057,8 @@ void DialogParticipantManager::update_dialog_online_member_count(const vector<Di
|
||||
}
|
||||
|
||||
Status DialogParticipantManager::can_manage_dialog_join_requests(DialogId dialog_id) {
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "can_manage_dialog_join_requests")) {
|
||||
return Status::Error(400, "Chat not found");
|
||||
}
|
||||
TRY_STATUS(td_->dialog_manager_->check_dialog_access(dialog_id, false, AccessRights::Write,
|
||||
"can_manage_dialog_join_requests"));
|
||||
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::SecretChat:
|
||||
|
@ -683,9 +683,8 @@ void StatisticsManager::send_get_channel_stats_query(DcId dc_id, ChannelId chann
|
||||
|
||||
void StatisticsManager::get_channel_revenue_statistics(
|
||||
DialogId dialog_id, bool is_dark, Promise<td_api::object_ptr<td_api::chatRevenueStatistics>> &&promise) {
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "get_channel_revenue_statistics")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
TRY_STATUS_PROMISE(promise, td_->dialog_manager_->check_dialog_access(dialog_id, false, AccessRights::Write,
|
||||
"get_channel_revenue_statistics"));
|
||||
if (!td_->dialog_manager_->is_broadcast_channel(dialog_id)) {
|
||||
return promise.set_error(Status::Error(400, "Chat is not a channel"));
|
||||
}
|
||||
@ -694,9 +693,8 @@ void StatisticsManager::get_channel_revenue_statistics(
|
||||
|
||||
void StatisticsManager::get_channel_revenue_withdrawal_url(DialogId dialog_id, const string &password,
|
||||
Promise<string> &&promise) {
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "get_channel_revenue_withdrawal_url")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
TRY_STATUS_PROMISE(promise, td_->dialog_manager_->check_dialog_access(dialog_id, false, AccessRights::Write,
|
||||
"get_channel_revenue_withdrawal_url"));
|
||||
if (!td_->dialog_manager_->is_broadcast_channel(dialog_id)) {
|
||||
return promise.set_error(Status::Error(400, "Chat is not a channel"));
|
||||
}
|
||||
@ -731,9 +729,8 @@ void StatisticsManager::send_get_channel_revenue_withdrawal_url_query(
|
||||
void StatisticsManager::get_channel_revenue_transactions(
|
||||
DialogId dialog_id, int32 offset, int32 limit,
|
||||
Promise<td_api::object_ptr<td_api::chatRevenueTransactions>> &&promise) {
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "get_channel_revenue_transactions")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
TRY_STATUS_PROMISE(promise, td_->dialog_manager_->check_dialog_access(dialog_id, false, AccessRights::Write,
|
||||
"get_channel_revenue_transactions"));
|
||||
if (!td_->dialog_manager_->is_broadcast_channel(dialog_id)) {
|
||||
return promise.set_error(Status::Error(400, "Chat is not a channel"));
|
||||
}
|
||||
|
@ -103,12 +103,10 @@ class ResetTopPeerRatingQuery final : public Td::ResultHandler {
|
||||
|
||||
public:
|
||||
void send(TopDialogCategory category, DialogId dialog_id) {
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Read);
|
||||
if (input_peer == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
dialog_id_ = dialog_id;
|
||||
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Read);
|
||||
CHECK(input_peer != nullptr);
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::contacts_resetTopPeerRating(get_input_top_peer_category(category), std::move(input_peer))));
|
||||
}
|
||||
@ -240,9 +238,8 @@ void TopDialogManager::remove_dialog(TopDialogCategory category, DialogId dialog
|
||||
if (category == TopDialogCategory::Size) {
|
||||
return promise.set_error(Status::Error(400, "Top chat category must be non-empty"));
|
||||
}
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "remove_dialog")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
TRY_STATUS_PROMISE(promise,
|
||||
td_->dialog_manager_->check_dialog_access(dialog_id, false, AccessRights::Read, "remove_dialog"));
|
||||
CHECK(!td_->auth_manager_->is_bot());
|
||||
if (!is_enabled_) {
|
||||
return promise.set_value(Unit());
|
||||
|
Loading…
x
Reference in New Issue
Block a user