Add td_api::getUserLink.
This commit is contained in:
parent
38d3ecbd26
commit
b340e559bb
@ -2763,6 +2763,10 @@ sentWebAppMessage inline_message_id:string = SentWebAppMessage;
|
||||
httpUrl url:string = HttpUrl;
|
||||
|
||||
|
||||
//@description Contains an HTTPS URL, which can be used to get information about a user @url The URL @expires_in Left time for which the link is valid, in seconds; 0 if the link is a public username link
|
||||
userLink url:string expires_in:int32 = UserLink;
|
||||
|
||||
|
||||
//@class InputInlineQueryResult @description Represents a single result of an inline query; for bots only
|
||||
|
||||
//@description Represents a link to an animated GIF or an animated (i.e., without sound) H.264/MPEG-4 AVC video
|
||||
@ -6366,6 +6370,9 @@ resendChangePhoneNumberCode = AuthenticationCodeInfo;
|
||||
//@description Checks the authentication code sent to confirm a new phone number of the user @code Authentication code to check
|
||||
checkChangePhoneNumberCode code:string = Ok;
|
||||
|
||||
//@description Returns an HTTPS link, which can be used to get information about the current user
|
||||
getUserLink = UserLink;
|
||||
|
||||
|
||||
//@description Sets the list of commands supported by the bot for the given user scope and language; for bots only
|
||||
//@scope The scope to which the commands are relevant; pass null to change commands in the default bot command scope
|
||||
|
@ -589,6 +589,35 @@ class SetBotBroadcastDefaultAdminRightsQuery final : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class ExportContactTokenQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::userLink>> promise_;
|
||||
|
||||
public:
|
||||
explicit ExportContactTokenQuery(Promise<td_api::object_ptr<td_api::userLink>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send() {
|
||||
send_query(G()->net_query_creator().create(telegram_api::contacts_exportContactToken()));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::contacts_exportContactToken>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for ExportContactTokenQuery: " << to_string(ptr);
|
||||
promise_.set_value(td_api::make_object<td_api::userLink>(
|
||||
ptr->url_, td::max(static_cast<int32>(ptr->expires_ - G()->unix_time()), static_cast<int32>(1))));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
void set_default_message_ttl(Td *td, int32 message_ttl, Promise<Unit> &&promise) {
|
||||
td->create_handler<SetDefaultHistoryTtlQuery>(std::move(promise))->send(message_ttl);
|
||||
}
|
||||
@ -668,4 +697,8 @@ void set_default_channel_administrator_rights(Td *td, AdministratorRights admini
|
||||
td->create_handler<SetBotBroadcastDefaultAdminRightsQuery>(std::move(promise))->send(administrator_rights);
|
||||
}
|
||||
|
||||
void export_contact_token(Td *td, Promise<td_api::object_ptr<td_api::userLink>> &&promise) {
|
||||
td->create_handler<ExportContactTokenQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -50,4 +50,6 @@ void set_default_group_administrator_rights(Td *td, AdministratorRights administ
|
||||
void set_default_channel_administrator_rights(Td *td, AdministratorRights administrator_rights,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void export_contact_token(Td *td, Promise<td_api::object_ptr<td_api::userLink>> &&promise);
|
||||
|
||||
} // namespace td
|
||||
|
@ -6,6 +6,7 @@
|
||||
//
|
||||
#include "td/telegram/ContactsManager.h"
|
||||
|
||||
#include "td/telegram/Account.h"
|
||||
#include "td/telegram/AnimationsManager.h"
|
||||
#include "td/telegram/AuthManager.h"
|
||||
#include "td/telegram/BotMenuButton.h"
|
||||
@ -15406,6 +15407,27 @@ void ContactsManager::reload_dialog_info(DialogId dialog_id, Promise<Unit> &&pro
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::get_user_link(Promise<td_api::object_ptr<td_api::userLink>> &&promise) {
|
||||
get_me(
|
||||
PromiseCreator::lambda([actor_id = actor_id(this), promise = std::move(promise)](Result<Unit> &&result) mutable {
|
||||
if (result.is_error()) {
|
||||
promise.set_error(result.move_as_error());
|
||||
} else {
|
||||
send_closure(actor_id, &ContactsManager::get_user_link_impl, std::move(promise));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void ContactsManager::get_user_link_impl(Promise<td_api::object_ptr<td_api::userLink>> &&promise) {
|
||||
TRY_STATUS_PROMISE(promise, G()->close_status());
|
||||
const auto *u = get_user(get_my_id());
|
||||
if (u != nullptr && u->usernames.has_first_username()) {
|
||||
return promise.set_value(
|
||||
td_api::make_object<td_api::userLink>(LinkManager::get_public_chat_link(u->usernames.get_first_username()), 0));
|
||||
}
|
||||
export_contact_token(td_, std::move(promise));
|
||||
}
|
||||
|
||||
void ContactsManager::send_get_me_query(Td *td, Promise<Unit> &&promise) {
|
||||
vector<tl_object_ptr<telegram_api::InputUser>> users;
|
||||
users.push_back(make_tl_object<telegram_api::inputUserSelf>());
|
||||
|
@ -538,6 +538,8 @@ class ContactsManager final : public Actor {
|
||||
|
||||
void reload_dialog_info(DialogId dialog_id, Promise<Unit> &&promise);
|
||||
|
||||
void get_user_link(Promise<td_api::object_ptr<td_api::userLink>> &&promise);
|
||||
|
||||
static void send_get_me_query(Td *td, Promise<Unit> &&promise);
|
||||
UserId get_me(Promise<Unit> &&promise);
|
||||
bool get_user(UserId user_id, int left_tries, Promise<Unit> &&promise);
|
||||
@ -1312,6 +1314,8 @@ class ContactsManager final : public Actor {
|
||||
string get_channel_search_text(ChannelId channel_id) const;
|
||||
static string get_channel_search_text(const Channel *c);
|
||||
|
||||
void get_user_link_impl(Promise<td_api::object_ptr<td_api::userLink>> &&promise);
|
||||
|
||||
void set_my_id(UserId my_id);
|
||||
|
||||
static bool is_allowed_username(const string &username);
|
||||
|
@ -1668,6 +1668,10 @@ string LinkManager::get_instant_view_link(Slice url, Slice rhash) {
|
||||
<< "&rhash=" << url_encode(rhash);
|
||||
}
|
||||
|
||||
string LinkManager::get_public_chat_link(Slice username) {
|
||||
return PSTRING() << G()->get_option_string("t_me_url", "https://t.me/") << url_encode(username);
|
||||
}
|
||||
|
||||
UserId LinkManager::get_link_user_id(Slice url) {
|
||||
string lower_cased_url = to_lower(url);
|
||||
url = lower_cased_url;
|
||||
|
@ -88,6 +88,8 @@ class LinkManager final : public Actor {
|
||||
|
||||
static string get_instant_view_link(Slice url, Slice rhash);
|
||||
|
||||
static string get_public_chat_link(Slice username);
|
||||
|
||||
static UserId get_link_user_id(Slice url);
|
||||
|
||||
static Result<CustomEmojiId> get_link_custom_emoji_id(Slice url);
|
||||
|
@ -4530,6 +4530,12 @@ void Td::on_request(uint64 id, td_api::resendChangePhoneNumberCode &request) {
|
||||
send_closure(change_phone_number_manager_, &PhoneNumberManager::resend_authentication_code, id);
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getUserLink &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST_PROMISE();
|
||||
contacts_manager_->get_user_link(std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getActiveSessions &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST_PROMISE();
|
||||
|
@ -486,6 +486,8 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, td_api::resendChangePhoneNumberCode &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getUserLink &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getActiveSessions &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::terminateSession &request);
|
||||
|
@ -2171,6 +2171,8 @@ class CliClient final : public Actor {
|
||||
} else {
|
||||
send_request(td_api::make_object<td_api::searchContacts>("", as_limit(args)));
|
||||
}
|
||||
} else if (op == "gul") {
|
||||
send_request(td_api::make_object<td_api::getUserLink>());
|
||||
} else if (op == "AddContact") {
|
||||
UserId user_id;
|
||||
string first_name;
|
||||
|
Loading…
Reference in New Issue
Block a user