Fix internalLinkTypeMainWebApp.

This commit is contained in:
levlam 2024-07-22 18:19:04 +03:00
parent a0fdd7c579
commit 5c771778df
3 changed files with 10 additions and 18 deletions

View File

@ -6507,11 +6507,11 @@ internalLinkTypeLanguageSettings = InternalLinkType;
//-If the bot can be added to attachment menu, then use getAttachmentMenuBot to receive information about the bot, then if the bot isn't added to side menu, //-If the bot can be added to attachment menu, then use getAttachmentMenuBot to receive information about the bot, then if the bot isn't added to side menu,
//-show a disclaimer about Mini Apps being a third-party apps, ask the user to accept their Terms of service and confirm adding the bot to side and attachment menu, //-show a disclaimer about Mini Apps being a third-party apps, ask the user to accept their Terms of service and confirm adding the bot to side and attachment menu,
//-then if the user accepts the terms and confirms adding, use toggleBotIsAddedToAttachmentMenu to add the bot. //-then if the user accepts the terms and confirms adding, use toggleBotIsAddedToAttachmentMenu to add the bot.
//-Then use getMainWebAppUrl with the given URL and open the returned URL as a Web App //-Then use getMainWebApp with the given start parameter and open the returned URL as a Web App
//@bot_username Username of the bot //@bot_username Username of the bot
//@url URL to be passed to getMainWebAppUrl //@start_parameter Start parameter to be passed to getMainWebApp
//@is_compact True, if the Web App must be opened in the compact mode instead of the full-size mode //@is_compact True, if the Web App must be opened in the compact mode instead of the full-size mode
internalLinkTypeMainWebApp bot_username:string url:string is_compact:Bool = InternalLinkType; internalLinkTypeMainWebApp bot_username:string start_parameter:string is_compact:Bool = InternalLinkType;
//@description The link is a link to a Telegram message or a forum topic. Call getMessageLinkInfo with the given URL to process the link, //@description The link is a link to a Telegram message or a forum topic. Call getMessageLinkInfo with the given URL to process the link,
//-and then open received forum topic or chat and show the message there //-and then open received forum topic or chat and show the message there

View File

@ -530,19 +530,16 @@ class LinkManager::InternalLinkLanguageSettings final : public InternalLink {
class LinkManager::InternalLinkMainWebApp final : public InternalLink { class LinkManager::InternalLinkMainWebApp final : public InternalLink {
string bot_username_; string bot_username_;
string url_; string start_parameter_;
string mode_; string mode_;
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final { td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeMainWebApp>(bot_username_, url_, mode_ == "compact"); return td_api::make_object<td_api::internalLinkTypeMainWebApp>(bot_username_, start_parameter_, mode_ == "compact");
} }
public: public:
InternalLinkMainWebApp(string bot_username, string start_parameter, string mode) InternalLinkMainWebApp(string bot_username, string start_parameter, string mode)
: bot_username_(std::move(bot_username)), mode_(std::move(mode)) { : bot_username_(std::move(bot_username)), start_parameter_(std::move(start_parameter)), mode_(std::move(mode)) {
if (!start_parameter.empty()) {
url_ = PSTRING() << "start://" << start_parameter;
}
} }
}; };
@ -2214,15 +2211,11 @@ Result<string> LinkManager::get_internal_link_impl(const td_api::InternalLinkTyp
return Status::Error(400, "Invalid bot username specified"); return Status::Error(400, "Invalid bot username specified");
} }
string start_parameter; string start_parameter;
if (!link->url_.empty()) { if (!link->start_parameter_.empty()) {
if (!begins_with(link->url_, "start://")) { if (!is_valid_start_parameter(link->start_parameter_)) {
return Status::Error(400, "Unsupported link URL specified");
}
auto start_parameter_slice = Slice(link->url_).substr(8);
if (start_parameter_slice.empty() || !is_valid_start_parameter(start_parameter_slice)) {
return Status::Error(400, "Invalid start parameter specified"); return Status::Error(400, "Invalid start parameter specified");
} }
start_parameter = PSTRING() << '=' << start_parameter_slice; start_parameter = PSTRING() << '=' << link->start_parameter_;
} }
string mode = link->is_compact_ ? "&mode=compact" : ""; string mode = link->is_compact_ ? "&mode=compact" : "";
if (is_internal) { if (is_internal) {

View File

@ -273,8 +273,7 @@ static auto language_settings() {
} }
static auto main_web_app(const td::string &bot_username, const td::string &start_parameter, bool is_compact) { static auto main_web_app(const td::string &bot_username, const td::string &start_parameter, bool is_compact) {
return td::td_api::make_object<td::td_api::internalLinkTypeMainWebApp>( return td::td_api::make_object<td::td_api::internalLinkTypeMainWebApp>(bot_username, start_parameter, is_compact);
bot_username, start_parameter.empty() ? td::string() : "start://" + start_parameter, is_compact);
} }
static auto message(const td::string &url) { static auto message(const td::string &url) {