~ knotless Search/
↑↓ move↵ open⇧↵ all results

geesawra.industries/old-fella

Old people's social media app

0
1
main
75 lines · 3.6 KB Raw History
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
    }
}