Better getMe.

GitOrigin-RevId: 31a9ceaa4727f74ef30cd95a44c2520249fea10b
This commit is contained in:
levlam 2018-03-09 03:27:39 +03:00
parent 022c1a1163
commit 8ae5083073
5 changed files with 39 additions and 12 deletions

View File

@ -7925,6 +7925,19 @@ ContactsManager::User *ContactsManager::get_user(UserId user_id) {
}
}
UserId ContactsManager::get_me(Promise<Unit> &&promise) {
auto my_id = get_my_id("get_me");
if (!have_user_force(my_id)) {
vector<tl_object_ptr<telegram_api::InputUser>> users;
users.push_back(make_tl_object<telegram_api::inputUserSelf>());
td_->create_handler<GetUsersQuery>(std::move(promise))->send(std::move(users));
return UserId();
}
promise.set_value(Unit());
return my_id;
}
bool ContactsManager::get_user(UserId user_id, int left_tries, Promise<Unit> &&promise) {
if (!user_id.is_valid()) {
promise.set_error(Status::Error(6, "Invalid user id"));

View File

@ -335,6 +335,8 @@ class ContactsManager : public Actor {
bool have_user(UserId user_id) const;
bool have_min_user(UserId user_id) const;
bool have_user_force(UserId user_id);
UserId get_me(Promise<Unit> &&promise);
bool get_user(UserId user_id, int left_tries, Promise<Unit> &&promise);
bool get_user_full(UserId user_id, Promise<Unit> &&promise);

View File

@ -740,6 +740,23 @@ class DisconnectAllWebsitesRequest : public RequestOnceActor {
}
};
class GetMeRequest : public RequestActor<> {
UserId user_id_;
void do_run(Promise<Unit> &&promise) override {
user_id_ = td->contacts_manager_->get_me(std::move(promise));
}
void do_send_result() override {
send_result(td->contacts_manager_->get_user_object(user_id_));
}
public:
GetMeRequest(ActorShared<Td> td, uint64 request_id)
: RequestActor(std::move(td), request_id) {
}
};
class GetUserRequest : public RequestActor<> {
UserId user_id_;
@ -4811,7 +4828,7 @@ void Td::on_request(uint64 id, td_api::setAuthenticationPhoneNumber &request) {
request.allow_flash_call_, request.is_current_phone_number_);
}
void Td::on_request(uint64 id, const td_api::resendAuthenticationCode &) {
void Td::on_request(uint64 id, const td_api::resendAuthenticationCode &request) {
send_closure(auth_manager_actor_, &AuthManager::resend_authentication_code, id);
}
@ -5054,12 +5071,9 @@ void Td::on_request(uint64 id, const td_api::disconnectAllWebsites &request) {
CREATE_NO_ARGS_REQUEST(DisconnectAllWebsitesRequest);
}
void Td::on_request(uint64 id, const td_api::getMe &) {
void Td::on_request(uint64 id, const td_api::getMe &request) {
CHECK_AUTH();
UserId my_id = contacts_manager_->get_my_id("getMe");
CHECK(my_id.is_valid());
CREATE_REQUEST(GetUserRequest, my_id.get());
CREATE_NO_ARGS_REQUEST(GetMeRequest);
}
void Td::on_request(uint64 id, const td_api::getUser &request) {
@ -6856,7 +6870,7 @@ void Td::on_request(uint64 id, const td_api::getFileExtension &request) {
}
template <class T>
td_api::object_ptr<td_api::Object> Td::do_static_request(const T &) {
td_api::object_ptr<td_api::Object> Td::do_static_request(const T &request) {
return make_error(400, "Function can't be executed synchronously");
}

View File

@ -792,7 +792,7 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, td_api::testCallVectorStringObject &request);
template <class T>
static td_api::object_ptr<td_api::Object> do_static_request(const T &);
static td_api::object_ptr<td_api::Object> do_static_request(const T &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getTextEntities &request);
static td_api::object_ptr<td_api::Object> do_static_request(td_api::parseTextEntities &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getFileMimeType &request);

View File

@ -2824,9 +2824,7 @@ class CliClient final : public Actor {
} else if (op == "gproxy") {
send_request(make_tl_object<td_api::getProxy>());
} else if (op == "SetVerbosity") {
int new_verbosity = to_integer<int>(args);
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(FATAL) + new_verbosity);
LOG(PLAIN) << "Verbosity=" << new_verbosity;
td::Log::set_verbosity_level(to_integer<int>(args));
} else if (op == "q" || op == "Quit") {
quit();
} else if (op == "dnq" || op == "DumpNetQueries") {
@ -3027,7 +3025,7 @@ void main(int argc, char **argv) {
if (*arg == '\0' && i + 1 < argc) {
arg = argv[++i];
}
if (file_log.init(arg) && file_log.init(arg) && file_log.init(arg)) {
if (file_log.init(arg) && file_log.init(arg) && file_log.init(arg, 1000 << 20)) {
log_interface = &ts_log;
}
} else if (!std::strcmp(argv[i], "-W")) {