Skip to content

Commit 78be930

Browse files
authored
Open video chat links in the videochat form (#169)
The link parser only knew the voicechat key, so videochat links, which the API now exports for group video chats (including Copy Invite Link on macOS), opened the group without joining the chat. A livestream key with a value was ignored as well. Treat videochat and livestream like voicechat in t.me and tg://resolve links, with and without a value, like iOS, and cover them in LinkParsingTests.
1 parent 01a2a82 commit 78be930

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎packages/TelegramLinks/Sources/TelegramLinks/LinkParsing.swift‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ private let keyURLSet = "set";
5757
private let keyURLText = "text";
5858
private let keyURLStart = "start";
5959
private let keyURLVoiceChat = "voicechat";
60+
private let keyURLVideoChat = "videochat";
6061
private let keyURLStartattach = "startattach";
6162
private let keyURLAttach = "attach";
6263
private let keyURLStartGroup = "startgroup";
@@ -455,7 +456,7 @@ public func parseInAppLink(_ url: NSString, options: InAppLinkParsingOptions = I
455456
return .inviteBotToGroup(link: urlString, username: username, action: .start(parameter: value, behavior: .automatic), rights: rights, isChannel: key == keyURLStartChannel)
456457
}
457458
break loop;
458-
case keyURLVoiceChat:
459+
case keyURLVoiceChat, keyURLVideoChat, keyURLLivestream:
459460
action = .joinVoiceChat(value)
460461
break loop;
461462
case keyURLAttach:
@@ -471,7 +472,7 @@ public func parseInAppLink(_ url: NSString, options: InAppLinkParsingOptions = I
471472
break
472473
}
473474
}
474-
if vars.isEmpty && userAndVariables[1] == keyURLVoiceChat {
475+
if vars.isEmpty && [keyURLVoiceChat, keyURLVideoChat, keyURLLivestream].contains(userAndVariables[1]) {
475476
action = .joinVoiceChat(nil)
476477
}
477478
}
@@ -735,7 +736,7 @@ public func parseInAppLink(_ url: NSString, options: InAppLinkParsingOptions = I
735736
let rights = vars[keyURLAdmin]
736737
return .inviteBotToGroup(link: urlString, username: username, action: .start(parameter: value, behavior: .none), rights: rights, isChannel: key == keyURLStartChannel)
737738
}
738-
case keyURLVoiceChat:
739+
case keyURLVoiceChat, keyURLVideoChat, keyURLLivestream:
739740
action = .joinVoiceChat(value)
740741
break loop
741742
case keyURLAttach:
@@ -771,7 +772,7 @@ public func parseInAppLink(_ url: NSString, options: InAppLinkParsingOptions = I
771772
}
772773
if action == nil && emptyVars.contains(keyURLStartapp) {
773774
action = .makeWebview(appname: "", command: nil)
774-
} else if action == nil && emptyVars.contains(keyURLVoiceChat) {
775+
} else if action == nil && (emptyVars.contains(keyURLVoiceChat) || emptyVars.contains(keyURLVideoChat) || emptyVars.contains(keyURLLivestream)) {
775776
action = .joinVoiceChat(nil)
776777
} else if action == nil, vars[keyURLStartattach] != nil || vars[keyURLAttach] != nil {
777778
let choose = vars[keyURLChoose]?.split(separator: "+").compactMap { String($0) }

‎packages/TelegramLinks/Tests/TelegramLinksTests/LinkParsingTests.swift‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ final class LinkParsingTests: XCTestCase {
147147
assertPeer("tg://resolve?domain=alice&text=hello%20world", username: "alice", action: .inputText(text: "hello world", behavior: .automatic))
148148
assertPeer("tg://resolve?domain=alice&voicechat", username: "alice", action: .joinVoiceChat(nil))
149149
assertPeer("tg://resolve?domain=alice&voicechat=abc", username: "alice", action: .joinVoiceChat("abc"))
150+
assertPeer("tg://resolve?domain=alice&videochat", username: "alice", action: .joinVoiceChat(nil))
151+
assertPeer("tg://resolve?domain=alice&videochat=abc", username: "alice", action: .joinVoiceChat("abc"))
152+
assertPeer("tg://resolve?domain=alice&livestream=abc", username: "alice", action: .joinVoiceChat("abc"))
153+
assertPeer("https://t.me/alice?videochat", username: "alice", action: .joinVoiceChat(nil))
154+
assertPeer("https://t.me/alice?videochat=abc", username: "alice", action: .joinVoiceChat("abc"))
155+
assertPeer("https://t.me/alice?voicechat", username: "alice", action: .joinVoiceChat(nil))
150156
assertPeer("tg://resolve?domain=alice&startapp", username: "alice", action: .makeWebview(appname: "", command: nil))
151157
assertPeer("tg://resolve?domain=alice&attach=bot&choose=users+groups", username: "alice", action: .attachBot("bot", nil, ["bot"]))
152158
assertPeer("tg://resolve?domain=alice&direct", username: "alice", action: .direct)

0 commit comments

Comments
 (0)