Add internalLinkTypeChatInviteLink.

This commit is contained in:
levlam 2021-05-27 18:37:01 +03:00
parent 30f0509f71
commit ffa1da2cac
4 changed files with 72 additions and 8 deletions

View File

@ -2998,7 +2998,7 @@ chatReportReasonFake = ChatReportReason;
chatReportReasonCustom = ChatReportReason;
//@class InternalLinkType @description Describes an internal t.me or tg: link, which must be processed by the app in a special way
//@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 contains an authentication code. Call checkAuthenticationCode with the code if the current authorization state is authorizationStateWaitCode @code The authentication code
internalLinkTypeAuthenticationCode code:string = InternalLinkType;
@ -3006,6 +3006,9 @@ internalLinkTypeAuthenticationCode code:string = InternalLinkType;
//@description The link is a link to a background. Call searchBackground with the given background name to process the link @background_name Name of the background
internalLinkTypeBackground background_name:string = InternalLinkType;
//@description The link is a chat invite link. Call checkChatInviteLink to process the link
internalLinkTypeChatInviteLink = InternalLinkType;
//@description The link is a link to a Telegram message. Call getMessageLinkInfo to process the link
internalLinkTypeMessage = InternalLinkType;
@ -3244,7 +3247,7 @@ text text:string = Text;
seconds seconds:double = Seconds;
//@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
//@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;
@ -4049,7 +4052,7 @@ getMessageLink chat_id:int53 message_id:int53 for_album:Bool for_comment:Bool =
//@for_album Pass true to return an HTML code for embedding of the whole media album
getMessageEmbeddingCode chat_id:int53 message_id:int53 for_album:Bool = Text;
//@description Returns information about a public or private message link @url The message link in the format "https://t.me/c/...", or "tg://privatepost?...", or "https://t.me/username/...", or "tg://resolve?..."
//@description Returns information about a public or private message link @url The message link
getMessageLinkInfo url:string = MessageLinkInfo;
@ -4598,11 +4601,10 @@ deleteRevokedChatInviteLink chat_id:int53 invite_link:string = Ok;
//@creator_user_id User identifier of a chat administrator, which links will be deleted. Must be an identifier of the current user for non-owner
deleteAllRevokedChatInviteLinks chat_id:int53 creator_user_id:int32 = Ok;
//@description Checks the validity of an invite link for a chat and returns information about the corresponding chat @invite_link Invite link to be checked; must have URL "t.me", "telegram.me", or "telegram.dog" and query beginning with "/joinchat/" or "/+"
//@description Checks the validity of an invite link for a chat and returns information about the corresponding chat @invite_link Invite link to be checked
checkChatInviteLink invite_link:string = ChatInviteLinkInfo;
//@description Uses an invite link to add the current user to the chat if possible
//@invite_link Invite link to import; must have URL "t.me", "telegram.me", or "telegram.dog" and query beginning with "/joinchat/" or "/+"
//@description Uses an invite link to add the current user to the chat if possible @invite_link Invite link to use
joinChatByInviteLink invite_link:string = Chat;
@ -5096,7 +5098,7 @@ reportChat chat_id:int53 message_ids:vector<int53> reason:ChatReportReason text:
//@chat_id Chat identifier @file_id Identifier of the photo to report. Only full photos from chatPhoto can be reported @reason The reason for reporting the chat photo @text Additional report details; 0-1024 characters
reportChatPhoto chat_id:int53 file_id:int32 reason:ChatReportReason text:string = Ok;
//@description Returns an HTTP URL with the chat statistics. Currently this method of getting the statistics are disabled and can be deleted in the future @chat_id Chat identifier @parameters Parameters from "tg://statsrefresh?params=******" link @is_dark Pass true if a URL with the dark theme must be returned
//@description Returns an HTTP URL with the chat statistics. Currently this method of getting the statistics are disabled and can be deleted in the future @chat_id Chat identifier @parameters Parameters for the request @is_dark Pass true if a URL with the dark theme must be returned
getChatStatisticsUrl chat_id:int53 parameters:string is_dark:Bool = HttpUrl;
//@description Returns detailed statistics about a chat. Currently this method can be used only for supergroups and channels. Can be used only if SupergroupFullInfo.can_get_statistics == true @chat_id Chat identifier @is_dark Pass true if a dark theme is used by the application

View File

