Status visibility

This commit is contained in:
Thomas Ricouard 2022-12-27 14:20:00 +01:00
parent ee39840713
commit afbdd45e48
4 changed files with 42 additions and 2 deletions

View file

@ -5,6 +5,14 @@ public struct Application: Codable, Identifiable {
name
}
public let name: String
public let website: URL?
}
public enum Visibility: String, Codable {
case pub = "public"
case unlisted
case priv = "private"
case direct
}
public protocol AnyStatus {
@ -27,6 +35,7 @@ public protocol AnyStatus {
var url: URL? { get }
var application: Application? { get }
var inReplyToAccountId: String? { get }
var visibility: Visibility { get }
}
@ -54,6 +63,7 @@ public struct Status: AnyStatus, Codable, Identifiable {
public let url: URL?
public let application: Application?
public let inReplyToAccountId: String?
public let visibility: Visibility
public static func placeholder() -> Status {
.init(id: UUID().uuidString,
@ -74,7 +84,8 @@ public struct Status: AnyStatus, Codable, Identifiable {
emojis: [],
url: nil,
application: nil,
inReplyToAccountId: nil)
inReplyToAccountId: nil,
visibility: .pub)
}
public static func placeholders() -> [Status] {
@ -105,4 +116,5 @@ public struct ReblogStatus: AnyStatus, Codable, Identifiable {
public let url: URL?
public var application: Application?
public let inReplyToAccountId: String?
public let visibility: Visibility
}

View file

@ -0,0 +1,16 @@
import Models
extension Visibility {
public var iconName: String {
switch self {
case .pub:
return "globe.americas"
case .unlisted:
return "lock.open"
case .priv:
return "lock"
case .direct:
return "at.circle"
}
}
}

View file

@ -5,6 +5,7 @@ import Network
import DesignSystem
struct StatusActionsView: View {
@Environment(\.openURL) private var openURL
@EnvironmentObject private var routeurPath: RouterPath
@ObservedObject var viewModel: StatusRowViewModel
@ -91,10 +92,19 @@ struct StatusActionsView: View {
HStack {
Text(viewModel.status.createdAt.asDate, style: .date)
Text(viewModel.status.createdAt.asDate, style: .time)
Text("·")
Image(systemName: viewModel.status.visibility.iconName)
Spacer()
Text(viewModel.status.application?.name ?? "")
.underline()
.onTapGesture {
if let url = viewModel.status.application?.website {
openURL(url)
}
}
}
.font(.caption)
.foregroundColor(.gray)
if viewModel.favouritesCount > 0 {
Divider()
Button {

View file

@ -141,7 +141,9 @@ public struct StatusRowView: View {
Group {
Text("@\(status.account.acct)") +
Text("") +
Text(status.createdAt.formatted)
Text(status.createdAt.formatted) +
Text("") +
Text(Image(systemName: viewModel.status.visibility.iconName))
}
.font(.footnote)
.foregroundColor(.gray)