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 {
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

View file

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

View file

@ -3,6 +3,8 @@ import Models
import Network
import SwiftUI
import DesignSystem
@MainActor
public class StatusRowViewModel: ObservableObject {
let status: Status
@ -30,6 +32,8 @@ public class StatusRowViewModel: ObservableObject {
@Published var favoriters: [Account] = []
@Published var rebloggers: [Account] = []
private let theme = Theme.shared
var seen = false
@ -37,8 +41,15 @@ public class StatusRowViewModel: ObservableObject {
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?

View file

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