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

geesawra.industries/old-fella

Old people's social media app

0
1
main
79 lines · 2.2 KB Raw History
import Foundation

enum AvatarImageURL {
    static func thumbnail(_ url: URL) -> URL {
        replacingPreset(in: url, with: "avatar_thumbnail")
    }

    static func fullSize(_ url: URL) -> URL {
        replacingPreset(in: url, with: "avatar")
    }

    private static func replacingPreset(in url: URL, with preset: String) -> URL {
        guard url.scheme?.lowercased() == "https", url.host?.lowercased() == "cdn.bsky.app",
            var components = URLComponents(url: url, resolvingAgainstBaseURL: false)
        else { return url }
        let path = components.percentEncodedPath
        guard let prefix = ["/img/avatar/", "/img/avatar_thumbnail/"].first(where: path.hasPrefix) else {
            return url
        }
        components.percentEncodedPath = "/img/\(preset)/" + path.dropFirst(prefix.count)
        return components.url ?? url
    }
}

struct Account: Equatable {
    let handle: String
    private let providedDisplayName: String
    var id: String = ""
    var avatarURL: URL?
    var isAvatarURLKnown = true

    var displayName: String {
        providedDisplayName.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ? handle : providedDisplayName
    }

    init(handle: String, displayName: String, id: String = "", avatarURL: URL? = nil) {
        self.handle = handle
        self.providedDisplayName = displayName
        self.id = id
        self.avatarURL = avatarURL
    }
}

struct Profile: Equatable {
    struct Link: Equatable, Identifiable {
        let id: String
        let title: String
        let url: URL
        var moderationLabels: [ModerationPolicy.Label] = []
    }

    var author: Post.Author
    var bio: String
    let location: String?
    let website: URL?
    let followerCount: Int
    let followingCount: Int
    var isFollowing: Bool = false
    var followURI: String?
    var isFollowedBy: Bool = false
    var links: [Link] = []
}

enum ProfileConnectionKind: String, Codable {
    case followers
    case following

    var title: String {
        switch self {
        case .followers: "Followers"
        case .following: "Following"
        }
    }
}

struct ProfileConnectionsPage {
    let accounts: [Post.Author]
    let cursor: String?
}