Fix timeline filtering + looping

This commit is contained in:
Thomas Ricouard 2024-01-01 21:06:10 +01:00
parent 6f1896caf3
commit 1e7c25993a
3 changed files with 23 additions and 12 deletions

View file

@ -35,6 +35,7 @@ public protocol AnyStatus {
var filtered: [Filtered]? { get }
var sensitive: Bool { get }
var language: String? { get }
var isHidden: Bool { get }
}
public struct StatusViewId: Hashable {
@ -84,6 +85,10 @@ public final class Status: AnyStatus, Codable, Identifiable, Equatable, Hashable
public let filtered: [Filtered]?
public let sensitive: Bool
public let language: String?
public var isHidden: Bool {
filtered?.first?.filter.filterAction == .hide
}
public init(id: String, content: HTMLString, account: Account, createdAt: ServerDate, editedAt: ServerDate?, reblog: ReblogStatus?, mediaAttachments: [MediaAttachment], mentions: [Mention], repliesCount: Int, reblogsCount: Int, favouritesCount: Int, card: Card?, favourited: Bool?, reblogged: Bool?, pinned: Bool?, bookmarked: Bool?, emojis: [Emoji], url: String?, application: Application?, inReplyToId: String?, inReplyToAccountId: String?, visibility: Visibility, poll: Poll?, spoilerText: HTMLString, filtered: [Filtered]?, sensitive: Bool, language: String?) {
self.id = id
@ -221,6 +226,10 @@ public final class ReblogStatus: AnyStatus, Codable, Identifiable, Equatable, Ha
public let filtered: [Filtered]?
public let sensitive: Bool
public let language: String?
public var isHidden: Bool {
filtered?.first?.filter.filterAction == .hide
}
public init(id: String, content: HTMLString, account: Account, createdAt: ServerDate, editedAt: ServerDate?, mediaAttachments: [MediaAttachment], mentions: [Mention], repliesCount: Int, reblogsCount: Int, favouritesCount: Int, card: Card?, favourited: Bool?, reblogged: Bool?, pinned: Bool?, bookmarked: Bool?, emojis: [Emoji], url: String?, application: Application? = nil, inReplyToId: String?, inReplyToAccountId: String?, visibility: Visibility, poll: Poll?, spoilerText: HTMLString, filtered: [Filtered]?, sensitive: Bool, language: String?) {
self.id = id

View file

@ -48,17 +48,19 @@ public struct StatusesListView<Fetcher>: View where Fetcher: StatusesFetcher {
case let .display(statuses, nextPageState):
ForEach(statuses, id: \.viewId) { status in
StatusRowView(viewModel: StatusRowViewModel(status: status,
client: client,
routerPath: routerPath,
isRemote: isRemote))
.id(status.id)
.onAppear {
fetcher.statusDidAppear(status: status)
}
.onDisappear {
fetcher.statusDidDisappear(status: status)
}
if !status.isHidden {
StatusRowView(viewModel: StatusRowViewModel(status: status,
client: client,
routerPath: routerPath,
isRemote: isRemote))
.id(status.id)
.onAppear {
fetcher.statusDidAppear(status: status)
}
.onDisappear {
fetcher.statusDidDisappear(status: status)
}
}
}
switch nextPageState {
case .hasNextPage:

View file

@ -9,7 +9,7 @@ actor TimelineDatasource {
}
func get() -> [Status] {
statuses.filter { $0.filtered?.first?.filter.filterAction != .hide }
statuses
}
func count() -> Int {