Add direct status highlighting (#720)

This commit is contained in:
Sean Goldin 2023-02-08 11:47:09 -06:00 committed by GitHub
parent badab0aece
commit 0c359f2b79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 7 deletions

View file

@ -55,7 +55,7 @@ public protocol AnyStatus {
} }
protocol StatusUI { protocol StatusUI {
var uiShouldHighlight: Bool? { get set } var userMentioned: Bool? { get set }
} }
public struct Status: AnyStatus, Codable, Identifiable, Equatable, Hashable, StatusUI { 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 ?? "") id + createdAt + (editedAt ?? "")
} }
public var uiShouldHighlight: Bool? public var userMentioned: Bool?
public static func == (lhs: Status, rhs: Status) -> Bool { public static func == (lhs: Status, rhs: Status) -> Bool {
lhs.id == rhs.id lhs.id == rhs.id

View file

@ -83,7 +83,7 @@ public struct StatusRowView: View {
.contextMenu { .contextMenu {
contextMenu contextMenu
} }
.listRowBackground(viewModel.shouldHighlightRow ? theme.secondaryBackgroundColor : theme.primaryBackgroundColor) .listRowBackground(viewModel.highlightRowColor)
.swipeActions(edge: .trailing) { .swipeActions(edge: .trailing) {
if !viewModel.isCompact { if !viewModel.isCompact {
trailinSwipeActions trailinSwipeActions

View file

@ -3,6 +3,8 @@ import Models
import Network import Network
import SwiftUI import SwiftUI
import DesignSystem
@MainActor @MainActor
public class StatusRowViewModel: ObservableObject { public class StatusRowViewModel: ObservableObject {
let status: Status let status: Status
@ -31,14 +33,23 @@ public class StatusRowViewModel: ObservableObject {
@Published var favoriters: [Account] = [] @Published var favoriters: [Account] = []
@Published var rebloggers: [Account] = [] @Published var rebloggers: [Account] = []
private let theme = Theme.shared
var seen = false var seen = false
var filter: Filtered? { var filter: Filtered? {
status.reblog?.filtered?.first ?? status.filtered?.first status.reblog?.filtered?.first ?? status.filtered?.first
} }
var shouldHighlightRow: Bool { var highlightRowColor: Color {
status.uiShouldHighlight != nil
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? var client: Client?

View file

@ -102,7 +102,7 @@ class TimelineViewModel: ObservableObject {
var newStatus = event.status var newStatus = event.status
if let accountId { if let accountId {
if newStatus.mentions.first(where: { $0.id == accountId }) != nil { if newStatus.mentions.first(where: { $0.id == accountId }) != nil {
newStatus.uiShouldHighlight = true newStatus.userMentioned = true
} }
} }
statuses.insert(newStatus, at: 0) statuses.insert(newStatus, at: 0)
@ -344,7 +344,7 @@ extension TimelineViewModel: StatusesFetcher {
if !statuses.isEmpty, let accountId { if !statuses.isEmpty, let accountId {
for i in statuses.indices { for i in statuses.indices {
if statuses[i].mentions.first(where: { $0.id == accountId }) != nil { if statuses[i].mentions.first(where: { $0.id == accountId }) != nil {
statuses[i].uiShouldHighlight = true statuses[i].userMentioned = true
} }
} }
} }