From 2e279e8fd39f72ca390c2d4394c74f83df09dd13 Mon Sep 17 00:00:00 2001 From: Isaac <> Date: Tue, 2 Dec 2025 19:30:48 +0800 Subject: [PATCH] Temp --- .../Sources/AccountContext.swift | 1 + .../Sources/ChatListController.swift | 30 +++++++++++++++++++ .../TelegramCore/Sources/Suggestions.swift | 5 ++++ submodules/TelegramUI/BUILD | 1 + .../Sources/PasskeysScreen.swift | 15 ++++++++-- .../PasskeysScreenIntroComponent.swift | 14 +++++++++ .../Sources/SharedAccountContext.swift | 5 ++++ 7 files changed, 68 insertions(+), 3 deletions(-) diff --git a/submodules/AccountContext/Sources/AccountContext.swift b/submodules/AccountContext/Sources/AccountContext.swift index 8e1eea45ff..6dbe69cb02 100644 --- a/submodules/AccountContext/Sources/AccountContext.swift +++ b/submodules/AccountContext/Sources/AccountContext.swift @@ -1475,6 +1475,7 @@ public protocol SharedAccountContext: AnyObject { func makeNewContactScreen(context: AccountContext, peer: EnginePeer?, phoneNumber: String?, shareViaException: Bool, completion: @escaping (EnginePeer?, DeviceContactStableId?, DeviceContactExtendedData?) -> Void) -> ViewController func makeLoginEmailSetupController(context: AccountContext, blocking: Bool, emailPattern: String?, canAutoDismissIfNeeded: Bool, navigationController: NavigationController?, completion: @escaping () -> Void, dismiss: @escaping () -> Void) -> ViewController + public func makePasskeySetupController(context: AccountContext, displaySkip: Bool, navigationController: NavigationController?, completion: @escaping () -> Void, dismiss: completion: @escaping () -> Void) -> ViewController func navigateToCurrentCall() var hasOngoingCall: ValuePromise { get } diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index 5c5e8f23e3..a09dc29986 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -137,6 +137,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController private let dismissAutoarchiveDisposable = MetaDisposable() private var didSuggestAutoarchive = false private var didSuggestLoginEmailSetup = false + private var didSuggestLoginPasskeySetup = false private var presentationData: PresentationData private let presentationDataValue = Promise() @@ -2586,6 +2587,35 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController return } + if values.contains(.setupPasskey) { + if strongSelf.didSuggestLoginPasskeySetup { + return + } + strongSelf.didSuggestLoginPasskeySetup = true + + let _ = (context.engine.notices.getServerProvidedSuggestions(reload: true) + |> deliverOnMainQueue).start(next: { [weak strongSelf] currentValues in + guard let strongSelf, currentValues.contains(.setupPasskey) else { + return + } + if let navigationController = strongSelf.navigationController as? NavigationController { + let controller = strongSelf.context.sharedContext.makePasskeySetupController(context: strongSelf.context, displaySkip: true, navigationController: navigationController, completion: { + let _ = context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.setupPasskey.id).startStandalone() + }, dismiss: { + let _ = context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.setupPasskey.id).startStandalone() + }) + if let layout = strongSelf.validLayout, layout.metrics.isTablet { + controller.navigationPresentation = .standaloneFlatModal + } else { + controller.navigationPresentation = .flatModal + } + navigationController.pushViewController(controller) + } + }) + + return + } + if strongSelf.didSuggestAutoarchive { return } diff --git a/submodules/TelegramCore/Sources/Suggestions.swift b/submodules/TelegramCore/Sources/Suggestions.swift index 041af82f71..d6b47a9a37 100644 --- a/submodules/TelegramCore/Sources/Suggestions.swift +++ b/submodules/TelegramCore/Sources/Suggestions.swift @@ -20,6 +20,7 @@ public enum ServerProvidedSuggestion: Equatable { case setupPhoto case setupLoginEmail case setupLoginEmailBlocking + case setupPasskey case link(id: String, url: String, title: ServerSuggestionInfo.Item.Text, subtitle: ServerSuggestionInfo.Item.Text) init?(string: String) { @@ -56,6 +57,8 @@ public enum ServerProvidedSuggestion: Equatable { self = .setupLoginEmail case "SETUP_LOGIN_EMAIL_NOSKIP": self = .setupLoginEmailBlocking + case "SETUP_PASSKEY": + self = .setupPasskey default: return nil } @@ -95,6 +98,8 @@ public enum ServerProvidedSuggestion: Equatable { return "SETUP_LOGIN_EMAIL" case .setupLoginEmailBlocking: return "SETUP_LOGIN_EMAIL_NOSKIP" + case .setupPasskey: + return "SETUP_PASSKEY" case let .link(id, _, _, _): return id } diff --git a/submodules/TelegramUI/BUILD b/submodules/TelegramUI/BUILD index cb1458551a..f367043c06 100644 --- a/submodules/TelegramUI/BUILD +++ b/submodules/TelegramUI/BUILD @@ -498,6 +498,7 @@ swift_library( "//submodules/TelegramUI/Components/AttachmentFileController", "//submodules/TelegramUI/Components/Contacts/NewContactScreen", "//submodules/TelegramUI/Components/Chat/ChatSendAsContextMenu", + "//submodules/TelegramUI/Components/Settings/PasskeysScreen", ] + select({ "@build_bazel_rules_apple//apple:ios_arm64": appcenter_targets, "//build-system:ios_sim_arm64": [], diff --git a/submodules/TelegramUI/Components/Settings/PasskeysScreen/Sources/PasskeysScreen.swift b/submodules/TelegramUI/Components/Settings/PasskeysScreen/Sources/PasskeysScreen.swift index 06d143f3de..616c52ba4e 100644 --- a/submodules/TelegramUI/Components/Settings/PasskeysScreen/Sources/PasskeysScreen.swift +++ b/submodules/TelegramUI/Components/Settings/PasskeysScreen/Sources/PasskeysScreen.swift @@ -19,17 +19,26 @@ final class PasskeysScreenComponent: Component { typealias EnvironmentType = ViewControllerComponentContainer.Environment let context: AccountContext + let displaySkip: Bool let initialPasskeysData: [TelegramPasskey]? let passkeysDataUpdated: ([TelegramPasskey]) -> Void + let completion: () -> Void + let cancel: () -> Void init( context: AccountContext, + displaySkip: Bool, initialPasskeysData: [TelegramPasskey]?, - passkeysDataUpdated: @escaping ([TelegramPasskey]) -> Void + passkeysDataUpdated: @escaping ([TelegramPasskey]) -> Void, + completion: @escaping () -> Void, + cancel: @escaping () -> Void ) { self.context = context + self.displaySkip = displaySkip self.initialPasskeysData = initialPasskeysData self.passkeysDataUpdated = passkeysDataUpdated + self.completion = completion + self.cancel = cancel } static func ==(lhs: PasskeysScreenComponent, rhs: PasskeysScreenComponent) -> Bool { @@ -353,10 +362,10 @@ final class PasskeysScreenComponent: Component { public final class PasskeysScreen: ViewControllerComponentContainer { private let context: AccountContext - public init(context: AccountContext, initialPasskeysData: [TelegramPasskey]?, passkeysDataUpdated: @escaping ([TelegramPasskey]) -> Void) async { + public init(context: AccountContext, displaySkip: Bool, initialPasskeysData: [TelegramPasskey]?, passkeysDataUpdated: @escaping ([TelegramPasskey]) -> Void, completion: @escaping () -> Void, cancel: @escaping () -> Void) async { self.context = context - super.init(context: context, component: PasskeysScreenComponent(context: context, initialPasskeysData: initialPasskeysData, passkeysDataUpdated: passkeysDataUpdated), navigationBarAppearance: .transparent) + super.init(context: context, component: PasskeysScreenComponent(context: context, displaySkip: displaySkip, initialPasskeysData: initialPasskeysData, passkeysDataUpdated: passkeysDataUpdated), navigationBarAppearance: .transparent) } required public init(coder aDecoder: NSCoder) { diff --git a/submodules/TelegramUI/Components/Settings/PasskeysScreen/Sources/PasskeysScreenIntroComponent.swift b/submodules/TelegramUI/Components/Settings/PasskeysScreen/Sources/PasskeysScreenIntroComponent.swift index 28df5748a5..352f4e6c7c 100644 --- a/submodules/TelegramUI/Components/Settings/PasskeysScreen/Sources/PasskeysScreenIntroComponent.swift +++ b/submodules/TelegramUI/Components/Settings/PasskeysScreen/Sources/PasskeysScreenIntroComponent.swift @@ -14,17 +14,20 @@ final class PasskeysScreenIntroComponent: Component { let context: AccountContext let theme: PresentationTheme let insets: UIEdgeInsets + let displaySkip: Bool let createPasskeyAction: () -> Void init( context: AccountContext, theme: PresentationTheme, insets: UIEdgeInsets, + displaySkip: Bool, createPasskeyAction: @escaping () -> Void ) { self.context = context self.theme = theme self.insets = insets + self.displaySkip = displaySkip self.createPasskeyAction = createPasskeyAction } @@ -38,6 +41,9 @@ final class PasskeysScreenIntroComponent: Component { if lhs.insets != rhs.insets { return false } + if lhs.displaySkip != rhs.displaySkip { + return false + } return true } @@ -64,6 +70,7 @@ final class PasskeysScreenIntroComponent: Component { private let title = ComponentView() private let subtitle = ComponentView() private let actionButton = ComponentView() + private var skipButton: ComponentView? private var items: [Item] = [] @@ -292,6 +299,13 @@ final class PasskeysScreenIntroComponent: Component { environment: {}, containerSize: CGSize(width: availableSize.width - buttonInsets.left - buttonInsets.right, height: 52.0) ) + + if component.displaySkip { + let skipButton: ComponentView + } else if let skipButton = self.skipButton { + self.skipButton = nil + skipButton.view?.removeFromSuperview() + } let buttonFrame = CGRect(origin: CGPoint(x: buttonInsets.left, y: availableSize.height - buttonInsets.bottom - actionButtonSize.height), size: actionButtonSize) diff --git a/submodules/TelegramUI/Sources/SharedAccountContext.swift b/submodules/TelegramUI/Sources/SharedAccountContext.swift index ccf460e4a0..10c53cd312 100644 --- a/submodules/TelegramUI/Sources/SharedAccountContext.swift +++ b/submodules/TelegramUI/Sources/SharedAccountContext.swift @@ -90,6 +90,7 @@ import ForumCreateTopicScreen import GlassBackgroundComponent import AttachmentFileController import NewContactScreen +import PasskeysScreen private final class AccountUserInterfaceInUseContext { let subscribers = Bag<(Bool) -> Void>() @@ -4063,6 +4064,10 @@ public final class SharedAccountContextImpl: SharedAccountContext { public func makeLoginEmailSetupController(context: AccountContext, blocking: Bool, emailPattern: String?, canAutoDismissIfNeeded: Bool, navigationController: NavigationController?, completion: @escaping () -> Void, dismiss: @escaping () -> Void) -> ViewController { return loginEmailSetupController(context: context, blocking: blocking, emailPattern: emailPattern, canAutoDismissIfNeeded: canAutoDismissIfNeeded, navigationController: navigationController, completion: completion, dismiss: dismiss) } + + public func makePasskeySetupController(context: AccountContext, displaySkip: Bool, navigationController: NavigationController?, completion: @escaping () -> Void, dismiss: completion: @escaping () -> Void) -> ViewController { + return PasskeysScreen(context: context, displaySkip: displaySkip, initialPasskeysData: nil, passkeysDataUpdated: { _ in }, completion: completion, cancel: dismiss) + } } private func peerInfoControllerImpl(context: AccountContext, updatedPresentationData: (PresentationData, Signal)?, peer: Peer, mode: PeerInfoControllerMode, avatarInitiallyExpanded: Bool, isOpenedFromChat: Bool, requestsContext: PeerInvitationImportersContext? = nil) -> ViewController? {