Add internalLinkTypeSettings.

This commit is contained in:
levlam 2021-06-01 03:55:08 +03:00
parent 6f88008e84
commit 1de8b85809
4 changed files with 102 additions and 1 deletions

View File

@ -3000,6 +3000,9 @@ chatReportReasonCustom = ChatReportReason;
//@class InternalLinkType @description Describes an internal https://t.me or tg: link, which must be processed by the app in a special way
//@description The link is a link to the active sessions section of the app. Use getActiveSessions to handle the link
internalLinkTypeActiveSessions = InternalLinkType;
//@description The link contains an authentication code. Call checkAuthenticationCode with the code if the current authorization state is authorizationStateWaitCode @code The authentication code
internalLinkTypeAuthenticationCode code:string = InternalLinkType;
@ -3016,9 +3019,15 @@ internalLinkTypeBotStart bot_username:string start_parameter:string = InternalLi
//@bot_username Username of the bot @start_parameter The parameter to be passed to sendBotStartMessage
internalLinkTypeBotStartInGroup bot_username:string start_parameter:string = InternalLinkType;
//@description The link is a link to the change phone number section of the app
internalLinkTypeChangePhoneNumber = InternalLinkType;
//@description The link is a chat invite link. Call checkChatInviteLink to process the link
internalLinkTypeChatInvite = InternalLinkType;
//@description The link is a link to the filter settings section of the app
internalLinkTypeFilterSettings = InternalLinkType;
//@description The link is a link to a game. Call searchPublicChat with the given bot username, check that the user is a bot, ask the current user to select a group to send the game, and then call sendMessage with inputMessageGame
//@bot_username Username of the bot that owns the game @game_short_name Short name of the game
internalLinkTypeGame bot_username:string game_short_name:string = InternalLinkType;
@ -3053,12 +3062,18 @@ internalLinkTypePublicChat chat_username:string = InternalLinkType;
//-"This code can be used to allow someone to log in to your Telegram account. To confirm Telegram login, please go to Settings > Devices > Scan QR and scan the code" needs to be shown
internalLinkTypeQrCodeAuthentication = InternalLinkType;
//@description The link is a link to app settings
internalLinkTypeSettings = InternalLinkType;
//@description The link is a link to a sticker set. Call searchStickerSet with the given sticker set name to process the link and show the sticker set @sticker_set_name Name of the sticker set
internalLinkTypeStickerSet sticker_set_name:string = InternalLinkType;
//@description The link is a link to a theme. TDLib has no theme support yet @theme_name Name of the theme
internalLinkTypeTheme theme_name:string = InternalLinkType;
//@description The link is a link to the theme settings section of the app
internalLinkTypeThemeSettings = InternalLinkType;
//@description The link is an unknown tg: link. Call getDeepLinkInfo to process the link
internalLinkTypeUnknownDeepLink = InternalLinkType;

View File

