IOS-123: Open profiles and statuses in app (#981)
This commit is contained in:
parent
f6f90bda9d
commit
245582961b
|
@ -4,6 +4,11 @@
|
||||||
<dict>
|
<dict>
|
||||||
<key>aps-environment</key>
|
<key>aps-environment</key>
|
||||||
<string>development</string>
|
<string>development</string>
|
||||||
|
<key>com.apple.developer.associated-domains</key>
|
||||||
|
<array>
|
||||||
|
<string>applinks:mastodon.social</string>
|
||||||
|
<string>applinks:mastodon.online</string>
|
||||||
|
</array>
|
||||||
<key>com.apple.developer.siri</key>
|
<key>com.apple.developer.siri</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>com.apple.security.application-groups</key>
|
<key>com.apple.security.application-groups</key>
|
||||||
|
|
|
@ -71,6 +71,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||||
if let urlContext = connectionOptions.urlContexts.first {
|
if let urlContext = connectionOptions.urlContexts.first {
|
||||||
handleUrl(context: urlContext)
|
handleUrl(context: urlContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let userActivity = connectionOptions.userActivities.first {
|
||||||
|
handleUniversalLink(userActivity: userActivity)
|
||||||
|
}
|
||||||
|
|
||||||
#if SNAPSHOT
|
#if SNAPSHOT
|
||||||
// speedup animation
|
// speedup animation
|
||||||
|
@ -104,13 +108,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
func sceneDidDisconnect(_ scene: UIScene) {
|
|
||||||
// Called as the scene is being released by the system.
|
|
||||||
// This occurs shortly after the scene enters the background, or when its session is discarded.
|
|
||||||
// Release any resources associated with this scene that can be re-created the next time the scene connects.
|
|
||||||
// The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
|
|
||||||
}
|
|
||||||
|
|
||||||
func sceneDidBecomeActive(_ scene: UIScene) {
|
func sceneDidBecomeActive(_ scene: UIScene) {
|
||||||
// Called when the scene has moved from an inactive state to an active state.
|
// Called when the scene has moved from an inactive state to an active state.
|
||||||
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
|
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
|
||||||
|
@ -135,22 +132,68 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sceneWillResignActive(_ scene: UIScene) {
|
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
|
||||||
// Called when the scene will move from an active state to an inactive state.
|
handleUniversalLink(userActivity: userActivity)
|
||||||
// This may occur due to temporary interruptions (ex. an incoming phone call).
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func sceneWillEnterForeground(_ scene: UIScene) {
|
private func handleUniversalLink(userActivity: NSUserActivity) {
|
||||||
// Called as the scene transitions from the background to the foreground.
|
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
|
||||||
// Use this method to undo the changes made on entering the background.
|
let incomingURL = userActivity.webpageURL,
|
||||||
}
|
let components = NSURLComponents(url: incomingURL, resolvingAgainstBaseURL: true) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func sceneDidEnterBackground(_ scene: UIScene) {
|
guard let path = components.path, let authContext = coordinator?.authContext else {
|
||||||
// Called as the scene transitions from the foreground to the background.
|
return
|
||||||
// Use this method to save data, release shared resources, and store enough scene-specific state information
|
}
|
||||||
// to restore the scene back to its current state.
|
|
||||||
}
|
|
||||||
|
|
||||||
|
let pathElements = path.split(separator: "/")
|
||||||
|
|
||||||
|
let profile: String?
|
||||||
|
if let profileInPath = pathElements[safe: 0] {
|
||||||
|
profile = String(profileInPath)
|
||||||
|
} else {
|
||||||
|
profile = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let statusID: String?
|
||||||
|
if let statusIDInPath = pathElements[safe: 1] {
|
||||||
|
statusID = String(statusIDInPath)
|
||||||
|
} else {
|
||||||
|
statusID = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (profile, statusID) {
|
||||||
|
case (profile, nil):
|
||||||
|
let profileViewModel = RemoteProfileViewModel(
|
||||||
|
context: AppContext.shared,
|
||||||
|
authContext: authContext,
|
||||||
|
acct: incomingURL.absoluteString
|
||||||
|
)
|
||||||
|
self.coordinator?.present(
|
||||||
|
scene: .profile(viewModel: profileViewModel),
|
||||||
|
from: nil,
|
||||||
|
transition: .show
|
||||||
|
)
|
||||||
|
|
||||||
|
case (profile, statusID):
|
||||||
|
Task {
|
||||||
|
guard let statusOnMyInstance = try await AppContext.shared.apiService.search(query: .init(q: incomingURL.absoluteString, resolve: true), authenticationBox: authContext.mastodonAuthenticationBox).value.statuses.first else { return }
|
||||||
|
|
||||||
|
let threadViewModel = RemoteThreadViewModel(
|
||||||
|
context: AppContext.shared,
|
||||||
|
authContext: authContext,
|
||||||
|
statusID: statusOnMyInstance.id
|
||||||
|
)
|
||||||
|
coordinator?.present(scene: .thread(viewModel: threadViewModel), from: nil, transition: .show)
|
||||||
|
}
|
||||||
|
|
||||||
|
case (_, _):
|
||||||
|
break
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SceneDelegate {
|
extension SceneDelegate {
|
||||||
|
@ -298,3 +341,4 @@ extension SceneDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue