Handle mentions tap in status

This commit is contained in:
Thomas Ricouard 2022-12-19 15:51:25 +01:00
parent cab21c137b
commit b47df4605d
4 changed files with 27 additions and 2 deletions

View file

@ -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
}

View file

@ -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]
}

View file

@ -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
}
}

View file

@ -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)