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

geesawra.industries/old-fella

Old people's social media app

0
1
main
220 lines · 12.6 KB Raw History
import Foundation
import UIKit

extension MockBlueskyService {
    var firstPage: [Post] { initialPosts.map(withInteractions) }

    var initialPosts: [Post] {
        if usesRichScrollFixture { return richScrollFixture.posts }
        if ProcessInfo.processInfo.arguments.contains("-ui-testing-post-targets") { return postTargetFixture }
        var posts = [
            Post(
                id: "post-1", author: authors[0],
                text: "Morning walk along the water. The light changed every few minutes.", likeCount: 18,
                repostCount: 3, isLiked: false, isReposted: false, imageURLs: [], replyIDs: ["post-2"],
                createdAt: Date(timeIntervalSince1970: 1_714_998_896)),
            Post(
                id: "post-2", author: authors[1],
                text: "A small reminder to take breaks and look away from the screen.", likeCount: 42, repostCount: 8,
                isLiked: false, isReposted: false, imageURLs: [], replyRootURI: "post-1", replyRootCID: "",
                replyParentURI: "post-1", replyParentCID: "", replyIDs: []),
            Post(
                id: "post-3", author: authors[2], text: "This is a quote post. Open the link to read the original.",
                likeCount: 7, repostCount: 1, isLiked: false, isReposted: false, imageURLs: [],
                quote: Post.Quote(postID: "post-2"), replyIDs: [])
        ]
        if ProcessInfo.processInfo.arguments.contains("-ui-testing-image-scroll") {
            let encodedImage = Self.imageGridPNGData.base64EncodedString()
            return (0..<24).map { index in
                let imageURL = URL(string: "data:image/png;name=scroll-image-\(index);base64,\(encodedImage)")!
                return Post(
                    id: "image-scroll-\(index)", author: authors[index % authors.count],
                    text: "Image \(index + 1)", likeCount: 0, repostCount: 0,
                    isLiked: false, isReposted: false, imageURLs: [imageURL], replyIDs: [])
            }
        }
        if ProcessInfo.processInfo.arguments.contains("-ui-testing-adult-media") {
            posts[0].moderationLabels = [.init(value: "porn", sourceDID: ModerationPolicy.defaultLabelerDID)]
            posts[0].imageURLs = [URL(string: "data:image/png;base64,\(Self.imageGridPNGData.base64EncodedString())")!]
            posts[1].replyRootURI = nil
            posts[1].replyParentURI = nil
        }
        if ProcessInfo.processInfo.arguments.contains("-ui-testing-info-label") {
            posts[0].moderationLabels = [.init(value: "scam", sourceDID: posts[0].author.id)]
        }
        if ProcessInfo.processInfo.arguments.contains("-ui-testing-content-warnings") {
            let warning = ModerationPolicy.Label(value: "!warn", sourceDID: ModerationPolicy.defaultLabelerDID)
            if ProcessInfo.processInfo.arguments.contains("-ui-testing-notification-warning") {
                posts[0].moderationLabels = [warning]
            } else {
                posts[0].quote = Post.Quote(
                    postID: "warning-quote", author: authors[2], text: "A quoted post with a warning.",
                    moderationLabels: [warning])
                posts[1].replyRootURI = nil
                posts[1].replyParentURI = nil
            }
        }
        if ProcessInfo.processInfo.arguments.contains("-ui-testing-reply-attribution") {
            posts.insert(
                Post(
                    id: "attribution-selected", author: authors[2], text: "The latest reply.", likeCount: 0,
                    repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyRootURI: "post-1",
                    replyParentURI: "post-2", replyIDs: []), at: 0)
        }
        if ProcessInfo.processInfo.arguments.contains("-ui-testing-context-quote") {
            posts[0].text =
                "A thread starts here with enough text to wrap across several lines. "
                + "This text must stay above the quoted post."
            posts[0].quote = Post.Quote(postID: "post-3", author: authors[2], text: "The quoted post.")
            posts[0].author.isFollowing = true
            posts[1].author.isFollowing = true
            posts.swapAt(0, 1)
        }
        if ProcessInfo.processInfo.arguments.contains("-ui-testing-share") {
            posts.insert(
                Post(
                    id: "at://did:plc:sharetest/app.bsky.feed.post/abc123", author: authors[0],
                    text: "A post to share.", likeCount: 0, repostCount: 0, isLiked: false, isReposted: false,
                    imageURLs: [], replyIDs: []), at: 0)
        }
        if ProcessInfo.processInfo.arguments.contains("-ui-testing-own-post") {
            let author = Post.Author(id: account.id, name: account.displayName, handle: account.handle)
            posts.insert(
                Post(
                    id: "at://\(account.id)/app.bsky.feed.post/own123", author: author,
                    text: "My post to share and delete.", likeCount: 0, repostCount: 0, isLiked: false,
                    isReposted: false, imageURLs: [], replyIDs: []), at: 0)
        }
        if ProcessInfo.processInfo.arguments.contains("-ui-testing-facets") {
            let rootText =
                "Root context: @alex.example shared https://oldsky.app/post?uri=post-2 and https://example.com/reply."
            posts[0].text = rootText
            posts[0].facets = [
                Self.mockFacet(in: rootText, matching: "@alex.example", feature: .mention("alex")),
                Self.mockFacet(
                    in: rootText, matching: "https://oldsky.app/post?uri=post-2",
                    feature: .link(URL(string: "https://oldsky.app/post?uri=post-2")!)),
                Self.mockFacet(
                    in: rootText, matching: "https://example.com/reply",
                    feature: .link(URL(string: "https://example.com/reply")!))
            ]

            let quotedText =
                "Quoted context: @mae.example shared https://oldsky.app/post?uri=post-1 and https://example.com/quote."
            posts[2].quote = Post.Quote(
                postID: "post-2",
                author: authors[1],
                text: quotedText,
                facets: [
                    Self.mockFacet(in: quotedText, matching: "@mae.example", feature: .mention("mae")),
                    Self.mockFacet(
                        in: quotedText, matching: "https://oldsky.app/post?uri=post-1",
                        feature: .link(URL(string: "https://oldsky.app/post?uri=post-1")!)),
                    Self.mockFacet(
                        in: quotedText, matching: "https://example.com/quote",
                        feature: .link(URL(string: "https://example.com/quote")!))
                ]
            )
            posts[0].author.isFollowing = true
            posts[1].author.isFollowing = true
            posts.swapAt(0, 1)
        }
        if ProcessInfo.processInfo.arguments.contains("-ui-testing-gif") {
            let image = URL(
                string:
                    "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAAAAAAALAAAAAABAAEAAAIBRAAh+QQAAAAA"
                    + "ACwAAAAAAQABAAACAUQAOw=="
            )!
            posts[0].gifURLs = [image]
            posts[0].imageDescriptions[image] = "A moving square."
            posts[1].imageURLs = [image]
            posts[1].gifURLs = [image]
            posts[0].quote = Post.Quote(postID: "post-2", author: authors[1], text: "Quoted GIF", gifURLs: [image])
        }
        if ProcessInfo.processInfo.arguments.contains("-ui-testing-video") {
            posts[0].videoURLs = [URL(fileURLWithPath: "/ui-test-missing-video.mp4")]
        }
        if ProcessInfo.processInfo.arguments.contains("-ui-testing-link-only") {
            posts.insert(
                Post(
                    id: "link-only", author: authors[0], text: " \n ", likeCount: 0, repostCount: 0, isLiked: false,
                    isReposted: false, imageURLs: [], links: [URL(string: "https://example.com/article")!], replyIDs: []
                ), at: 0)
            return posts
        }
        if let imageCount = imageGridImageCount {
            let encodedImage = Self.imageGridPNGData.base64EncodedString()
            posts[0].imageURLs = (1...imageCount).compactMap {
                URL(string: "data:image/png;name=ui-test-image-\($0);base64,\(encodedImage)")
            }
            if ProcessInfo.processInfo.arguments.contains("-ui-testing-image-quality") {
                let data = ProcessInfo.processInfo.arguments.contains("-ui-testing-image-failure")
                    ? Data("invalid".utf8) : Self.viewerPNGData
                let thumbnails = posts[0].imageURLs
                posts[0].imageURLs = thumbnails.indices.map { index in
                    URL(string: "data:image/png;name=viewer-\(index);base64,\(data.base64EncodedString())")!
                }
                posts[0].imageThumbnailURLs = Dictionary(uniqueKeysWithValues: zip(posts[0].imageURLs, thumbnails))
            }
            if let first = posts[0].imageURLs.first {
                posts[0].imageDescriptions[first] = "A blue square."
            }
            if ProcessInfo.processInfo.arguments.contains("-ui-testing-image-grid-reply-context") {
                posts[0].author.isFollowing = true
                posts[1].author.isFollowing = true
                posts.swapAt(0, 1)
            }
            return posts
        }
        guard replyBranchesEnabled else { return posts }

        posts[0].replyIDs = ["post-2", "post-branch-a", "post-branch-b", "post-branch-child"]
        posts.append(contentsOf: [
            Post(
                id: "post-gap", author: authors[1], text: "A reply after a longer conversation.", likeCount: 0,
                repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyRootURI: "post-1",
                replyParentURI: "post-gap-parent", replyIDs: []),
            Post(
                id: "post-gap-parent", author: authors[2], text: "A later reply in the conversation.", likeCount: 0,
                repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyRootURI: "post-1",
                replyParentURI: "post-gap-middle", replyIDs: []),
            Post(
                id: "post-branch-a", author: authors[1], text: "A separate conversation starts here.", likeCount: 0,
                repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyRootURI: "post-1",
                replyParentURI: "post-1", replyIDs: ["post-branch-child"], replyCount: 1),
            Post(
                id: "post-branch-b", author: authors[2], text: "Another separate conversation starts here.",
                likeCount: 0, repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyRootURI: "post-1",
                replyParentURI: "post-1", replyIDs: [], replyCount: 0),
            Post(
                id: "post-branch-child", author: authors[0], text: "A direct reply in the first separate conversation.",
                likeCount: 0, repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyRootURI: "post-1",
                replyParentURI: "post-branch-a", replyIDs: [])
        ])
        if ProcessInfo.processInfo.arguments.contains("-ui-testing-thread-gap-link"),
            let index = posts.firstIndex(where: { $0.id == "post-gap-parent" }) {
            posts[index].links = [URL(string: "https://example.invalid/thread")!]
            for index in posts.indices { posts[index].author.isFollowing = true }
        }
        if ProcessInfo.processInfo.arguments.contains("-ui-testing-long-reply-branch") {
            posts.append(
                contentsOf: (1...9).map { index in
                    Post(
                        id: "post-branch-preview-\(index)", author: authors[1], text: "Reply \(index) in this branch.",
                        likeCount: 0, repostCount: 0, isLiked: false, isReposted: false, imageURLs: [],
                        replyRootURI: "post-1", replyParentURI: "post-branch-a", replyIDs: [])
                })
            posts.append(contentsOf: [
                Post(
                    id: "post-branch-sibling", author: authors[2], text: "A second reply in this branch.", likeCount: 0,
                    repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyRootURI: "post-1",
                    replyParentURI: "post-branch-a", replyIDs: []),
                Post(
                    id: "post-branch-grandchild", author: authors[1], text: "A deeper reply in this branch.",
                    likeCount: 0, repostCount: 0, isLiked: false, isReposted: false, imageURLs: [],
                    replyRootURI: "post-1", replyParentURI: "post-branch-child", replyIDs: [])
            ])
        }
        return posts
    }
}