mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-26 10:11:00 +00:00
Fix Link Handling (#69)
This commit is contained in:
parent
66efedbbda
commit
d646fef9f4
6 changed files with 34 additions and 3 deletions
|
@ -22,12 +22,21 @@ public class CurrentAccount: ObservableObject {
|
|||
|
||||
private func fetchUserData() async {
|
||||
await withTaskGroup(of: Void.self) { group in
|
||||
group.addTask { await self.fetchConnections() }
|
||||
group.addTask { await self.fetchCurrentAccount() }
|
||||
group.addTask { await self.fetchLists() }
|
||||
group.addTask { await self.fetchFollowedTags() }
|
||||
}
|
||||
}
|
||||
|
||||
public func fetchConnections() async {
|
||||
guard let client = client else { return }
|
||||
do {
|
||||
let connections: [String] = try await client.get(endpoint: Instances.peers)
|
||||
client.addConnections(connections)
|
||||
} catch { }
|
||||
}
|
||||
|
||||
public func fetchCurrentAccount() async {
|
||||
guard let client = client, client.isAuth else {
|
||||
account = nil
|
||||
|
@ -62,7 +71,6 @@ public class CurrentAccount: ObservableObject {
|
|||
} catch { }
|
||||
}
|
||||
|
||||
|
||||
public func deleteList(list: Models.List) async {
|
||||
guard let client else { return }
|
||||
lists.removeAll(where: { $0.id == list.id })
|
||||
|
|
|
@ -66,6 +66,8 @@ public class RouterPath: ObservableObject {
|
|||
navigate(to: .accountDetail(id: mention.id))
|
||||
return .handled
|
||||
} else if let client = client,
|
||||
client.isAuth,
|
||||
client.hasConnection(with: url),
|
||||
let id = Int(url.lastPathComponent) {
|
||||
if url.absoluteString.contains(client.server) {
|
||||
navigate(to: .statusDetail(id: String(id)))
|
||||
|
|
|
@ -20,6 +20,7 @@ public class Client: ObservableObject, Equatable {
|
|||
|
||||
public var server: String
|
||||
public let version: Version
|
||||
public private(set) var connections: Set<String>
|
||||
private let urlSession: URLSession
|
||||
private let decoder = JSONDecoder()
|
||||
|
||||
|
@ -38,8 +39,20 @@ public class Client: ObservableObject, Equatable {
|
|||
self.urlSession = URLSession.shared
|
||||
self.decoder.keyDecodingStrategy = .convertFromSnakeCase
|
||||
self.oauthToken = oauthToken
|
||||
self.connections = Set([server])
|
||||
}
|
||||
|
||||
public func addConnections(_ connections: [String]) {
|
||||
connections.forEach {
|
||||
self.connections.insert($0)
|
||||
}
|
||||
}
|
||||
|
||||
public func hasConnection(with url: URL) -> Bool {
|
||||
guard let host = url.host(percentEncoded: false) else { return false }
|
||||
return connections.contains(host)
|
||||
}
|
||||
|
||||
private func makeURL(scheme: String = "https", endpoint: Endpoint, forceVersion: Version? = nil) -> URL {
|
||||
var components = URLComponents()
|
||||
components.scheme = scheme
|
||||
|
|
|
@ -2,11 +2,14 @@ import Foundation
|
|||
|
||||
public enum Instances: Endpoint {
|
||||
case instance
|
||||
case peers
|
||||
|
||||
public func path() -> String {
|
||||
switch self {
|
||||
case .instance:
|
||||
return "instance"
|
||||
case .peers:
|
||||
return "instance/peers"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ public struct StatusDetailView: View {
|
|||
@EnvironmentObject private var watcher: StreamWatcher
|
||||
@EnvironmentObject private var client: Client
|
||||
@EnvironmentObject private var routeurPath: RouterPath
|
||||
@Environment(\.openURL) private var openURL
|
||||
@StateObject private var viewModel: StatusDetailViewModel
|
||||
@State private var isLoaded: Bool = false
|
||||
|
||||
|
@ -81,7 +82,12 @@ public struct StatusDetailView: View {
|
|||
viewModel.client = client
|
||||
let result = await viewModel.fetch()
|
||||
if !result {
|
||||
_ = routeurPath.path.popLast()
|
||||
if let url = viewModel.remoteStatusURL {
|
||||
openURL(url)
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
_ = routeurPath.path.popLast()
|
||||
}
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
proxy.scrollTo(viewModel.statusId, anchor: .center)
|
||||
|
|
|
@ -51,7 +51,6 @@ class StatusDetailViewModel: ObservableObject {
|
|||
await fetchStatusDetail()
|
||||
return true
|
||||
} else {
|
||||
await UIApplication.shared.open(remoteStatusURL)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue