td_api::getDeepLinkInfo.

GitOrigin-RevId: edcedaeeaeb54802bb2830343e43ab095f92acaf
This commit is contained in:
levlam 2018-04-12 23:51:42 +03:00
parent 00590f1b72
commit 4a3784155a
6 changed files with 78 additions and 1 deletions

View File

@ -1899,6 +1899,10 @@ count count:int32 = Count;
text text:string = Text; text text:string = Text;
//@description Contains information about a tg:// deep link @text Text to be shown to the user @need_update_application True, if user should be asked to update the application
deepLinkInfo text:formattedText need_update_application:Bool = DeepLinkInfo;
//@class TextParseMode @description Describes the way the text should be parsed for TextEntities //@class TextParseMode @description Describes the way the text should be parsed for TextEntities
//@description The text should be parsed in markdown-style //@description The text should be parsed in markdown-style
@ -3046,6 +3050,9 @@ getInviteText = Text;
//@description Returns the terms of service. Can be called before authorization //@description Returns the terms of service. Can be called before authorization
getTermsOfService = Text; getTermsOfService = Text;
//@description Returns information about a tg:// deep link. Returns a 404 error for unknown links. Can be called before authorization @link The link
getDeepLinkInfo link:string = DeepLinkInfo;
//@description Sets the proxy server for network requests. Can be called before authorization @proxy Proxy server to use. Specify null to remove the proxy server //@description Sets the proxy server for network requests. Can be called before authorization @proxy Proxy server to use. Specify null to remove the proxy server
setProxy proxy:Proxy = Ok; setProxy proxy:Proxy = Ok;

Binary file not shown.

View File

@ -1860,7 +1860,7 @@ vector<MessageEntity> get_message_entities(const ContactsManager *contacts_manag
LOG(ERROR) << "Receive invalid " << user_id << " in MentionName from " << source; LOG(ERROR) << "Receive invalid " << user_id << " in MentionName from " << source;
continue; continue;
} }
if (!contacts_manager->have_user(user_id)) { if (contacts_manager == nullptr || !contacts_manager->have_user(user_id)) {
LOG(ERROR) << "Receive unknown " << user_id << " in MentionName from " << source; LOG(ERROR) << "Receive unknown " << user_id << " in MentionName from " << source;
continue; continue;
} }

View File

@ -458,6 +458,66 @@ class GetTermsOfServiceQuery : public Td::ResultHandler {
} }
}; };
class GetDeepLinkInfoQuery : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::deepLinkInfo>> promise_;
public:
explicit GetDeepLinkInfoQuery(Promise<td_api::object_ptr<td_api::deepLinkInfo>> &&promise) : promise_(std::move(promise)) {
}
void send(Slice link) {
Slice link_scheme("tg:");
if (begins_with(link, link_scheme)) {
link.remove_prefix(link_scheme.size());
if (begins_with(link, "//")) {
link.remove_prefix(2);
}
}
size_t pos = 0;
while (pos < link.size() && link[pos] != '/' && link[pos] != '?' && link[pos] != '#') {
pos++;
}
link.truncate(pos);
send_query(G()->net_query_creator().create(create_storer(telegram_api::help_getDeepLinkInfo(link.str())), DcId::main(),
NetQuery::Type::Common, NetQuery::AuthFlag::Off));
}
void on_result(uint64 id, BufferSlice packet) override {
auto result_ptr = fetch_result<telegram_api::help_getDeepLinkInfo>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
auto result = result_ptr.move_as_ok();
switch (result->get_id()) {
case telegram_api::help_deepLinkInfoEmpty::ID:
return promise_.set_value(nullptr);
case telegram_api::help_deepLinkInfo::ID: {
auto info = telegram_api::move_object_as<telegram_api::help_deepLinkInfo>(result);
bool need_update = (info->flags_ & telegram_api::help_deepLinkInfo::UPDATE_APP_MASK) != 0;
auto entities = get_message_entities(nullptr, std::move(info->entities_), "GetDeepLinkInfoQuery");
auto status = fix_formatted_text(info->message_, entities, true, true, true, true);
if (status.is_error()) {
LOG(ERROR) << "Receive error " << status << " while parsing deep link info " << info->message_;
if (!clean_input_string(info->message_)) {
info->message_.clear();
}
entities.clear();
}
FormattedText text{std::move(info->message_), std::move(entities)};
return promise_.set_value(td_api::make_object<td_api::deepLinkInfo>(get_formatted_text_object(text), need_update));
}
default:
UNREACHABLE();
}
}
void on_error(uint64 id, Status status) override {
promise_.set_error(std::move(status));
}
};
template <class T = Unit> template <class T = Unit>
class RequestActor : public Actor { class RequestActor : public Actor {
public: public:
@ -7002,6 +7062,12 @@ void Td::on_request(uint64 id, const td_api::getTermsOfService &request) {
CREATE_NO_ARGS_REQUEST(GetTermsOfServiceRequest); CREATE_NO_ARGS_REQUEST(GetTermsOfServiceRequest);
} }
void Td::on_request(uint64 id, td_api::getDeepLinkInfo &request) {
CLEAN_INPUT_STRING(request.link_);
CREATE_REQUEST_PROMISE(promise);
create_handler<GetDeepLinkInfoQuery>(std::move(promise))->send(request.link_);
}
void Td::on_request(uint64 id, const td_api::getProxy &request) { void Td::on_request(uint64 id, const td_api::getProxy &request) {
CREATE_REQUEST_PROMISE(promise); CREATE_REQUEST_PROMISE(promise);
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<Proxy> result) mutable { auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<Proxy> result) mutable {

View File

@ -793,6 +793,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, const td_api::getTermsOfService &request); void on_request(uint64 id, const td_api::getTermsOfService &request);
void on_request(uint64 id, td_api::getDeepLinkInfo &request);
void on_request(uint64 id, const td_api::getProxy &request); void on_request(uint64 id, const td_api::getProxy &request);
void on_request(uint64 id, const td_api::setProxy &request); void on_request(uint64 id, const td_api::setProxy &request);

View File

@ -1605,6 +1605,8 @@ class CliClient final : public Actor {
send_request(make_tl_object<td_api::getInviteText>()); send_request(make_tl_object<td_api::getInviteText>());
} else if (op == "gtos") { } else if (op == "gtos") {
send_request(make_tl_object<td_api::getTermsOfService>()); send_request(make_tl_object<td_api::getTermsOfService>());
} else if (op == "gdli") {
send_request(make_tl_object<td_api::getDeepLinkInfo>(args));
} else if (op == "tme") { } else if (op == "tme") {
send_request(make_tl_object<td_api::getRecentlyVisitedTMeUrls>(args)); send_request(make_tl_object<td_api::getRecentlyVisitedTMeUrls>(args));
} else if (op == "bu") { } else if (op == "bu") {