Add direct status highlighting (#720)
This commit is contained in:
parent
badab0aece
commit
0c359f2b79
|
@ -55,7 +55,7 @@ public protocol AnyStatus {
|
|||
}
|
||||
|
||||
protocol StatusUI {
|
||||
var uiShouldHighlight: Bool? { get set }
|
||||
var userMentioned: Bool? { get set }
|
||||
}
|
||||
|
||||
public struct Status: AnyStatus, Codable, Identifiable, Equatable, Hashable, StatusUI {
|
||||
|
@ -63,7 +63,7 @@ public struct Status: AnyStatus, Codable, Identifiable, Equatable, Hashable, Sta
|
|||
id + createdAt + (editedAt ?? "")
|
||||
}
|
||||
|
||||
public var uiShouldHighlight: Bool?
|
||||
public var userMentioned: Bool?
|
||||
|
||||
public static func == (lhs: Status, rhs: Status) -> Bool {
|
||||
lhs.id == rhs.id
|
||||
|
|
|
@ -83,7 +83,7 @@ public struct StatusRowView: View {
|
|||
.contextMenu {
|
||||
contextMenu
|
||||
}
|
||||
.listRowBackground(viewModel.shouldHighlightRow ? theme.secondaryBackgroundColor : theme.primaryBackgroundColor)
|
||||
.listRowBackground(viewModel.highlightRowColor)
|
||||
.swipeActions(edge: .trailing) {
|
||||
if !viewModel.isCompact {
|
||||
trailinSwipeActions
|
||||
|
|
|
@ -3,6 +3,8 @@ import Models
|
|||
import Network
|
||||
import SwiftUI
|
||||
|
||||
import DesignSystem
|
||||
|
||||
@MainActor
|
||||
public class StatusRowViewModel: ObservableObject {
|
||||
let status: Status
|
||||
|
@ -31,14 +33,23 @@ public class StatusRowViewModel: ObservableObject {
|
|||
@Published var favoriters: [Account] = []
|
||||
@Published var rebloggers: [Account] = []
|
||||
|
||||
private let theme = Theme.shared
|
||||
|
||||
var seen = false
|
||||
|
||||
var filter: Filtered? {
|
||||
status.reblog?.filtered?.first ?? status.filtered?.first
|
||||
}
|
||||
|
||||
var shouldHighlightRow: Bool {
|
||||
status.uiShouldHighlight != nil
|
||||
var highlightRowColor: Color {
|
||||
|
||||
if status.visibility == .direct {
|
||||
return theme.tintColor.opacity(0.15)
|
||||
} else if status.userMentioned != nil {
|
||||
return theme.secondaryBackgroundColor
|
||||
} else {
|
||||
return theme.primaryBackgroundColor
|
||||
}
|
||||
}
|
||||
|
||||
var client: Client?
|
||||
|
|
|
@ -102,7 +102,7 @@ class TimelineViewModel: ObservableObject {
|
|||
var newStatus = event.status
|
||||
if let accountId {
|
||||
if newStatus.mentions.first(where: { $0.id == accountId }) != nil {
|
||||
newStatus.uiShouldHighlight = true
|
||||
newStatus.userMentioned = true
|
||||
}
|
||||
}
|
||||
statuses.insert(newStatus, at: 0)
|
||||
|
@ -344,7 +344,7 @@ extension TimelineViewModel: StatusesFetcher {
|
|||
if !statuses.isEmpty, let accountId {
|
||||
for i in statuses.indices {
|
||||
if statuses[i].mentions.first(where: { $0.id == accountId }) != nil {
|
||||
statuses[i].uiShouldHighlight = true
|
||||
statuses[i].userMentioned = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue