Handle mentions tap in status
This commit is contained in:
parent
cab21c137b
commit
b47df4605d
|
@ -0,0 +1,8 @@
|
|||
import Foundation
|
||||
|
||||
public struct Mention: Codable {
|
||||
public let id: String
|
||||
public let username: String
|
||||
public let url: URL
|
||||
public let acct: String
|
||||
}
|
|
@ -6,6 +6,7 @@ public protocol AnyStatus {
|
|||
var account: Account { get }
|
||||
var createdAt: String { get }
|
||||
var mediaAttachments: [MediaAttachement] { get }
|
||||
var mentions: [Mention] { get }
|
||||
}
|
||||
|
||||
public struct Status: AnyStatus, Codable, Identifiable {
|
||||
|
@ -15,6 +16,7 @@ public struct Status: AnyStatus, Codable, Identifiable {
|
|||
public let createdAt: ServerDate
|
||||
public let reblog: ReblogStatus?
|
||||
public let mediaAttachments: [MediaAttachement]
|
||||
public let mentions: [Mention]
|
||||
|
||||
public static func placeholder() -> Status {
|
||||
.init(id: UUID().uuidString,
|
||||
|
@ -22,7 +24,8 @@ public struct Status: AnyStatus, Codable, Identifiable {
|
|||
account: .placeholder(),
|
||||
createdAt: "2022-12-16T10:20:54.000Z",
|
||||
reblog: nil,
|
||||
mediaAttachments: [])
|
||||
mediaAttachments: [],
|
||||
mentions: [])
|
||||
}
|
||||
|
||||
public static func placeholders() -> [Status] {
|
||||
|
@ -36,4 +39,5 @@ public struct ReblogStatus: AnyStatus, Codable, Identifiable {
|
|||
public let account: Account
|
||||
public let createdAt: String
|
||||
public let mediaAttachments: [MediaAttachement]
|
||||
public let mentions: [Mention]
|
||||
}
|
||||
|
|
|
@ -16,4 +16,12 @@ public class RouterPath: ObservableObject {
|
|||
public func navigate(to: RouteurDestinations) {
|
||||
path.append(to)
|
||||
}
|
||||
|
||||
public func handleStatus(status: AnyStatus, url: URL) -> OpenURLAction.Result {
|
||||
if let mention = status.mentions.first(where: { $0.url == url }) {
|
||||
navigate(to: .accountDetail(id: mention.id))
|
||||
return .handled
|
||||
}
|
||||
return .systemAction
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,11 @@ import SwiftUI
|
|||
import Models
|
||||
import Routeur
|
||||
import DesignSystem
|
||||
import Network
|
||||
|
||||
public struct StatusRowView: View {
|
||||
@Environment(\.redactionReasons) private var reasons
|
||||
@EnvironmentObject private var client: Client
|
||||
@EnvironmentObject private var routeurPath: RouterPath
|
||||
|
||||
private let status: Status
|
||||
|
@ -48,11 +50,14 @@ public struct StatusRowView: View {
|
|||
}.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
Text(try! AttributedString(markdown: status.content.asMarkdown))
|
||||
Text(status.content.asSafeAttributedString)
|
||||
.font(.body)
|
||||
.onTapGesture {
|
||||
routeurPath.navigate(to: .statusDetail(id: status.id))
|
||||
}
|
||||
.environment(\.openURL, OpenURLAction { url in
|
||||
routeurPath.handleStatus(status: status, url: url)
|
||||
})
|
||||
|
||||
if !status.mediaAttachments.isEmpty {
|
||||
StatusMediaPreviewView(attachements: status.mediaAttachments)
|
||||
|
|
Loading…
Reference in New Issue