@ -56,6 +56,12 @@ static bool is_valid_username(Slice username) {
return true;
}
class LinkManager::InternalLinkActiveSessions : public InternalLink {
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeActiveSessions>();
}
};
class LinkManager::InternalLinkAuthenticationCode : public InternalLink {
string code_;
@ -108,6 +114,12 @@ class LinkManager::InternalLinkBotStartInGroup : public InternalLink {
}
};
class LinkManager::InternalLinkChangePhoneNumber : public InternalLink {
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeChangePhoneNumber>();
}
};
class LinkManager::InternalLinkConfirmPhone : public InternalLink {
string hash_;
string phone_number_;
@ -128,6 +140,12 @@ class LinkManager::InternalLinkDialogInvite : public InternalLink {
}
};
class LinkManager::InternalLinkFilterSettings : public InternalLink {
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeFilterSettings>();
}
};
class LinkManager::InternalLinkGame : public InternalLink {
string bot_username_;
string game_short_name_;
@ -246,6 +264,12 @@ class LinkManager::InternalLinkQrCodeAuthentication : public InternalLink {
}
};
class LinkManager::InternalLinkSettings : public InternalLink {
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeSettings>();
}
};
class LinkManager::InternalLinkStickerSet : public InternalLink {
string sticker_set_name_;
@ -270,6 +294,12 @@ class LinkManager::InternalLinkTheme : public InternalLink {
}
};
class LinkManager::InternalLinkThemeSettings : public InternalLink {
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeThemeSettings>();
}
};
class LinkManager::InternalLinkUnknownDeepLink : public InternalLink {
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeUnknownDeepLink>();
@ -654,6 +684,25 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
} else if (path.size() == 1 && path[0] == "passport") {
// passport?bot_id=<bot_user_id>&scope=<scope>&public_key=<public_key>&nonce=<nonce>
return get_internal_link_passport(url_query.args_);
} else if (path.size() >= 1 && path[0] == "settings") {
if (path.size() == 2 && path[1] == "change_number") {
// settings/change_number
return td::make_unique<InternalLinkChangePhoneNumber>();
}
if (path.size() == 2 && path[1] == "devices") {
// settings/devices
return td::make_unique<InternalLinkActiveSessions>();
}
if (path.size() == 2 && path[1] == "folders") {
// settings/folders
return td::make_unique<InternalLinkFilterSettings>();
}
if (path.size() == 2 && path[1] == "themes") {
// settings/themes
return td::make_unique<InternalLinkThemeSettings>();
}
// settings
return td::make_unique<InternalLinkSettings>();
} else if (path.size() == 1 && path[0] == "join") {
// join?invite=<hash>
if (has_arg("invite")) {

View File

@ -70,12 +70,15 @@ class LinkManager : public Actor {
private:
void tear_down() override;
class InternalLinkActiveSessions;
class InternalLinkAuthenticationCode;
class InternalLinkBackground;
class InternalLinkBotStart;
class InternalLinkBotStartInGroup;
class InternalLinkChangePhoneNumber;
class InternalLinkConfirmPhone;
class InternalLinkDialogInvite;
class InternalLinkFilterSettings;
class InternalLinkGame;
class InternalLinkLanguage;
class InternalLinkMessage;
@ -84,8 +87,10 @@ class LinkManager : public Actor {
class InternalLinkProxy;
class InternalLinkPublicDialog;
class InternalLinkQrCodeAuthentication;
class InternalLinkSettings;
class InternalLinkStickerSet;
class InternalLinkTheme;
class InternalLinkThemeSettings;
class InternalLinkUnknownDeepLink;
class InternalLinkVoiceChat;

View File

@ -63,6 +63,9 @@ static void parse_internal_link(td::string url, td::td_api::object_ptr<td::td_ap
}
TEST(Link, parse_internal_link) {
auto active_sessions = [] {
return td::td_api::make_object<td::td_api::internalLinkTypeActiveSessions>();
};
auto authentication_code = [](td::string code) {
return td::td_api::make_object<td::td_api::internalLinkTypeAuthenticationCode>(code);
};
@ -75,9 +78,15 @@ TEST(Link, parse_internal_link) {
auto bot_start_in_group = [](td::string bot_username, td::string start_parameter) {
return td::td_api::make_object<td::td_api::internalLinkTypeBotStartInGroup>(bot_username, start_parameter);
};
auto change_phone_number = [] {
return td::td_api::make_object<td::td_api::internalLinkTypeChangePhoneNumber>();
};
auto chat_invite = [] {
return td::td_api::make_object<td::td_api::internalLinkTypeChatInvite>();
};
auto filter_settings = [] {
return td::td_api::make_object<td::td_api::internalLinkTypeFilterSettings>();
};
auto game = [](td::string bot_username, td::string game_short_name) {
return td::td_api::make_object<td::td_api::internalLinkTypeGame>(bot_username, game_short_name);
};
@ -111,15 +120,21 @@ TEST(Link, parse_internal_link) {
auto public_chat = [](td::string chat_username) {
return td::td_api::make_object<td::td_api::internalLinkTypePublicChat>(chat_username);
};
auto qr_code_authentication = []() {
auto qr_code_authentication = [] {
return td::td_api::make_object<td::td_api::internalLinkTypeQrCodeAuthentication>();
};
auto settings = [] {
return td::td_api::make_object<td::td_api::internalLinkTypeSettings>();
};
auto sticker_set = [](td::string sticker_set_name) {
return td::td_api::make_object<td::td_api::internalLinkTypeStickerSet>(sticker_set_name);
};
auto theme = [](td::string theme_name) {
return td::td_api::make_object<td::td_api::internalLinkTypeTheme>(theme_name);
};
auto theme_settings = [] {
return td::td_api::make_object<td::td_api::internalLinkTypeThemeSettings>();
};
auto unknown_deep_link = [] {
return td::td_api::make_object<td::td_api::internalLinkTypeUnknownDeepLink>();
};
@ -566,4 +581,21 @@ TEST(Link, parse_internal_link) {
parse_internal_link("tg://passport?bot_id=12345&public_key=key&scope=asd&payload=", unknown_deep_link());
parse_internal_link("t.me/telegrampassport?bot_id=12345&public_key=key&scope=asd&payload=nonce",
public_chat("telegrampassport"));
parse_internal_link("tg://settings", settings());
parse_internal_link("tg://setting", unknown_deep_link());
parse_internal_link("tg://settings?asdsa?D?SADasD?asD", settings());
parse_internal_link("tg://settings#test", settings());
parse_internal_link("tg://settings/#test", settings());
parse_internal_link("tg://settings/aadsa#test", settings());
parse_internal_link("tg://settings/theme#test", settings());
parse_internal_link("tg://settings/themes#test", theme_settings());
parse_internal_link("tg://settings/themesa#test", settings());
parse_internal_link("tg://settings/themes/?as#rad", theme_settings());
parse_internal_link("tg://settings/themes/a", settings());
parse_internal_link("tg://settings/asdsathemesasdas/devices", settings());
parse_internal_link("tg://settings/devices", active_sessions());
parse_internal_link("tg://settings/change_number", change_phone_number());
parse_internal_link("tg://settings/folders", filter_settings());
parse_internal_link("tg://settings/filters", settings());
}