Add MessagesManager::check_dialog_access.
This commit is contained in:
parent
be7434dbf3
commit
c4e1a44a5c
@ -273,8 +273,8 @@ void CallbackQueriesManager::send_get_callback_answer_query(
|
||||
TRY_STATUS_PROMISE(promise, G()->close_status());
|
||||
|
||||
auto dialog_id = message_full_id.get_dialog_id();
|
||||
TRY_STATUS_PROMISE(promise, td_->dialog_manager_->check_dialog_access(dialog_id, false, AccessRights::Read,
|
||||
"send_get_callback_answer_query"));
|
||||
TRY_STATUS_PROMISE(promise,
|
||||
td_->dialog_manager_->check_dialog_access_in_memory(dialog_id, false, AccessRights::Read));
|
||||
if (!td_->messages_manager_->have_message_force(message_full_id, "send_get_callback_answer_query")) {
|
||||
return promise.set_error(Status::Error(400, "Message not found"));
|
||||
}
|
||||
|
@ -574,6 +574,11 @@ Status DialogManager::check_dialog_access(DialogId dialog_id, bool allow_secret_
|
||||
}
|
||||
return Status::Error(400, "Chat not found");
|
||||
}
|
||||
return check_dialog_access_in_memory(dialog_id, allow_secret_chats, access_rights);
|
||||
}
|
||||
|
||||
Status DialogManager::check_dialog_access_in_memory(DialogId dialog_id, bool allow_secret_chats,
|
||||
AccessRights access_rights) const {
|
||||
if (!have_input_peer(dialog_id, allow_secret_chats, access_rights)) {
|
||||
if (dialog_id.get_type() == DialogType::SecretChat && !allow_secret_chats) {
|
||||
return Status::Error(400, "Not supported in secret chats");
|
||||
|
@ -75,6 +75,8 @@ class DialogManager final : public Actor {
|
||||
Status check_dialog_access(DialogId dialog_id, bool allow_secret_chats, AccessRights access_rights,
|
||||
const char *source) const;
|
||||
|
||||
Status check_dialog_access_in_memory(DialogId dialog_id, bool allow_secret_chats, AccessRights access_rights) const;
|
||||
|
||||
bool have_input_peer(DialogId dialog_id, bool allow_secret_chats, AccessRights access_rights) const;
|
||||
|
||||
bool have_dialog_force(DialogId dialog_id, const char *source) const;
|
||||
|
@ -6,7 +6,6 @@
|
||||
//
|
||||
#include "td/telegram/MessagesManager.h"
|
||||
|
||||
#include "td/telegram/AccessRights.h"
|
||||
#include "td/telegram/AccountManager.h"
|
||||
#include "td/telegram/AuthManager.h"
|
||||
#include "td/telegram/BackgroundInfo.hpp"
|
||||
@ -35827,6 +35826,19 @@ MessagesManager::Dialog *MessagesManager::on_load_dialog_from_database(DialogId
|
||||
return add_new_dialog(parse_dialog(dialog_id, value, source), true, source);
|
||||
}
|
||||
|
||||
Result<MessagesManager::Dialog *> MessagesManager::check_dialog_access(DialogId dialog_id, bool allow_secret_chats,
|
||||
AccessRights access_rights, const char *source) {
|
||||
auto *d = get_dialog_force(dialog_id, source);
|
||||
if (d == nullptr) {
|
||||
if (!dialog_id.is_valid()) {
|
||||
return Status::Error(400, "Invalid chat identifier specified");
|
||||
}
|
||||
return Status::Error(400, "Chat not found");
|
||||
}
|
||||
TRY_STATUS(td_->dialog_manager_->check_dialog_access_in_memory(dialog_id, allow_secret_chats, access_rights));
|
||||
return d;
|
||||
}
|
||||
|
||||
vector<FolderId> MessagesManager::get_dialog_list_folder_ids(const DialogList &list) const {
|
||||
CHECK(!td_->auth_manager_->is_bot());
|
||||
if (list.dialog_list_id.is_folder()) {
|
||||
|
@ -6,6 +6,7 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/AccessRights.h"
|
||||
#include "td/telegram/AffectedHistory.h"
|
||||
#include "td/telegram/BackgroundInfo.h"
|
||||
#include "td/telegram/ChannelId.h"
|
||||
@ -2646,6 +2647,9 @@ class MessagesManager final : public Actor {
|
||||
void on_get_dialogs_from_database(FolderId folder_id, int32 limit, DialogDbGetDialogsResult &&dialogs,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
Result<Dialog *> check_dialog_access(DialogId dialog_id, bool allow_secret_chats, AccessRights access_rights,
|
||||
const char *source);
|
||||
|
||||
void send_get_dialog_query(DialogId dialog_id, Promise<Unit> &&promise, uint64 log_event_id, const char *source);
|
||||
|
||||
void send_search_public_dialogs_query(const string &query, Promise<Unit> &&promise);
|
||||
|
Loading…
Reference in New Issue
Block a user