From 1c56e62a6a320e0586d2f7089c547bec5bd53a30 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 8 Sep 2021 13:53:24 +0300 Subject: [PATCH] Add internalLinkTypeVoiceChat.is_live_stream flag. --- td/generate/scheme/td_api.tl | 3 ++- td/telegram/LinkManager.cpp | 13 ++++++++----- test/link.cpp | 30 +++++++++++++++--------------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 84593a4c9..9ba8ff5db 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3180,7 +3180,8 @@ internalLinkTypeUnknownDeepLink link:string = InternalLinkType; //@description The link is a link to a voice chat. Call searchPublicChat with the given chat username, and then joinGoupCall with the given invite hash to process the link //@chat_username Username of the chat with the voice chat @invite_hash If non-empty, invite hash to be used to join the voice chat without being muted by administrators -internalLinkTypeVoiceChat chat_username:string invite_hash:string = InternalLinkType; +//@is_live_stream True, if the voice chat is expected to be a live stream in a channel or a broadcast group +internalLinkTypeVoiceChat chat_username:string invite_hash:string is_live_stream:Bool = InternalLinkType; //@description Contains an HTTPS link to a message in a supergroup or channel @link Message link @is_public True, if the link will work for non-members of the chat diff --git a/td/telegram/LinkManager.cpp b/td/telegram/LinkManager.cpp index b3274aed7..71c7dc89c 100644 --- a/td/telegram/LinkManager.cpp +++ b/td/telegram/LinkManager.cpp @@ -357,14 +357,17 @@ class LinkManager::InternalLinkUnknownDeepLink final : public InternalLink { class LinkManager::InternalLinkVoiceChat final : public InternalLink { string dialog_username_; string invite_hash_; + bool is_live_stream_; td_api::object_ptr get_internal_link_type_object() const final { - return td_api::make_object(dialog_username_, invite_hash_); + return td_api::make_object(dialog_username_, invite_hash_, is_live_stream_); } public: - InternalLinkVoiceChat(string dialog_username, string invite_hash) - : dialog_username_(std::move(dialog_username)), invite_hash_(std::move(invite_hash)) { + InternalLinkVoiceChat(string dialog_username, string invite_hash, bool is_live_stream) + : dialog_username_(std::move(dialog_username)) + , invite_hash_(std::move(invite_hash)) + , is_live_stream_(is_live_stream) { } }; @@ -774,7 +777,7 @@ unique_ptr LinkManager::parse_tg_link_query(Slice que if (Scheduler::context() != nullptr) { send_closure(G()->messages_manager(), &MessagesManager::reload_voice_chat_on_search, username); } - return td::make_unique(std::move(username), arg.second); + return td::make_unique(std::move(username), arg.second, arg.first == "livestream"); } if (arg.first == "start" && is_valid_start_parameter(arg.second)) { // resolve?domain=?start= @@ -1023,7 +1026,7 @@ unique_ptr LinkManager::parse_t_me_link_query(Slice q if (Scheduler::context() != nullptr) { send_closure(G()->messages_manager(), &MessagesManager::reload_voice_chat_on_search, username); } - return td::make_unique(std::move(username), arg.second); + return td::make_unique(std::move(username), arg.second, arg.first == "livestream"); } if (arg.first == "start" && is_valid_start_parameter(arg.second)) { // /?start= diff --git a/test/link.cpp b/test/link.cpp index f564e591d..f2c5fdae1 100644 --- a/test/link.cpp +++ b/test/link.cpp @@ -170,8 +170,8 @@ TEST(Link, parse_internal_link) { auto unknown_deep_link = [](td::string link) { return td::td_api::make_object(link); }; - auto voice_chat = [](td::string chat_username, td::string invite_hash) { - return td::td_api::make_object(chat_username, invite_hash); + auto voice_chat = [](td::string chat_username, td::string invite_hash, bool is_live_stream) { + return td::td_api::make_object(chat_username, invite_hash, is_live_stream); }; parse_internal_link("t.me/levlam/1", message("tg:resolve?domain=levlam&post=1")); @@ -523,27 +523,27 @@ TEST(Link, parse_internal_link) { parse_internal_link("tg:socks?server=google.com&port=8%30&user=&pass=2", proxy_socks("google.com", 80, "", "2")); parse_internal_link("tg:socks?server=google.com&port=80&user=1&pass=2", proxy_socks("google.com", 80, "1", "2")); - parse_internal_link("tg:resolve?domain=username&voice%63hat=aasdasd", voice_chat("username", "aasdasd")); - parse_internal_link("tg:resolve?domain=username&video%63hat=aasdasd", voice_chat("username", "aasdasd")); - parse_internal_link("tg:resolve?domain=username&livestream=aasdasd", voice_chat("username", "aasdasd")); - parse_internal_link("TG://resolve?domain=username&voicechat=", voice_chat("username", "")); + parse_internal_link("tg:resolve?domain=username&voice%63hat=aasdasd", voice_chat("username", "aasdasd", false)); + parse_internal_link("tg:resolve?domain=username&video%63hat=aasdasd", voice_chat("username", "aasdasd", false)); + parse_internal_link("tg:resolve?domain=username&livestream=aasdasd", voice_chat("username", "aasdasd", true)); + parse_internal_link("TG://resolve?domain=username&voicechat=", voice_chat("username", "", false)); parse_internal_link("TG://test@resolve?domain=username&voicechat=", nullptr); parse_internal_link("tg:resolve:80?domain=username&voicechat=", nullptr); parse_internal_link("tg:http://resolve?domain=username&voicechat=", nullptr); parse_internal_link("tg:https://resolve?domain=username&voicechat=", nullptr); parse_internal_link("tg:resolve?domain=&voicechat=", unknown_deep_link("tg://resolve?domain=&voicechat=")); - parse_internal_link("tg:resolve?domain=telegram&&&&&&&voicechat=%30", voice_chat("telegram", "0")); + parse_internal_link("tg:resolve?domain=telegram&&&&&&&voicechat=%30", voice_chat("telegram", "0", false)); - parse_internal_link("t.me/username/0/a//s/as?voicechat=", voice_chat("username", "")); - parse_internal_link("t.me/username/0/a//s/as?videochat=2", voice_chat("username", "2")); - parse_internal_link("t.me/username/0/a//s/as?livestream=3", voice_chat("username", "3")); - parse_internal_link("t.me/username/aasdas?test=1&voicechat=#12312", voice_chat("username", "")); - parse_internal_link("t.me/username/0?voicechat=", voice_chat("username", "")); - parse_internal_link("t.me/username/-1?voicechat=asdasd", voice_chat("username", "asdasd")); - parse_internal_link("t.me/username?voicechat=", voice_chat("username", "")); + parse_internal_link("t.me/username/0/a//s/as?voicechat=", voice_chat("username", "", false)); + parse_internal_link("t.me/username/0/a//s/as?videochat=2", voice_chat("username", "2", false)); + parse_internal_link("t.me/username/0/a//s/as?livestream=3", voice_chat("username", "3", true)); + parse_internal_link("t.me/username/aasdas?test=1&voicechat=#12312", voice_chat("username", "", false)); + parse_internal_link("t.me/username/0?voicechat=", voice_chat("username", "", false)); + parse_internal_link("t.me/username/-1?voicechat=asdasd", voice_chat("username", "asdasd", false)); + parse_internal_link("t.me/username?voicechat=", voice_chat("username", "", false)); parse_internal_link("t.me/username#voicechat=asdas", public_chat("username")); parse_internal_link("t.me//username?voicechat=", nullptr); - parse_internal_link("https://telegram.dog/tele%63ram?voi%63e%63hat=t%63st", voice_chat("telecram", "tcst")); + parse_internal_link("https://telegram.dog/tele%63ram?voi%63e%63hat=t%63st", voice_chat("telecram", "tcst", false)); parse_internal_link("tg:resolve?domain=username&start=aasdasd", bot_start("username", "aasdasd")); parse_internal_link("TG://resolve?domain=username&start=", bot_start("username", ""));