Return Result<...> from get_input_user.

This commit is contained in:
levlam 2021-12-16 22:46:03 +03:00
parent cfc254e9b1
commit b060536ae3
14 changed files with 195 additions and 212 deletions

View File

@ -100,7 +100,9 @@ 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 = user_id_.is_valid() ? td->contacts_manager_->get_input_user(user_id_) : nullptr;
auto input_user = td->contacts_manager_->have_input_user(user_id_)
? td->contacts_manager_->get_input_user(user_id_).move_as_ok()
: nullptr;
switch (type_) {
case Type::Default:
return telegram_api::make_object<telegram_api::botCommandScopeDefault>();

View File

@ -1431,8 +1431,8 @@ class GetExportedChatInvitesQuery final : public Td::ResultHandler {
return on_error(Status::Error(400, "Can't access the chat"));
}
auto input_user = td_->contacts_manager_->get_input_user(creator_user_id);
CHECK(input_user != nullptr);
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) {
@ -1442,9 +1442,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),
std::move(input_user), offset_date, offset_invite_link, limit)));
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)));
}
void on_result(BufferSlice packet) final {
@ -1548,15 +1548,15 @@ class GetChatInviteImportersQuery final : public Td::ResultHandler {
return on_error(Status::Error(400, "Can't access the chat"));
}
auto input_user = td_->contacts_manager_->get_input_user(offset_user_id);
if (input_user == nullptr) {
input_user = make_tl_object<telegram_api::inputUserEmpty>();
auto r_input_user = td_->contacts_manager_->get_input_user(offset_user_id);
if (r_input_user.is_error()) {
r_input_user = make_tl_object<telegram_api::inputUserEmpty>();
}
int32 flags = telegram_api::messages_getChatInviteImporters::LINK_MASK;
send_query(G()->net_query_creator().create(
telegram_api::messages_getChatInviteImporters(flags, false /*ignored*/, std::move(input_peer), invite_link,
string(), offset_date, std::move(input_user), limit)));
string(), offset_date, r_input_user.move_as_ok(), limit)));
}
void on_result(BufferSlice packet) final {
@ -1619,9 +1619,9 @@ class GetChatJoinRequestsQuery final : public Td::ResultHandler {
return on_error(Status::Error(400, "Can't access the chat"));
}
auto input_user = td_->contacts_manager_->get_input_user(offset_user_id);
if (input_user == nullptr) {
input_user = make_tl_object<telegram_api::inputUserEmpty>();
auto r_input_user = td_->contacts_manager_->get_input_user(offset_user_id);
if (r_input_user.is_error()) {
r_input_user = make_tl_object<telegram_api::inputUserEmpty>();
}
int32 flags = telegram_api::messages_getChatInviteImporters::REQUESTED_MASK;
@ -1633,7 +1633,7 @@ class GetChatJoinRequestsQuery final : public Td::ResultHandler {
}
send_query(G()->net_query_creator().create(
telegram_api::messages_getChatInviteImporters(flags, false /*ignored*/, std::move(input_peer), invite_link,
query, offset_date, std::move(input_user), limit)));
query, offset_date, r_input_user.move_as_ok(), limit)));
}
void on_result(BufferSlice packet) final {
@ -1696,9 +1696,9 @@ class HideChatJoinRequestQuery final : public Td::ResultHandler {
return on_error(Status::Error(400, "Can't access the chat"));
}
auto input_user = td_->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return on_error(Status::Error(400, "Can't find user"));
auto r_input_user = td_->contacts_manager_->get_input_user(user_id);
if (r_input_user.is_error()) {
return on_error(r_input_user.move_as_error());
}
int32 flags = 0;
@ -1706,7 +1706,7 @@ class HideChatJoinRequestQuery final : public Td::ResultHandler {
flags |= telegram_api::messages_hideChatJoinRequest::APPROVED_MASK;
}
send_query(G()->net_query_creator().create(telegram_api::messages_hideChatJoinRequest(
flags, false /*ignored*/, std::move(input_peer), std::move(input_user))));
flags, false /*ignored*/, std::move(input_peer), r_input_user.move_as_ok())));
}
void on_result(BufferSlice packet) final {
@ -1893,11 +1893,11 @@ class DeleteRevokedExportedChatInvitesQuery final : public Td::ResultHandler {
return on_error(Status::Error(400, "Can't access the chat"));
}
auto input_user = td_->contacts_manager_->get_input_user(creator_user_id);
CHECK(input_user != nullptr);
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), std::move(input_user))));
telegram_api::messages_deleteRevokedExportedChatInvites(std::move(input_peer), r_input_user.move_as_ok())));
}
void on_result(BufferSlice packet) final {
@ -2208,10 +2208,10 @@ class CanEditChannelCreatorQuery final : public Td::ResultHandler {
}
void send() {
auto input_user = td_->contacts_manager_->get_input_user(td_->contacts_manager_->get_my_id());
CHECK(input_user != nullptr);
auto r_input_user = td_->contacts_manager_->get_input_user(td_->contacts_manager_->get_my_id());
CHECK(r_input_user.is_ok());
send_query(G()->net_query_creator().create(telegram_api::channels_editCreator(
telegram_api::make_object<telegram_api::inputChannelEmpty>(), std::move(input_user),
telegram_api::make_object<telegram_api::inputChannelEmpty>(), r_input_user.move_as_ok(),
make_tl_object<telegram_api::inputCheckPasswordEmpty>())));
}
@ -2246,12 +2246,12 @@ class EditChannelCreatorQuery final : public Td::ResultHandler {
if (input_channel == nullptr) {
return promise_.set_error(Status::Error(400, "Have no access to the chat"));
}
auto input_user = td_->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return 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()) {
return promise_.set_error(r_input_user.move_as_error());
}
send_query(G()->net_query_creator().create(telegram_api::channels_editCreator(
std::move(input_channel), std::move(input_user), std::move(input_check_password))));
std::move(input_channel), r_input_user.move_as_ok(), std::move(input_check_password))));
}
void on_result(BufferSlice packet) final {
@ -4359,17 +4359,20 @@ void ContactsManager::SecretChat::parse(ParserT &parser) {
}
}
tl_object_ptr<telegram_api::InputUser> ContactsManager::get_input_user(UserId user_id) const {
Result<tl_object_ptr<telegram_api::InputUser>> ContactsManager::get_input_user(UserId user_id) const {
if (user_id == get_my_id()) {
return make_tl_object<telegram_api::inputUserSelf>();
}
const User *u = get_user(user_id);
if (u == nullptr || u->access_hash == -1 || u->is_min_access_hash) {
if (u == nullptr) {
return Status::Error(400, "User not found");
}
if (u->access_hash == -1 || u->is_min_access_hash) {
if (td_->auth_manager_->is_bot() && user_id.is_valid()) {
return make_tl_object<telegram_api::inputUser>(user_id.get(), 0);
}
return nullptr;
return Status::Error(400, "Have no access to the user");
}
return make_tl_object<telegram_api::inputUser>(user_id.get(), u->access_hash);
@ -5166,13 +5169,13 @@ void ContactsManager::add_contact(Contact contact, bool share_phone_number, Prom
LOG(INFO) << "Add " << contact << " with share_phone_number = " << share_phone_number;
auto user_id = contact.get_user_id();
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "User not found"));
auto r_input_user = get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
td_->create_handler<AddContactQuery>(std::move(promise))
->send(user_id, std::move(input_user), contact, share_phone_number);
->send(user_id, r_input_user.move_as_ok(), contact, share_phone_number);
}
std::pair<vector<UserId>, vector<int32>> ContactsManager::import_contacts(const vector<Contact> &contacts,
@ -5302,10 +5305,10 @@ void ContactsManager::remove_contacts(const vector<UserId> &user_ids, Promise<Un
for (auto &user_id : user_ids) {
const User *u = get_user(user_id);
if (u != nullptr && u->is_contact) {
auto input_user = get_input_user(user_id);
if (input_user != nullptr) {
auto r_input_user = get_input_user(user_id);
if (r_input_user.is_ok()) {
to_delete_user_ids.push_back(user_id);
input_users.push_back(std::move(input_user));
input_users.push_back(r_input_user.move_as_ok());
}
}
}
@ -5652,14 +5655,14 @@ void ContactsManager::share_phone_number(UserId user_id, Promise<Unit> &&promise
}
LOG(INFO) << "Share phone number with " << user_id;
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "User not found"));
auto r_input_user = get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
td_->messages_manager_->hide_dialog_action_bar(DialogId(user_id));
td_->create_handler<AcceptContactQuery>(std::move(promise))->send(user_id, std::move(input_user));
td_->create_handler<AcceptContactQuery>(std::move(promise))->send(user_id, r_input_user.move_as_ok());
}
void ContactsManager::search_dialogs_nearby(const Location &location,
@ -6773,13 +6776,13 @@ void ContactsManager::add_chat_participant(ChatId chat_id, UserId user_id, int32
}
// TODO upper bound on forward_limit
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "User not found"));
auto r_input_user = get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
// TODO invoke after
td_->create_handler<AddChatUserQuery>(std::move(promise))->send(chat_id, std::move(input_user), forward_limit);
td_->create_handler<AddChatUserQuery>(std::move(promise))->send(chat_id, r_input_user.move_as_ok(), forward_limit);
}
void ContactsManager::add_channel_participant(ChannelId channel_id, UserId user_id,
@ -6792,9 +6795,9 @@ void ContactsManager::add_channel_participant(ChannelId channel_id, UserId user_
if (c == nullptr) {
return promise.set_error(Status::Error(400, "Chat info not found"));
}
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "User not found"));
auto r_input_user = get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
if (user_id == get_my_id()) {
@ -6814,7 +6817,7 @@ void ContactsManager::add_channel_participant(ChannelId channel_id, UserId user_
speculative_add_channel_user(channel_id, user_id, DialogParticipantStatus::Member(), old_status);
vector<tl_object_ptr<telegram_api::InputUser>> input_users;
input_users.push_back(std::move(input_user));
input_users.push_back(r_input_user.move_as_ok());
td_->create_handler<InviteToChannelQuery>(std::move(promise))->send(channel_id, std::move(input_users));
}
@ -6835,16 +6838,16 @@ void ContactsManager::add_channel_participants(ChannelId channel_id, const vecto
vector<tl_object_ptr<telegram_api::InputUser>> input_users;
for (auto user_id : user_ids) {
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "User not found"));
auto r_input_user = get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
if (user_id == get_my_id()) {
// can't invite self
continue;
}
input_users.push_back(std::move(input_user));
input_users.push_back(r_input_user.move_as_ok());
}
if (input_users.empty()) {
@ -6921,9 +6924,10 @@ void ContactsManager::set_channel_participant_status_impl(ChannelId channel_id,
}
if (status.is_member() == old_status.is_member()) {
// change rank and is_anonymous
auto input_user = get_input_user(get_my_id());
CHECK(input_user != nullptr);
td_->create_handler<EditChannelAdminQuery>(std::move(promise))->send(channel_id, std::move(input_user), status);
auto r_input_user = get_input_user(get_my_id());
CHECK(r_input_user.is_ok());
td_->create_handler<EditChannelAdminQuery>(std::move(promise))
->send(channel_id, r_input_user.move_as_ok(), status);
return;
}
if (status.is_member()) {
@ -7002,13 +7006,13 @@ void ContactsManager::promote_channel_participant(ChannelId channel_id, UserId u
CHECK(!status.is_creator());
}
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "User not found"));
auto r_input_user = get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
speculative_add_channel_user(channel_id, user_id, status, old_status);
td_->create_handler<EditChannelAdminQuery>(std::move(promise))->send(channel_id, std::move(input_user), status);
td_->create_handler<EditChannelAdminQuery>(std::move(promise))->send(channel_id, r_input_user.move_as_ok(), status);
}
void ContactsManager::set_chat_participant_status(ChatId chat_id, UserId user_id, DialogParticipantStatus status,
@ -7080,12 +7084,13 @@ void ContactsManager::set_chat_participant_status(ChatId chat_id, UserId user_id
void ContactsManager::send_edit_chat_admin_query(ChatId chat_id, UserId user_id, bool is_administrator,
Promise<Unit> &&promise) {
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "User not found"));
auto r_input_user = get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
td_->create_handler<EditChatAdminQuery>(std::move(promise))->send(chat_id, std::move(input_user), is_administrator);
td_->create_handler<EditChatAdminQuery>(std::move(promise))
->send(chat_id, r_input_user.move_as_ok(), is_administrator);
}
void ContactsManager::can_transfer_ownership(Promise<CanTransferOwnershipResult> &&promise) {
@ -7472,13 +7477,14 @@ void ContactsManager::delete_chat_participant(ChatId chat_id, UserId user_id, bo
}
}
}
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "User not found"));
auto r_input_user = get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
// TODO invoke after
td_->create_handler<DeleteChatUserQuery>(std::move(promise))->send(chat_id, std::move(input_user), revoke_messages);
td_->create_handler<DeleteChatUserQuery>(std::move(promise))
->send(chat_id, r_input_user.move_as_ok(), revoke_messages);
}
void ContactsManager::restrict_channel_participant(ChannelId channel_id, DialogId participant_dialog_id,
@ -13956,14 +13962,14 @@ bool ContactsManager::get_user(UserId user_id, int left_tries, Promise<Unit> &&p
std::move(promise));
return false;
}
auto input_user = get_input_user(user_id);
if (left_tries == 1 || input_user == nullptr) {
promise.set_error(Status::Error(400, "User not found"));
auto r_input_user = get_input_user(user_id);
if (left_tries == 1 || r_input_user.is_error()) {
promise.set_error(r_input_user.move_as_error());
return false;
}
vector<tl_object_ptr<telegram_api::InputUser>> users;
users.push_back(std::move(input_user));
users.push_back(r_input_user.move_as_ok());
td_->create_handler<GetUsersQuery>(std::move(promise))->send(std::move(users));
return false;
}
@ -14014,14 +14020,14 @@ void ContactsManager::reload_user(UserId user_id, Promise<Unit> &&promise) {
}
have_user_force(user_id);
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "User info not found"));
auto r_input_user = get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
// there is no much reason to combine different requests into one request
vector<tl_object_ptr<telegram_api::InputUser>> users;
users.push_back(std::move(input_user));
users.push_back(r_input_user.move_as_ok());
td_->create_handler<GetUsersQuery>(std::move(promise))->send(std::move(users));
}
@ -14033,30 +14039,30 @@ void ContactsManager::load_user_full(UserId user_id, bool force, Promise<Unit> &
auto user_full = get_user_full_force(user_id);
if (user_full == nullptr) {
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "Can't get info about inaccessible user"));
auto r_input_user = get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
return send_get_user_full_query(user_id, std::move(input_user), std::move(promise), source);
return send_get_user_full_query(user_id, r_input_user.move_as_ok(), std::move(promise), source);
}
if (user_full->is_expired()) {
auto input_user = get_input_user(user_id);
CHECK(input_user != nullptr);
auto r_input_user = get_input_user(user_id);
CHECK(r_input_user.is_ok());
if (td_->auth_manager_->is_bot() && !force) {
return send_get_user_full_query(user_id, std::move(input_user), std::move(promise), "load expired user_full");
return send_get_user_full_query(user_id, r_input_user.move_as_ok(), std::move(promise), "load expired user_full");
}
send_get_user_full_query(user_id, std::move(input_user), Auto(), "load expired user_full");
send_get_user_full_query(user_id, r_input_user.move_as_ok(), Auto(), "load expired user_full");
}
promise.set_value(Unit());
}
void ContactsManager::reload_user_full(UserId user_id) {
auto input_user = get_input_user(user_id);
if (input_user != nullptr) {
send_get_user_full_query(user_id, std::move(input_user), Auto(), "reload_user_full");
auto r_input_user = get_input_user(user_id);
if (r_input_user.is_ok()) {
send_get_user_full_query(user_id, r_input_user.move_as_ok(), Auto(), "reload_user_full");
}
}
@ -14089,9 +14095,9 @@ std::pair<int32, vector<const Photo *>> ContactsManager::get_user_profile_photos
limit = MAX_GET_PROFILE_PHOTOS;
}
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
promise.set_error(Status::Error(400, "User not found"));
auto r_input_user = get_input_user(user_id);
if (r_input_user.is_error()) {
promise.set_error(r_input_user.move_as_error());
return result;
}
@ -14141,20 +14147,22 @@ std::pair<int32, vector<const Photo *>> ContactsManager::get_user_profile_photos
limit = MAX_GET_PROFILE_PHOTOS / 5; // make limit reasonable
}
td_->create_handler<GetUserPhotosQuery>(std::move(promise))->send(user_id, std::move(input_user), offset, limit, 0);
td_->create_handler<GetUserPhotosQuery>(std::move(promise))
->send(user_id, r_input_user.move_as_ok(), offset, limit, 0);
return result;
}
void ContactsManager::reload_user_profile_photo(UserId user_id, int64 photo_id, Promise<Unit> &&promise) {
get_user_force(user_id);
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "User info not found"));
auto r_input_user = get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
// this request will be needed only to download the photo,
// so there is no reason to combine different requests for a photo into one request
td_->create_handler<GetUserPhotosQuery>(std::move(promise))->send(user_id, std::move(input_user), -1, 1, photo_id);
td_->create_handler<GetUserPhotosQuery>(std::move(promise))
->send(user_id, r_input_user.move_as_ok(), -1, 1, photo_id);
}
FileSourceId ContactsManager::get_user_profile_photo_file_source_id(UserId user_id, int64 photo_id) {
@ -15154,9 +15162,9 @@ void ContactsManager::get_channel_participant(ChannelId channel_id, DialogId par
Promise<DialogParticipant> &&promise) {
LOG(INFO) << "Trying to get " << participant_dialog_id << " as member of " << channel_id;
auto input_peer = td_->messages_manager_->get_input_peer(participant_dialog_id, AccessRights::Read);
auto input_peer = td_->messages_manager_->get_input_peer(participant_dialog_id, AccessRights::Know);
if (input_peer == nullptr) {
return promise.set_error(Status::Error(400, "User not found"));
return promise.set_error(Status::Error(400, "Member not found"));
}
if (have_channel_participant_cache(channel_id)) {

View File

@ -72,7 +72,7 @@ class ContactsManager final : public Actor {
static ChatId get_chat_id(const tl_object_ptr<telegram_api::Chat> &chat);
static ChannelId get_channel_id(const tl_object_ptr<telegram_api::Chat> &chat);
tl_object_ptr<telegram_api::InputUser> get_input_user(UserId user_id) const;
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 ???

View File

@ -488,11 +488,11 @@ void get_dialog_event_log(Td *td, DialogId dialog_id, const string &query, int64
vector<tl_object_ptr<telegram_api::InputUser>> input_users;
for (auto user_id : user_ids) {
auto input_user = td->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "User not found"));
auto r_input_user = td->contacts_manager_->get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
input_users.push_back(std::move(input_user));
input_users.push_back(r_input_user.move_as_ok());
}
td->create_handler<GetChannelAdminLogQuery>(std::move(promise))

View File

@ -90,10 +90,10 @@ bool Game::has_input_media() const {
}
tl_object_ptr<telegram_api::inputMediaGame> Game::get_input_media_game(const Td *td) const {
auto input_user = td->contacts_manager_->get_input_user(bot_user_id_);
CHECK(input_user != nullptr);
auto r_input_user = td->contacts_manager_->get_input_user(bot_user_id_);
CHECK(r_input_user.is_ok());
return make_tl_object<telegram_api::inputMediaGame>(
make_tl_object<telegram_api::inputGameShortName>(std::move(input_user), short_name_));
make_tl_object<telegram_api::inputGameShortName>(r_input_user.move_as_ok(), short_name_));
}
bool operator==(const Game &lhs, const Game &rhs) {

View File

@ -217,9 +217,9 @@ void GameManager::set_game_score(FullMessageId full_message_id, bool edit_messag
return promise.set_error(Status::Error(400, "Can't access the chat"));
}
auto input_user = td_->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "Invalid user identifier specified"));
auto r_input_user = td_->contacts_manager_->get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
if (!td_->messages_manager_->can_set_game_score(full_message_id)) {
@ -234,7 +234,7 @@ void GameManager::set_game_score(FullMessageId full_message_id, bool edit_messag
send_closure(actor_id, &GameManager::on_set_game_score, full_message_id, std::move(promise));
});
send_closure(td_->create_net_actor<SetGameScoreActor>(std::move(query_promise)), &SetGameScoreActor::send, dialog_id,
full_message_id.get_message_id(), edit_message, std::move(input_user), score, force,
full_message_id.get_message_id(), edit_message, r_input_user.move_as_ok(), score, force,
MessagesManager::get_sequence_dispatcher_id(dialog_id, MessageContentType::None));
}
@ -252,13 +252,13 @@ void GameManager::set_inline_game_score(const string &inline_message_id, bool ed
return promise.set_error(Status::Error(400, "Invalid inline message identifier specified"));
}
auto input_user = td_->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "Wrong user identifier specified"));
auto r_input_user = td_->contacts_manager_->get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
td_->create_handler<SetInlineGameScoreQuery>(std::move(promise))
->send(std::move(input_bot_inline_message_id), edit_message, std::move(input_user), score, force);
->send(std::move(input_bot_inline_message_id), edit_message, r_input_user.move_as_ok(), score, force);
}
void GameManager::get_game_high_scores(FullMessageId full_message_id, UserId user_id,
@ -278,12 +278,13 @@ void GameManager::get_game_high_scores(FullMessageId full_message_id, UserId use
return promise.set_error(Status::Error(400, "Wrong message identifier specified"));
}
auto input_user = td_->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "Wrong user identifier specified"));
auto r_input_user = td_->contacts_manager_->get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
td_->create_handler<GetGameHighScoresQuery>(std::move(promise))->send(dialog_id, message_id, std::move(input_user));
td_->create_handler<GetGameHighScoresQuery>(std::move(promise))
->send(dialog_id, message_id, r_input_user.move_as_ok());
}
void GameManager::get_inline_game_high_scores(const string &inline_message_id, UserId user_id,
@ -295,13 +296,13 @@ void GameManager::get_inline_game_high_scores(const string &inline_message_id, U
return promise.set_error(Status::Error(400, "Invalid inline message identifier specified"));
}
auto input_user = td_->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "Wrong user identifier specified"));
auto r_input_user = td_->contacts_manager_->get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
td_->create_handler<GetInlineGameHighScoresQuery>(std::move(promise))
->send(std::move(input_bot_inline_message_id), std::move(input_user));
->send(std::move(input_bot_inline_message_id), r_input_user.move_as_ok());
}
td_api::object_ptr<td_api::gameHighScores> GameManager::get_game_high_scores_object(

View File

@ -3329,16 +3329,16 @@ void GroupCallManager::invite_group_call_participants(GroupCallId group_call_id,
vector<tl_object_ptr<telegram_api::InputUser>> input_users;
auto my_user_id = td_->contacts_manager_->get_my_id();
for (auto user_id : user_ids) {
auto input_user = td_->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "User not found"));
auto r_input_user = td_->contacts_manager_->get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
if (user_id == my_user_id) {
// can't invite self
continue;
}
input_users.push_back(std::move(input_user));
input_users.push_back(r_input_user.move_as_ok());
}
if (input_users.empty()) {

View File

@ -876,17 +876,17 @@ void InlineQueriesManager::loop() {
auto now = Time::now();
if (now >= next_inline_query_time_) {
LOG(INFO) << "Send inline query " << pending_inline_query_->query_hash;
auto bot_input_user = td_->contacts_manager_->get_input_user(pending_inline_query_->bot_user_id);
if (bot_input_user != nullptr) {
auto r_bot_input_user = td_->contacts_manager_->get_input_user(pending_inline_query_->bot_user_id);
if (r_bot_input_user.is_ok()) {
if (!sent_query_.empty()) {
LOG(INFO) << "Cancel inline query request";
cancel_query(sent_query_);
}
sent_query_ =
td_->create_handler<GetInlineBotResultsQuery>(std::move(pending_inline_query_->promise))
->send(pending_inline_query_->bot_user_id, pending_inline_query_->dialog_id, std::move(bot_input_user),
std::move(pending_inline_query_->input_peer), pending_inline_query_->user_location,
pending_inline_query_->query, pending_inline_query_->offset, pending_inline_query_->query_hash);
sent_query_ = td_->create_handler<GetInlineBotResultsQuery>(std::move(pending_inline_query_->promise))
->send(pending_inline_query_->bot_user_id, pending_inline_query_->dialog_id,
r_bot_input_user.move_as_ok(), std::move(pending_inline_query_->input_peer),
pending_inline_query_->user_location, pending_inline_query_->query,
pending_inline_query_->offset, pending_inline_query_->query_hash);
next_inline_query_time_ = now + INLINE_QUERY_DELAY_MS * 1e-3;
}

View File

@ -4171,10 +4171,10 @@ vector<tl_object_ptr<telegram_api::MessageEntity>> get_input_message_entities(co
make_tl_object<telegram_api::messageEntityTextUrl>(entity.offset, entity.length, entity.argument));
break;
case MessageEntity::Type::MentionName: {
auto input_user = contacts_manager->get_input_user(entity.user_id);
LOG_CHECK(input_user != nullptr) << source;
auto r_input_user = contacts_manager->get_input_user(entity.user_id);
LOG_CHECK(r_input_user.is_ok()) << source << ' ' << r_input_user.error();
result.push_back(make_tl_object<telegram_api::inputMessageEntityMentionName>(entity.offset, entity.length,
std::move(input_user)));
r_input_user.move_as_ok()));
break;
}
default:

View File

@ -837,11 +837,11 @@ class GetCommonDialogsQuery final : public Td::ResultHandler {
user_id_ = user_id;
offset_chat_id_ = offset_chat_id;
auto input_user = td_->contacts_manager_->get_input_user(user_id);
CHECK(input_user != nullptr);
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(std::move(input_user), offset_chat_id, limit)));
telegram_api::messages_getCommonChats(r_input_user.move_as_ok(), offset_chat_id, limit)));
}
void on_result(BufferSlice packet) final {
@ -19661,12 +19661,12 @@ DialogId MessagesManager::create_new_group_chat(const vector<UserId> &user_ids,
vector<tl_object_ptr<telegram_api::InputUser>> input_users;
for (auto user_id : user_ids) {
auto input_user = td_->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
promise.set_error(Status::Error(400, "User not found"));
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 DialogId();
}
input_users.push_back(std::move(input_user));
input_users.push_back(r_input_user.move_as_ok());
}
do {
@ -19720,11 +19720,14 @@ DialogId MessagesManager::create_new_channel_chat(const string &title, bool is_m
}
void MessagesManager::create_new_secret_chat(UserId user_id, Promise<SecretChatId> &&promise) {
auto user_base = td_->contacts_manager_->get_input_user(user_id);
if (user_base == nullptr || user_base->get_id() != telegram_api::inputUser::ID) {
return promise.set_error(Status::Error(400, "User not found"));
auto r_input_user = td_->contacts_manager_->get_input_user(user_id);
if (r_input_user.is_error()) {
return promise.set_error(r_input_user.move_as_error());
}
auto user = move_tl_object_as<telegram_api::inputUser>(user_base);
if (r_input_user.ok()->get_id() != telegram_api::inputUser::ID) {
return promise.set_error(Status::Error(400, "Can't create secret chat with self"));
}
auto user = static_cast<const telegram_api::inputUser *>(r_input_user.ok().get());
send_closure(G()->secret_chats_manager(), &SecretChatsManager::create_chat, UserId(user->user_id_),
user->access_hash_, std::move(promise));
@ -25276,12 +25279,12 @@ void MessagesManager::do_send_bot_start_message(UserId bot_user_id, DialogId dia
if (input_peer == nullptr) {
return on_send_message_fail(random_id, Status::Error(400, "Have no info about the chat"));
}
auto bot_input_user = td_->contacts_manager_->get_input_user(bot_user_id);
if (bot_input_user == nullptr) {
return on_send_message_fail(random_id, Status::Error(400, "Have no info about the bot"));
auto r_bot_input_user = td_->contacts_manager_->get_input_user(bot_user_id);
if (r_bot_input_user.is_error()) {
return on_send_message_fail(random_id, r_bot_input_user.move_as_error());
}
m->send_query_ref = td_->create_handler<StartBotQuery>()->send(std::move(bot_input_user), dialog_id,
m->send_query_ref = td_->create_handler<StartBotQuery>()->send(r_bot_input_user.move_as_ok(), dialog_id,
std::move(input_peer), parameter, random_id);
}

View File

@ -318,9 +318,9 @@ Result<PrivacyManager::UserPrivacySettingRule> PrivacyManager::UserPrivacySettin
vector<tl_object_ptr<telegram_api::InputUser>> PrivacyManager::UserPrivacySettingRule::get_input_users() const {
vector<tl_object_ptr<telegram_api::InputUser>> result;
for (auto user_id : user_ids_) {
auto input_user = G()->td().get_actor_unsafe()->contacts_manager_->get_input_user(user_id);
if (input_user != nullptr) {
result.push_back(std::move(input_user));
auto r_input_user = G()->td().get_actor_unsafe()->contacts_manager_->get_input_user(user_id);
if (r_input_user.is_ok()) {
result.push_back(r_input_user.move_as_ok());
} else {
LOG(ERROR) << "Have no access to " << user_id;
}

View File

@ -700,25 +700,26 @@ static tl_object_ptr<telegram_api::KeyboardButton> get_inline_keyboard_button(
if (!keyboard_button.forward_text.empty()) {
flags |= telegram_api::inputKeyboardButtonUrlAuth::FWD_TEXT_MASK;
}
auto input_user = G()->td().get_actor_unsafe()->contacts_manager_->get_input_user(UserId(bot_user_id));
if (input_user == nullptr) {
LOG(ERROR) << "Failed to get InputUser for " << bot_user_id;
auto r_input_user = G()->td().get_actor_unsafe()->contacts_manager_->get_input_user(UserId(bot_user_id));
if (r_input_user.is_error()) {
LOG(ERROR) << "Failed to get InputUser for " << bot_user_id << ": " << r_input_user.error();
return make_tl_object<telegram_api::keyboardButtonUrl>(keyboard_button.text, keyboard_button.data);
}
return make_tl_object<telegram_api::inputKeyboardButtonUrlAuth>(flags, false /*ignored*/, keyboard_button.text,
keyboard_button.forward_text,
keyboard_button.data, std::move(input_user));
keyboard_button.data, r_input_user.move_as_ok());
}
case InlineKeyboardButton::Type::CallbackWithPassword:
UNREACHABLE();
break;
case InlineKeyboardButton::Type::User: {
auto input_user = G()->td().get_actor_unsafe()->contacts_manager_->get_input_user(keyboard_button.user_id);
if (input_user == nullptr) {
LOG(ERROR) << "Failed to get InputUser for " << keyboard_button.user_id;
input_user = make_tl_object<telegram_api::inputUserEmpty>();
auto r_input_user = G()->td().get_actor_unsafe()->contacts_manager_->get_input_user(keyboard_button.user_id);
if (r_input_user.is_error()) {
LOG(ERROR) << "Failed to get InputUser for " << keyboard_button.user_id << ": " << r_input_user.error();
r_input_user = make_tl_object<telegram_api::inputUserEmpty>();
}
return make_tl_object<telegram_api::inputKeyboardButtonUserProfile>(keyboard_button.text, std::move(input_user));
return make_tl_object<telegram_api::inputKeyboardButtonUserProfile>(keyboard_button.text,
r_input_user.move_as_ok());
}
default:
UNREACHABLE();

View File

@ -5453,15 +5453,9 @@ FileId StickersManager::upload_sticker_file(UserId user_id, tl_object_ptr<td_api
user_id = td_->contacts_manager_->get_my_id();
}
auto input_user = td_->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
promise.set_error(Status::Error(400, "User not found"));
return FileId();
}
DialogId dialog_id(user_id);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
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 FileId();
}
@ -5579,15 +5573,8 @@ void StickersManager::create_new_sticker_set(UserId user_id, string &title, stri
if (!is_bot) {
user_id = td_->contacts_manager_->get_my_id();
}
auto input_user = td_->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "User not found"));
}
DialogId dialog_id(user_id);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
return promise.set_error(Status::Error(400, "Have no access to the user"));
}
TRY_RESULT_PROMISE(promise, input_user, td_->contacts_manager_->get_input_user(user_id));
title = strip_empty_characters(title, MAX_STICKER_SET_TITLE_LENGTH);
if (title.empty()) {
@ -5804,10 +5791,8 @@ void StickersManager::on_new_stickers_uploaded(int64 random_id, Result<Unit> res
CHECK(pending_new_sticker_set->upload_files_multipromise.promise_count() == 0);
auto input_user = td_->contacts_manager_->get_input_user(pending_new_sticker_set->user_id);
if (input_user == nullptr) {
return pending_new_sticker_set->promise.set_error(Status::Error(400, "User not found"));
}
auto &promise = pending_new_sticker_set->promise;
TRY_RESULT_PROMISE(promise, input_user, td_->contacts_manager_->get_input_user(pending_new_sticker_set->user_id));
bool is_masks = pending_new_sticker_set->is_masks;
bool is_animated = pending_new_sticker_set->is_animated;
@ -5827,15 +5812,7 @@ void StickersManager::on_new_stickers_uploaded(int64 random_id, Result<Unit> res
void StickersManager::add_sticker_to_set(UserId user_id, string &short_name,
tl_object_ptr<td_api::InputSticker> &&sticker, Promise<Unit> &&promise) {
auto input_user = td_->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "User not found"));
}
DialogId dialog_id(user_id);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
return promise.set_error(Status::Error(400, "Have no access to the user"));
}
TRY_RESULT_PROMISE(promise, input_user, td_->contacts_manager_->get_input_user(user_id));
short_name = strip_empty_characters(short_name, MAX_STICKER_SET_SHORT_NAME_LENGTH);
if (short_name.empty()) {
@ -5896,15 +5873,7 @@ void StickersManager::on_added_sticker_uploaded(int64 random_id, Result<Unit> re
void StickersManager::set_sticker_set_thumbnail(UserId user_id, string &short_name,
tl_object_ptr<td_api::InputFile> &&thumbnail, Promise<Unit> &&promise) {
auto input_user = td_->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "User not found"));
}
DialogId dialog_id(user_id);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
return promise.set_error(Status::Error(400, "Have no access to the user"));
}
TRY_RESULT_PROMISE(promise, input_user, td_->contacts_manager_->get_input_user(user_id));
short_name = clean_username(strip_empty_characters(short_name, MAX_STICKER_SET_SHORT_NAME_LENGTH));
if (short_name.empty()) {

View File

@ -5606,9 +5606,9 @@ void Td::on_request(uint64 id, const td_api::createCall &request) {
}
UserId user_id(request.user_id_);
auto input_user = contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return send_error_raw(id, 400, "User not found");
auto r_input_user = contacts_manager_->get_input_user(user_id);
if (r_input_user.is_error()) {
return send_error_raw(id, r_input_user.error().code(), r_input_user.error().message());
}
if (!G()->shared_config().get_option_boolean("calls_enabled")) {
@ -5623,7 +5623,7 @@ void Td::on_request(uint64 id, const td_api::createCall &request) {
promise.set_value(result.ok().get_call_id_object());
}
});
send_closure(G()->call_manager(), &CallManager::create_call, user_id, std::move(input_user),
send_closure(G()->call_manager(), &CallManager::create_call, user_id, r_input_user.move_as_ok(),
CallProtocol(*request.protocol_), request.is_video_, std::move(query_promise));
}
@ -7317,13 +7317,12 @@ void Td::on_request(uint64 id, const td_api::deletePassportElement &request) {
void Td::on_request(uint64 id, td_api::setPassportElementErrors &request) {
CHECK_IS_BOT();
UserId user_id(request.user_id_);
auto input_user = contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return send_error_raw(id, 400, "User not found");
auto r_input_user = contacts_manager_->get_input_user(UserId(request.user_id_));
if (r_input_user.is_error()) {
return send_error_raw(id, r_input_user.error().code(), r_input_user.error().message());
}
CREATE_OK_REQUEST_PROMISE();
send_closure(secure_manager_, &SecureManager::set_secure_value_errors, this, std::move(input_user),
send_closure(secure_manager_, &SecureManager::set_secure_value_errors, this, r_input_user.move_as_ok(),
std::move(request.errors_), std::move(promise));
}