From 4a3784155afee19c63328b98210cc8b607d76f45 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 12 Apr 2018 23:51:42 +0300 Subject: [PATCH] td_api::getDeepLinkInfo. GitOrigin-RevId: edcedaeeaeb54802bb2830343e43ab095f92acaf --- td/generate/scheme/td_api.tl | 7 ++++ td/generate/scheme/td_api.tlo | Bin 120728 -> 120996 bytes td/telegram/MessageEntity.cpp | 2 +- td/telegram/Td.cpp | 66 ++++++++++++++++++++++++++++++++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 2 ++ 6 files changed, 78 insertions(+), 1 deletion(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 3dd562fd..3c0860d6 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1899,6 +1899,10 @@ count count:int32 = Count; 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 //@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 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 setProxy proxy:Proxy = Ok; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 684277dee08babb9f5f426c5695c39195598a253..656ae89b2a95bebfff0b94b242cb1a28bb7d46dc 100644 GIT binary patch delta 174 zcmbQSo_)zicHT#`^{p77V8=#YeGb8Y3#9XTTvAgDd@}R0J@eA?CvTLJ-fY8hLX1&s zGpjtejRaUl3X%$-evsIt4LUsHd8w%>@udYRi6yC%FZ@)PoM6bo0+QU!620Xcqu}

8H2Bj~OOWjWsk(Vg$cJ&V get_message_entities(const ContactsManager *contacts_manag LOG(ERROR) << "Receive invalid " << user_id << " in MentionName from " << source; 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; continue; } diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 7ecdb2cc..f5cc4954 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -458,6 +458,66 @@ class GetTermsOfServiceQuery : public Td::ResultHandler { } }; +class GetDeepLinkInfoQuery : public Td::ResultHandler { + Promise> promise_; + + public: + explicit GetDeepLinkInfoQuery(Promise> &&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(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(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(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 RequestActor : public Actor { public: @@ -7002,6 +7062,12 @@ void Td::on_request(uint64 id, const td_api::getTermsOfService &request) { 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(std::move(promise))->send(request.link_); +} + void Td::on_request(uint64 id, const td_api::getProxy &request) { CREATE_REQUEST_PROMISE(promise); auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result result) mutable { diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 4a4c5596..bf99bc71 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -793,6 +793,8 @@ class Td final : public NetQueryCallback { 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::setProxy &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index b55ef755..3cd908f3 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1605,6 +1605,8 @@ class CliClient final : public Actor { send_request(make_tl_object()); } else if (op == "gtos") { send_request(make_tl_object()); + } else if (op == "gdli") { + send_request(make_tl_object(args)); } else if (op == "tme") { send_request(make_tl_object(args)); } else if (op == "bu") {