Use get_input_user instead of have_input_user.
This commit is contained in:
parent
ac8e856269
commit
0375704460
@ -54,12 +54,7 @@ Result<BotCommandScope> BotCommandScope::get_bot_command_scope(Td *td,
|
||||
type = Type::DialogParticipant;
|
||||
dialog_id = DialogId(scope->chat_id_);
|
||||
user_id = UserId(scope->user_id_);
|
||||
if (!user_id.is_valid()) {
|
||||
return Status::Error(400, "User not found");
|
||||
}
|
||||
if (!td->contacts_manager_->have_input_user(user_id)) {
|
||||
return Status::Error(400, "Can't access the user");
|
||||
}
|
||||
TRY_STATUS(td->contacts_manager_->get_input_user(user_id));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -100,9 +95,8 @@ telegram_api::object_ptr<telegram_api::BotCommandScope> BotCommandScope::get_inp
|
||||
const Td *td) const {
|
||||
auto input_peer =
|
||||
dialog_id_.is_valid() ? td->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read) : nullptr;
|
||||
auto input_user = td->contacts_manager_->have_input_user(user_id_)
|
||||
? td->contacts_manager_->get_input_user(user_id_).move_as_ok()
|
||||
: nullptr;
|
||||
auto r_input_user = td->contacts_manager_->get_input_user(user_id_);
|
||||
auto input_user = r_input_user.is_ok() ? r_input_user.move_as_ok() : nullptr;
|
||||
switch (type_) {
|
||||
case Type::Default:
|
||||
return telegram_api::make_object<telegram_api::botCommandScopeDefault>();
|
||||
|
@ -1471,7 +1471,7 @@ class GetExportedChatInvitesQuery final : public Td::ResultHandler {
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(DialogId dialog_id, UserId creator_user_id, bool is_revoked, int32 offset_date,
|
||||
void send(DialogId dialog_id, tl_object_ptr<telegram_api::InputUser> &&input_user, bool is_revoked, int32 offset_date,
|
||||
const string &offset_invite_link, int32 limit) {
|
||||
dialog_id_ = dialog_id;
|
||||
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
@ -1479,9 +1479,6 @@ class GetExportedChatInvitesQuery final : public Td::ResultHandler {
|
||||
return on_error(Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
|
||||
auto r_input_user = td_->contacts_manager_->get_input_user(creator_user_id);
|
||||
CHECK(r_input_user.is_ok());
|
||||
|
||||
int32 flags = 0;
|
||||
if (!offset_invite_link.empty() || offset_date != 0) {
|
||||
flags |= telegram_api::messages_getExportedChatInvites::OFFSET_DATE_MASK;
|
||||
@ -1490,9 +1487,9 @@ class GetExportedChatInvitesQuery final : public Td::ResultHandler {
|
||||
if (is_revoked) {
|
||||
flags |= telegram_api::messages_getExportedChatInvites::REVOKED_MASK;
|
||||
}
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_getExportedChatInvites(
|
||||
flags, false /*ignored*/, std::move(input_peer), r_input_user.move_as_ok(), offset_date, offset_invite_link,
|
||||
limit)));
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::messages_getExportedChatInvites(flags, false /*ignored*/, std::move(input_peer),
|
||||
std::move(input_user), offset_date, offset_invite_link, limit)));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
@ -1934,18 +1931,15 @@ class DeleteRevokedExportedChatInvitesQuery final : public Td::ResultHandler {
|
||||
explicit DeleteRevokedExportedChatInvitesQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(DialogId dialog_id, UserId creator_user_id) {
|
||||
void send(DialogId dialog_id, tl_object_ptr<telegram_api::InputUser> &&input_user) {
|
||||
dialog_id_ = dialog_id;
|
||||
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
if (input_peer == nullptr) {
|
||||
return on_error(Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
|
||||
auto r_input_user = td_->contacts_manager_->get_input_user(creator_user_id);
|
||||
CHECK(r_input_user.is_ok());
|
||||
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::messages_deleteRevokedExportedChatInvites(std::move(input_peer), r_input_user.move_as_ok())));
|
||||
telegram_api::messages_deleteRevokedExportedChatInvites(std::move(input_peer), std::move(input_user))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
@ -4445,22 +4439,6 @@ Result<tl_object_ptr<telegram_api::InputUser>> ContactsManager::get_input_user(U
|
||||
return make_tl_object<telegram_api::inputUser>(user_id.get(), u->access_hash);
|
||||
}
|
||||
|
||||
bool ContactsManager::have_input_user(UserId user_id) const {
|
||||
if (user_id == get_my_id()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const User *u = get_user(user_id);
|
||||
if (u == nullptr || u->access_hash == -1 || u->is_min_access_hash) {
|
||||
if (td_->auth_manager_->is_bot() && user_id.is_valid()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
tl_object_ptr<telegram_api::InputChannel> ContactsManager::get_input_channel(ChannelId channel_id) const {
|
||||
const Channel *c = get_channel(channel_id);
|
||||
if (c == nullptr) {
|
||||
@ -7432,17 +7410,14 @@ void ContactsManager::get_dialog_invite_links(DialogId dialog_id, UserId creator
|
||||
int32 offset_date, const string &offset_invite_link, int32 limit,
|
||||
Promise<td_api::object_ptr<td_api::chatInviteLinks>> &&promise) {
|
||||
TRY_STATUS_PROMISE(promise, can_manage_dialog_invite_links(dialog_id, creator_user_id != get_my_id()));
|
||||
|
||||
if (!have_input_user(creator_user_id)) {
|
||||
return promise.set_error(Status::Error(400, "Administrator user not found"));
|
||||
}
|
||||
TRY_RESULT_PROMISE(promise, input_user, get_input_user(creator_user_id));
|
||||
|
||||
if (limit <= 0) {
|
||||
return promise.set_error(Status::Error(400, "Parameter limit must be positive"));
|
||||
}
|
||||
|
||||
td_->create_handler<GetExportedChatInvitesQuery>(std::move(promise))
|
||||
->send(dialog_id, creator_user_id, is_revoked, offset_date, offset_invite_link, limit);
|
||||
->send(dialog_id, std::move(input_user), is_revoked, offset_date, offset_invite_link, limit);
|
||||
}
|
||||
|
||||
void ContactsManager::get_dialog_invite_link_users(
|
||||
@ -7526,12 +7501,10 @@ void ContactsManager::delete_revoked_dialog_invite_link(DialogId dialog_id, cons
|
||||
void ContactsManager::delete_all_revoked_dialog_invite_links(DialogId dialog_id, UserId creator_user_id,
|
||||
Promise<Unit> &&promise) {
|
||||
TRY_STATUS_PROMISE(promise, can_manage_dialog_invite_links(dialog_id, creator_user_id != get_my_id()));
|
||||
TRY_RESULT_PROMISE(promise, input_user, get_input_user(creator_user_id));
|
||||
|
||||
if (!have_input_user(creator_user_id)) {
|
||||
return promise.set_error(Status::Error(400, "Administrator user not found"));
|
||||
}
|
||||
|
||||
td_->create_handler<DeleteRevokedExportedChatInvitesQuery>(std::move(promise))->send(dialog_id, creator_user_id);
|
||||
td_->create_handler<DeleteRevokedExportedChatInvitesQuery>(std::move(promise))
|
||||
->send(dialog_id, std::move(input_user));
|
||||
}
|
||||
|
||||
void ContactsManager::check_dialog_invite_link(const string &invite_link, bool force, Promise<Unit> &&promise) {
|
||||
|
@ -78,7 +78,6 @@ class ContactsManager final : public Actor {
|
||||
static ChannelId get_channel_id(const tl_object_ptr<telegram_api::Chat> &chat);
|
||||
|
||||
Result<tl_object_ptr<telegram_api::InputUser>> get_input_user(UserId user_id) const;
|
||||
bool have_input_user(UserId user_id) const;
|
||||
|
||||
// TODO get_input_chat ???
|
||||
|
||||
|
@ -120,9 +120,7 @@ Result<Game> process_input_message_game(const ContactsManager *contacts_manager,
|
||||
auto input_message_game = move_tl_object_as<td_api::inputMessageGame>(input_message_content);
|
||||
|
||||
UserId bot_user_id(input_message_game->bot_user_id_);
|
||||
if (!contacts_manager->have_input_user(bot_user_id)) {
|
||||
return Status::Error(400, "Game owner bot is not accessible");
|
||||
}
|
||||
TRY_STATUS(contacts_manager->get_input_user(bot_user_id));
|
||||
|
||||
if (!clean_input_string(input_message_game->game_short_name_)) {
|
||||
return Status::Error(400, "Game short name must be encoded in UTF-8");
|
||||
|
@ -3276,8 +3276,8 @@ Result<vector<MessageEntity>> get_message_entities(const ContactsManager *contac
|
||||
}
|
||||
auto user_id = LinkManager::get_link_user_id(entity->url_);
|
||||
if (user_id.is_valid()) {
|
||||
if (contacts_manager != nullptr && !contacts_manager->have_input_user(user_id)) {
|
||||
return Status::Error(400, "Have no access to the user");
|
||||
if (contacts_manager != nullptr) {
|
||||
TRY_STATUS(contacts_manager->get_input_user(user_id));
|
||||
}
|
||||
entities.emplace_back(offset, length, user_id);
|
||||
break;
|
||||
@ -3292,8 +3292,8 @@ Result<vector<MessageEntity>> get_message_entities(const ContactsManager *contac
|
||||
case td_api::textEntityTypeMentionName::ID: {
|
||||
auto entity = static_cast<td_api::textEntityTypeMentionName *>(input_entity->type_.get());
|
||||
UserId user_id(entity->user_id_);
|
||||
if (contacts_manager != nullptr && !contacts_manager->have_input_user(user_id)) {
|
||||
return Status::Error(400, "Have no access to the user");
|
||||
if (contacts_manager != nullptr) {
|
||||
TRY_STATUS(contacts_manager->get_input_user(user_id));
|
||||
}
|
||||
entities.emplace_back(offset, length, user_id);
|
||||
break;
|
||||
@ -3432,12 +3432,13 @@ vector<MessageEntity> get_message_entities(const ContactsManager *contacts_manag
|
||||
LOG(ERROR) << "Receive invalid " << user_id << " in MentionName from " << source;
|
||||
continue;
|
||||
}
|
||||
if (contacts_manager == nullptr || !contacts_manager->have_user(user_id)) {
|
||||
if (contacts_manager == nullptr) {
|
||||
LOG(ERROR) << "Receive unknown " << user_id << " in MentionName from " << source;
|
||||
continue;
|
||||
}
|
||||
if (!contacts_manager->have_input_user(user_id)) {
|
||||
LOG(ERROR) << "Receive inaccessible " << user_id << " in MentionName from " << source;
|
||||
auto r_input_user = contacts_manager->get_input_user(user_id);
|
||||
if (r_input_user.is_error()) {
|
||||
LOG(ERROR) << "Receive wrong " << user_id << ": " << r_input_user.error() << " from " << source;
|
||||
continue;
|
||||
}
|
||||
entities.emplace_back(entity->offset_, entity->length_, user_id);
|
||||
|
@ -880,15 +880,12 @@ class GetCommonDialogsQuery final : public Td::ResultHandler {
|
||||
explicit GetCommonDialogsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(UserId user_id, int64 offset_chat_id, int32 limit) {
|
||||
void send(UserId user_id, tl_object_ptr<telegram_api::InputUser> &&input_user, int64 offset_chat_id, int32 limit) {
|
||||
user_id_ = user_id;
|
||||
offset_chat_id_ = offset_chat_id;
|
||||
|
||||
auto r_input_user = td_->contacts_manager_->get_input_user(user_id);
|
||||
CHECK(r_input_user.is_ok());
|
||||
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::messages_getCommonChats(r_input_user.move_as_ok(), offset_chat_id, limit)));
|
||||
telegram_api::messages_getCommonChats(std::move(input_user), offset_chat_id, limit)));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
@ -17717,8 +17714,9 @@ void MessagesManager::drop_common_dialogs_cache(UserId user_id) {
|
||||
std::pair<int32, vector<DialogId>> MessagesManager::get_common_dialogs(UserId user_id, DialogId offset_dialog_id,
|
||||
int32 limit, bool force,
|
||||
Promise<Unit> &&promise) {
|
||||
if (!td_->contacts_manager_->have_input_user(user_id)) {
|
||||
promise.set_error(Status::Error(400, "Have no access to the user"));
|
||||
auto r_input_user = td_->contacts_manager_->get_input_user(user_id);
|
||||
if (r_input_user.is_error()) {
|
||||
promise.set_error(r_input_user.move_as_error());
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -17792,7 +17790,8 @@ std::pair<int32, vector<DialogId>> MessagesManager::get_common_dialogs(UserId us
|
||||
}
|
||||
}
|
||||
|
||||
td_->create_handler<GetCommonDialogsQuery>(std::move(promise))->send(user_id, offset_chat_id, MAX_GET_DIALOGS);
|
||||
td_->create_handler<GetCommonDialogsQuery>(std::move(promise))
|
||||
->send(user_id, r_input_user.move_as_ok(), offset_chat_id, MAX_GET_DIALOGS);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -530,7 +530,7 @@ bool UpdatesManager::is_acceptable_message_entities(
|
||||
if (entity->get_id() == telegram_api::messageEntityMentionName::ID) {
|
||||
auto entity_mention_name = static_cast<const telegram_api::messageEntityMentionName *>(entity.get());
|
||||
UserId user_id(entity_mention_name->user_id_);
|
||||
if (!is_acceptable_user(user_id) || !td_->contacts_manager_->have_input_user(user_id)) {
|
||||
if (!is_acceptable_user(user_id) || td_->contacts_manager_->get_input_user(user_id).is_error()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -547,7 +547,7 @@ bool UpdatesManager::is_acceptable_reply_markup(const tl_object_ptr<telegram_api
|
||||
if (button->get_id() == telegram_api::keyboardButtonUserProfile::ID) {
|
||||
auto user_profile_button = static_cast<const telegram_api::keyboardButtonUserProfile *>(button.get());
|
||||
UserId user_id(user_profile_button->user_id_);
|
||||
if (!is_acceptable_user(user_id) || !td_->contacts_manager_->have_input_user(user_id)) {
|
||||
if (!is_acceptable_user(user_id) || td_->contacts_manager_->get_input_user(user_id).is_error()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user