Add and use ContactsManager::get_input_user_force.

This commit is contained in:
levlam 2023-03-22 18:18:35 +03:00
parent 25047c28cf
commit 7c3822d932
4 changed files with 20 additions and 16 deletions

View File

@ -3996,11 +3996,7 @@ ContactsManager::ContactsManager(Td *td, ActorShared<> parent) : td_(td), parent
get_user_queries_.set_merge_function([this](vector<int64> query_ids, Promise<Unit> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
auto input_users = transform(query_ids, [this](int64 query_id) {
auto r_input_user = get_input_user(UserId(query_id));
CHECK(r_input_user.is_ok());
return r_input_user.move_as_ok();
});
auto input_users = transform(query_ids, [this](int64 query_id) { return get_input_user_force(UserId(query_id)); });
td_->create_handler<GetUsersQuery>(std::move(promise))->send(std::move(input_users));
});
get_chat_queries_.set_merge_function([this](vector<int64> query_ids, Promise<Unit> &&promise) {
@ -5325,6 +5321,15 @@ 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);
}
telegram_api::object_ptr<telegram_api::InputUser> ContactsManager::get_input_user_force(UserId user_id) const {
auto r_input_user = get_input_user(user_id);
if (r_input_user.is_error()) {
CHECK(user_id.is_valid());
return make_tl_object<telegram_api::inputUser>(user_id.get(), 0);
}
return r_input_user.move_as_ok();
}
tl_object_ptr<telegram_api::InputChannel> ContactsManager::get_input_channel(ChannelId channel_id) const {
const Channel *c = get_channel(channel_id);
if (c == nullptr) {
@ -16112,13 +16117,12 @@ void ContactsManager::load_user_full(UserId user_id, bool force, Promise<Unit> &
return send_get_user_full_query(user_id, std::move(input_user), std::move(promise), source);
}
if (user_full->is_expired()) {
auto r_input_user = get_input_user(user_id);
CHECK(r_input_user.is_ok());
auto input_user = get_input_user_force(user_id);
if (td_->auth_manager_->is_bot() && !force) {
return send_get_user_full_query(user_id, r_input_user.move_as_ok(), std::move(promise), "load expired user_full");
return send_get_user_full_query(user_id, std::move(input_user), std::move(promise), "load expired user_full");
}
send_get_user_full_query(user_id, r_input_user.move_as_ok(), Auto(), "load expired user_full");
send_get_user_full_query(user_id, std::move(input_user), Auto(), "load expired user_full");
}
promise.set_value(Unit());
@ -16224,7 +16228,7 @@ void ContactsManager::send_get_user_photos_query(UserId user_id, const UserPhoto
});
td_->create_handler<GetUserPhotosQuery>(std::move(query_promise))
->send(user_id, get_input_user(user_id).move_as_ok(), offset, max(limit, MAX_GET_PROFILE_PHOTOS / 5), 0);
->send(user_id, get_input_user_force(user_id), offset, max(limit, MAX_GET_PROFILE_PHOTOS / 5), 0);
}
void ContactsManager::on_get_user_profile_photos(UserId user_id, Result<Unit> &&result) {

View File

@ -90,6 +90,8 @@ class ContactsManager final : public Actor {
Result<tl_object_ptr<telegram_api::InputUser>> get_input_user(UserId user_id) const;
tl_object_ptr<telegram_api::InputUser> get_input_user_force(UserId user_id) const;
// TODO get_input_chat ???
tl_object_ptr<telegram_api::InputChannel> get_input_channel(ChannelId channel_id) const;

View File

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

View File

@ -4460,10 +4460,9 @@ 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 r_input_user = contacts_manager->get_input_user(entity.user_id);
LOG_CHECK(r_input_user.is_ok()) << source << ' ' << entity.user_id << ' ' << r_input_user.error();
auto input_user = contacts_manager->get_input_user_force(entity.user_id);
result.push_back(make_tl_object<telegram_api::inputMessageEntityMentionName>(entity.offset, entity.length,
r_input_user.move_as_ok()));
std::move(input_user)));
break;
}
default: