1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import Foundation
import SwiftUI
extension AppModel {
func visibleNotifications(in notifications: [FeedNotification]) -> [FeedNotification] {
notifications.filter { notification in
guard !isHidden(notification.author.id), !isHidden(notification.relatedPost?.author.id),
!isHidden(notification.parentPost?.author.id),
let authorDecision = contentDecision(author: notification.author),
!authorDecision.contentList.filter, !authorDecision.contentList.blur
else { return false }
return [notification.relatedPost, notification.parentPost].compactMap { $0 }.allSatisfy { post in
guard let decision = contentDecision(for: post) else { return false }
return decision.action != .hide
}
}
}
func filteredTimelinePosts() -> [Post] {
filteredFeedPosts(
posts.filter { timelinePostIDs.contains($0.id) }, contexts: replyContexts, reposts: repostedBy)
}
func filteredFeedPosts(
_ feedPosts: [Post], contexts: [String: [Post]], reposts: [String: Post.Author],
stagedPosts: [String: Post] = [:]
) -> [Post] {
TimelinePolicy.filter(
feedPosts,
contexts: contexts,
reposts: reposts,
includeUnfollowedReplies: induceADHD,
visibility: TimelinePolicy.Visibility(
canShow: { self.canShowTimelineItem($0, stagedPosts: stagedPosts) },
canShowRepostAuthor: isRepostAuthorVisible,
follows: follows
))
}
func follows(_ author: Post.Author) -> Bool {
author.id == account?.id
|| (followResults[author.id] ?? (author.isFollowing || followingActorIDs.contains(author.id)))
}
func canShowTimelineItem(_ post: Post, stagedPosts: [String: Post] = [:]) -> Bool {
guard canShowTimelineContent(post, stagedPosts: stagedPosts) else { return false }
guard let quote = post.quote else { return true }
let fallback = stagedPosts[quote.postID] ?? self.post(id: quote.postID)
guard !isHidden(quote.author?.id ?? fallback?.author.id) else { return true }
guard let decision = quoteContentDecision(quote, fallbackPost: fallback) else { return true }
guard decision.action != .hide, !decision.contentList.filter, !decision.contentList.blur else { return false }
let hasMedia: Bool
if quote.author == nil, let fallback {
hasMedia =
!fallback.imageURLs.isEmpty || !fallback.videoURLs.isEmpty || !fallback.gifURLs.isEmpty
|| !fallback.inlineGIFVideoURLs.isEmpty || !fallback.pendingImages.isEmpty
} else {
hasMedia =
!quote.imageURLs.isEmpty || !quote.videoURLs.isEmpty || !quote.gifURLs.isEmpty
|| !quote.inlineGIFVideoURLs.isEmpty
}
return !hasMedia || !decision.contentMedia.blur || decision.allMediaBlursAreAdultWarnings
}
func canShowTimelineContent(_ post: Post, stagedPosts: [String: Post] = [:]) -> Bool {
guard !isHidden(post.author.id), let decision = contentDecision(for: post, stagedPosts: stagedPosts),
!decision.ui(.contentList).filter, !decision.ui(.contentList).blur,
decision.action != .hide
else { return false }
let hasMedia =
!post.pendingImages.isEmpty || !post.imageURLs.isEmpty || !post.gifURLs.isEmpty
|| !post.inlineGIFVideoURLs.isEmpty || !post.videoURLs.isEmpty
return !hasMedia || !decision.ui(.contentMedia).blur || decision.allMediaBlursAreAdultWarnings
}
}