mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
111 lines
6.5 KiB
Swift
111 lines
6.5 KiB
Swift
import Foundation
|
|
import TelegramCore
|
|
import Postbox
|
|
import Display
|
|
import SwiftSignalKit
|
|
|
|
private func defaultNavigationForPeerId(_ peerId: PeerId?, navigation: ChatControllerInteractionNavigateToPeer) -> ChatControllerInteractionNavigateToPeer {
|
|
if case .default = navigation {
|
|
if let peerId = peerId {
|
|
if peerId.namespace == Namespaces.Peer.CloudUser {
|
|
return .info
|
|
} else {
|
|
return .chat(textInputState: nil, messageId: nil)
|
|
}
|
|
} else {
|
|
return .info
|
|
}
|
|
} else {
|
|
return navigation
|
|
}
|
|
}
|
|
|
|
func openResolvedUrl(_ resolvedUrl: ResolvedUrl, account: Account, context: OpenURLContext = .generic, navigationController: NavigationController?, openPeer: @escaping (PeerId, ChatControllerInteractionNavigateToPeer) -> Void, sendFile: ((FileMediaReference) -> Void)? = nil, present: (ViewController, Any?) -> Void, dismissInput: @escaping () -> Void) {
|
|
let presentationData = account.telegramApplicationContext.currentPresentationData.with { $0 }
|
|
switch resolvedUrl {
|
|
case let .externalUrl(url):
|
|
openExternalUrl(account: account, context: context, url: url, presentationData: account.telegramApplicationContext.currentPresentationData.with { $0 }, applicationContext: account.telegramApplicationContext, navigationController: navigationController, dismissInput: dismissInput)
|
|
case let .peer(peerId, navigation):
|
|
if let peerId = peerId {
|
|
openPeer(peerId, defaultNavigationForPeerId(peerId, navigation: navigation))
|
|
} else {
|
|
|
|
present(standardTextAlertController(theme: AlertControllerTheme(presentationTheme: presentationData.theme), title: nil, text: presentationData.strings.Resolve_ErrorNotFound, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
|
}
|
|
case let .botStart(peerId, payload):
|
|
openPeer(peerId, .withBotStartPayload(ChatControllerInitialBotStart(payload: payload, behavior: .interactive)))
|
|
case let .groupBotStart(botPeerId, payload):
|
|
let controller = PeerSelectionController(account: account, filter: [.onlyWriteable, .onlyGroups, .onlyManageable], title: presentationData.strings.UserInfo_InviteBotToGroup)
|
|
controller.peerSelected = { [weak controller] peerId in
|
|
if payload.isEmpty {
|
|
let _ = (addPeerMember(account: account, peerId: peerId, memberId: botPeerId)
|
|
|> deliverOnMainQueue).start(completed: {
|
|
controller?.dismiss()
|
|
})
|
|
} else {
|
|
let _ = (requestStartBotInGroup(account: account, botPeerId: botPeerId, groupPeerId: peerId, payload: payload)
|
|
|> deliverOnMainQueue).start(next: { result in
|
|
if let navigationController = navigationController {
|
|
navigateToChatController(navigationController: navigationController, account: account, chatLocation: .peer(peerId))
|
|
}
|
|
switch result {
|
|
case let .channelParticipant(participant):
|
|
account.telegramApplicationContext.peerChannelMemberCategoriesContextsManager.externallyAdded(peerId: peerId, participant: participant)
|
|
case .none:
|
|
break
|
|
}
|
|
controller?.dismiss()
|
|
}, error: { _ in
|
|
|
|
})
|
|
}
|
|
}
|
|
dismissInput()
|
|
present(controller, ViewControllerPresentationArguments(presentationAnimation: ViewControllerPresentationAnimation.modalSheet))
|
|
case let .channelMessage(peerId, messageId):
|
|
openPeer(peerId, .chat(textInputState: nil, messageId: messageId))
|
|
case let .stickerPack(name):
|
|
dismissInput()
|
|
let controller = StickerPackPreviewController(account: account, stickerPack: .name(name), parentNavigationController: navigationController)
|
|
controller.sendSticker = sendFile
|
|
present(controller, nil)
|
|
case let .instantView(webpage, anchor):
|
|
navigationController?.pushViewController(InstantPageController(account: account, webPage: webpage, anchor: anchor))
|
|
case let .join(link):
|
|
dismissInput()
|
|
present(JoinLinkPreviewController(account: account, link: link, navigateToPeer: { peerId in
|
|
openPeer(peerId, .chat(textInputState: nil, messageId: nil))
|
|
}), nil)
|
|
case let .localization(identifier):
|
|
dismissInput()
|
|
present(LanguageLinkPreviewController(account: account, identifier: identifier), nil)
|
|
case let .proxy(host, port, username, password, secret):
|
|
let presentationData = account.telegramApplicationContext.currentPresentationData.with { $0 }
|
|
let server: ProxyServerSettings
|
|
if let secret = secret {
|
|
server = ProxyServerSettings(host: host, port: abs(port), connection: .mtp(secret: secret))
|
|
} else {
|
|
server = ProxyServerSettings(host: host, port: abs(port), connection: .socks5(username: username, password: password))
|
|
}
|
|
|
|
dismissInput()
|
|
present(ProxyServerActionSheetController(account: account, theme: presentationData.theme, strings: presentationData.strings, server: server), nil)
|
|
case let .confirmationCode(code):
|
|
if let topController = navigationController?.topViewController as? ChangePhoneNumberCodeController {
|
|
topController.applyCode(code)
|
|
} else {
|
|
var found = false
|
|
navigationController?.currentWindow?.forEachController({ controller in
|
|
if let controller = controller as? SecureIdPlaintextFormController {
|
|
controller.applyPhoneCode(code)
|
|
found = true
|
|
}
|
|
})
|
|
if !found {
|
|
let presentationData = account.telegramApplicationContext.currentPresentationData.with { $0 }
|
|
present(standardTextAlertController(theme: AlertControllerTheme(presentationTheme: presentationData.theme), title: nil, text: presentationData.strings.AuthCode_Alert(formattedConfirmationCode(code)).0, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
|
}
|
|
}
|
|
}
|
|
}
|