@ -55,6 +55,16 @@ class LinkManager::InternalLinkBackground : public InternalLink {
}
};
class LinkManager::InternalLinkDialogInviteLink : public InternalLink {
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeChatInviteLink>();
}
InternalLinkType get_type() const final {
return InternalLinkType::DialogInviteLink;
}
};
class LinkManager::InternalLinkMessage : public InternalLink {
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeMessage>();
@ -421,6 +431,11 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
if (has_arg("token")) {
return td::make_unique<InternalLinkQrCodeAuthentication>();
}
} else if (path.size() == 1 && path[0] == "join") {
// join?invite=abcdef
if (has_arg("invite")) {
return td::make_unique<InternalLinkDialogInviteLink>();
}
} else if (path.size() == 1 && path[0] == "privatepost") {
// privatepost?channel=123456789&msg_id=12345
if (has_arg("channel") && has_arg("msg_id")) {
@ -480,6 +495,16 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
// /login/<code>
return td::make_unique<InternalLinkAuthenticationCode>(path[1]);
}
} else if (path[0] == "joinchat") {
if (path.size() >= 2 && !path[1].empty()) {
// /joinchat/<link>
return td::make_unique<InternalLinkDialogInviteLink>();
}
} else if (path[0][0] == ' ' || path[0][0] == '+') {
if (path[0].size() >= 2) {
// /+<link>
return td::make_unique<InternalLinkDialogInviteLink>();
}
} else if (path[0] == "bg") {
if (path.size() >= 2 && !path[1].empty()) {
// /bg/<hex_color>

View File

@ -36,6 +36,7 @@ class LinkManager : public Actor {
enum class InternalLinkType : int32 {
AuthenticationCode,
Background,
DialogInviteLink,
Message,
MessageDraft,
QrCodeAuthentication,
@ -86,6 +87,7 @@ class LinkManager : public Actor {
class InternalLinkAuthenticationCode;
class InternalLinkBackground;
class InternalLinkDialogInviteLink;
class InternalLinkMessage;
class InternalLinkMessageDraft;
class InternalLinkQrCodeAuthentication;

View File

@ -70,6 +70,9 @@ TEST(Link, parse_internal_link) {
auto background = [](td::string background_name) {
return td::td_api::make_object<td::td_api::internalLinkTypeBackground>(background_name);
};
auto chat_invite_link = [] {
return td::td_api::make_object<td::td_api::internalLinkTypeChatInviteLink>();
};
auto message = [] {
return td::td_api::make_object<td::td_api::internalLinkTypeMessage>();
};
@ -246,5 +249,37 @@ TEST(Link, parse_internal_link) {
parse_internal_link("t.me/login/123456/123123/12/31/a/s//21w/?asdas#test", authentication_code("123456"));
parse_internal_link("tg:login?token=abacaba", qr_code_authentication());
parse_internal_link("tg:login?token=", qr_code_authentication());
parse_internal_link("tg:login?token=", unknown_deep_link());
parse_internal_link("t.me/joinchat?invite=abcdef", nullptr);
parse_internal_link("t.me/joinchat", nullptr);
parse_internal_link("t.me/joinchat/", nullptr);
parse_internal_link("t.me/joinchat//abcdef", nullptr);
parse_internal_link("t.me/joinchat?/abcdef", nullptr);
parse_internal_link("t.me/joinchat/?abcdef", nullptr);
parse_internal_link("t.me/joinchat/#abcdef", nullptr);
parse_internal_link("t.me/joinchat/abacaba", chat_invite_link());
parse_internal_link("t.me/joinchat/aba%20aba", chat_invite_link());
parse_internal_link("t.me/joinchat/123456a", chat_invite_link());
parse_internal_link("t.me/joinchat/12345678901", chat_invite_link());
parse_internal_link("t.me/joinchat/123456", chat_invite_link());
parse_internal_link("t.me/joinchat/123456/123123/12/31/a/s//21w/?asdas#test", chat_invite_link());
parse_internal_link("t.me/+?invite=abcdef", nullptr);
parse_internal_link("t.me/+a", chat_invite_link());
parse_internal_link("t.me/+", nullptr);
parse_internal_link("t.me/+/abcdef", nullptr);
parse_internal_link("t.me/ ?/abcdef", nullptr);
parse_internal_link("t.me/+?abcdef", nullptr);
parse_internal_link("t.me/+#abcdef", nullptr);
parse_internal_link("t.me/ abacaba", chat_invite_link());
parse_internal_link("t.me/+aba%20aba", chat_invite_link());
parse_internal_link("t.me/+123456a", chat_invite_link());
parse_internal_link("t.me/%2012345678901", chat_invite_link());
parse_internal_link("t.me/+123456", chat_invite_link());
parse_internal_link("t.me/ 123456/123123/12/31/a/s//21w/?asdas#test", chat_invite_link());
parse_internal_link("t.me/ /123456/123123/12/31/a/s//21w/?asdas#test", nullptr);
parse_internal_link("tg:join?invite=abcdef", chat_invite_link());
parse_internal_link("tg:join?invite=", unknown_deep_link());
}