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

geesawra.industries/old-fella

Old people's social media app

0
1
main
62 lines · 1.5 KB Raw History
import Foundation

struct ThreadPosition: Equatable, Sendable {
    let index: Int
    let count: Int

    init?(index: Int, count: Int) {
        guard count > 1, index > 0, index <= count else { return nil }
        self.index = index
        self.count = count
    }
}

struct ThreadResult {
    let posts: [Post]
    let mutedPostIDs: Set<String>
    let positions: [String: ThreadPosition]

    init(posts: [Post], mutedPostIDs: Set<String>, positions: [String: ThreadPosition] = [:]) {
        self.posts = posts
        self.mutedPostIDs = mutedPostIDs
        self.positions = positions
    }
}

struct CustomFeed: Identifiable, Codable, Equatable, Sendable {
    let id: String
    let name: String
    let avatarURL: URL?
}

enum TimelineFeedID: Hashable {
    case following
    case custom(String)

    init(_ feed: CustomFeed?) {
        self = feed.map { .custom($0.id) } ?? .following
    }
}

enum CustomFeedError: Error {
    case unavailable
}

struct FeedPage: Equatable, Sendable {
    let posts: [Post]
    let cursor: String?
    let replyContexts: [String: [Post]]
    let repostedBy: [String: Post.Author]
    let mutedPostIDs: Set<String>

    init(
        posts: [Post], cursor: String?, replyContexts: [String: [Post]] = [:], repostedBy: [String: Post.Author] = [:],
        mutedPostIDs: Set<String> = []
    ) {
        self.posts = posts
        self.cursor = cursor
        self.replyContexts = replyContexts
        self.repostedBy = repostedBy
        self.mutedPostIDs = mutedPostIDs
    }
}