Improve getExternalLink methods.
This commit is contained in:
parent
eb7a1286ab
commit
54b9760935
@ -4228,8 +4228,12 @@ viewMessages chat_id:int53 message_thread_id:int53 message_ids:vector<int53> for
|
||||
//@description Informs TDLib that the message content has been opened (e.g., the user has opened a photo, video, document, location or venue, or has listened to an audio file or voice note message). An updateMessageContentOpened update will be generated if something has changed @chat_id Chat identifier of the message @message_id Identifier of the message with the opened content
|
||||
openMessageContent chat_id:int53 message_id:int53 = Ok;
|
||||
|
||||
//@description Returns an HTTP URL to open when user clicks on a given HTTP link. This method can be used to automatically login user on a Telegram site @link The HTTP link
|
||||
getExternalLink link:string = HttpUrl;
|
||||
//@description Returns information about an action to be done when the current user clicks an HTTP link. This method can be used to automatically authorize the current user on a website @link The HTTP link
|
||||
getExternalLinkInfo link:string = LoginUrlInfo;
|
||||
|
||||
//@description Returns an HTTP URL which can be used to automatically authorize the current user on a website after clicking an HTTP link. Use the method getExternalLinkInfo to find whether a prior user confirmation is needed
|
||||
//@link The HTTP link @allow_write_access True, if the current user allowed the bot, returned in getExternalLinkInfo, to send them messages
|
||||
getExternalLink link:string allow_write_access:Bool = HttpUrl;
|
||||
|
||||
|
||||
//@description Marks all mentions in a chat as read @chat_id Chat identifier
|
||||
|
@ -967,33 +967,34 @@ void ConfigManager::get_app_config(Promise<td_api::object_ptr<td_api::JsonValue>
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigManager::get_external_link(string &&link, Promise<string> &&promise) {
|
||||
void ConfigManager::get_external_link_info(string &&link, Promise<td_api::object_ptr<td_api::LoginUrlInfo>> &&promise) {
|
||||
auto default_result = td_api::make_object<td_api::loginUrlInfoOpen>(link, false);
|
||||
if (G()->close_flag()) {
|
||||
return promise.set_value(std::move(link));
|
||||
return promise.set_value(std::move(default_result));
|
||||
}
|
||||
|
||||
auto r_url = parse_url(link);
|
||||
if (r_url.is_error()) {
|
||||
return promise.set_value(std::move(link));
|
||||
return promise.set_value(std::move(default_result));
|
||||
}
|
||||
|
||||
if (!td::contains(autologin_domains_, r_url.ok().host_)) {
|
||||
return promise.set_value(std::move(link));
|
||||
return promise.set_value(std::move(default_result));
|
||||
}
|
||||
|
||||
if (autologin_update_time_ < Time::now() - 10000) {
|
||||
auto query_promise = PromiseCreator::lambda([link = std::move(link), promise = std::move(promise)](
|
||||
Result<td_api::object_ptr<td_api::JsonValue>> &&result) mutable {
|
||||
if (result.is_error()) {
|
||||
return promise.set_value(std::move(link));
|
||||
return promise.set_value(td_api::make_object<td_api::loginUrlInfoOpen>(link, false));
|
||||
}
|
||||
send_closure(G()->config_manager(), &ConfigManager::get_external_link, std::move(link), std::move(promise));
|
||||
send_closure(G()->config_manager(), &ConfigManager::get_external_link_info, std::move(link), std::move(promise));
|
||||
});
|
||||
return get_app_config(std::move(query_promise));
|
||||
}
|
||||
|
||||
if (autologin_token_.empty()) {
|
||||
return promise.set_value(std::move(link));
|
||||
return promise.set_value(std::move(default_result));
|
||||
}
|
||||
|
||||
auto url = r_url.move_as_ok();
|
||||
@ -1018,7 +1019,7 @@ void ConfigManager::get_external_link(string &&link, Promise<string> &&promise)
|
||||
|
||||
url.query_ = PSTRING() << path << parameters << added_parameter << hash;
|
||||
|
||||
promise.set_value(url.get_url());
|
||||
promise.set_value(td_api::make_object<td_api::loginUrlInfoOpen>(url.get_url(), false));
|
||||
}
|
||||
|
||||
void ConfigManager::get_content_settings(Promise<Unit> &&promise) {
|
||||
|
@ -93,7 +93,7 @@ class ConfigManager : public NetQueryCallback {
|
||||
|
||||
void get_app_config(Promise<td_api::object_ptr<td_api::JsonValue>> &&promise);
|
||||
|
||||
void get_external_link(string &&link, Promise<string> &&promise);
|
||||
void get_external_link_info(string &&link, Promise<td_api::object_ptr<td_api::LoginUrlInfo>> &&promise);
|
||||
|
||||
void get_content_settings(Promise<Unit> &&promise);
|
||||
|
||||
|
@ -5472,19 +5472,19 @@ void Td::on_request(uint64 id, const td_api::openMessageContent &request) {
|
||||
id, messages_manager_->open_message_content({DialogId(request.chat_id_), MessageId(request.message_id_)}));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::getExternalLinkInfo &request) {
|
||||
CHECK_IS_USER();
|
||||
CLEAN_INPUT_STRING(request.link_);
|
||||
CREATE_REQUEST_PROMISE();
|
||||
send_closure_later(G()->config_manager(), &ConfigManager::get_external_link_info, std::move(request.link_),
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::getExternalLink &request) {
|
||||
CHECK_IS_USER();
|
||||
CLEAN_INPUT_STRING(request.link_);
|
||||
CREATE_REQUEST_PROMISE();
|
||||
auto query_promise = [promise = std::move(promise)](Result<string> &&result) mutable {
|
||||
if (result.is_error()) {
|
||||
promise.set_error(result.move_as_error());
|
||||
} else {
|
||||
promise.set_value(td_api::make_object<td_api::httpUrl>(result.ok()));
|
||||
}
|
||||
};
|
||||
send_closure_later(G()->config_manager(), &ConfigManager::get_external_link, std::move(request.link_),
|
||||
std::move(query_promise));
|
||||
promise.set_value(td_api::make_object<td_api::httpUrl>(request.link_));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getChatHistory &request) {
|
||||
|
@ -577,6 +577,8 @@ class Td final : public NetQueryCallback {
|
||||
|
||||
void on_request(uint64 id, const td_api::openMessageContent &request);
|
||||
|
||||
void on_request(uint64 id, td_api::getExternalLinkInfo &request);
|
||||
|
||||
void on_request(uint64 id, td_api::getExternalLink &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getChatHistory &request);
|
||||
|
@ -3923,9 +3923,12 @@ class CliClient final : public Actor {
|
||||
string message_id;
|
||||
get_args(args, chat_id, message_id);
|
||||
send_request(td_api::make_object<td_api::openMessageContent>(as_chat_id(chat_id), as_message_id(message_id)));
|
||||
} else if (op == "gel") {
|
||||
} else if (op == "geli") {
|
||||
string link = args;
|
||||
send_request(td_api::make_object<td_api::getExternalLink>(link));
|
||||
send_request(td_api::make_object<td_api::getExternalLinkInfo>(link));
|
||||
} else if (op == "gel" || op == "gelw") {
|
||||
string link = args;
|
||||
send_request(td_api::make_object<td_api::getExternalLink>(link, op == "gelw"));
|
||||
} else if (op == "racm") {
|
||||
string chat_id = args;
|
||||
send_request(td_api::make_object<td_api::readAllChatMentions>(as_chat_id(chat_id)));
|
||||
|
Loading…
Reference in New Issue
Block a user