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

geesawra.industries/old-fella

Old people's social media app

0
1
main
103 lines · 6.0 KB Raw History
import Foundation

protocol BlueskyService {
    func restoreAccount() async throws -> Account?
    func restoreAccount(onLocalAccount: @MainActor @Sendable (String) -> Void) async throws -> Account?
    func signIn(handle: String, appPassword: String, authFactorToken: String?) async throws -> Account
    func signOut() async throws
    func loadFollowingFeed(cursor: String?) async throws -> FeedPage
    func searchAccounts(query: String, cursor: String?) async throws -> AccountSearchPage
    func suggestAccounts(query: String) async throws -> [Post.Author]
    func searchPosts(query: String, cursor: String?, authorID: String?) async throws -> FeedPage
    func loadSubscribedFeeds() async throws -> [CustomFeed]
    func loadCustomFeed(uri: String, cursor: String?) async throws -> FeedPage
    func loadNotifications(cursor: String?) async throws -> NotificationPage
    func markNotificationsRead(seenAt: Date) async throws
    func loadPost(uri: String) async throws -> [Post]
    func loadThread(uri: String) async throws -> ThreadResult
    func loadProfile(actorID: String) async throws -> Profile?
    func loadProfileConnections(actorID: String, kind: ProfileConnectionKind, cursor: String?) async throws
        -> ProfileConnectionsPage
    func loadProfileEdit(accountID: String) async throws -> EditableProfile
    func saveProfileEdit(_ draft: ProfileEdit, original: EditableProfile, accountID: String) async throws
        -> ProfileEditResult
    func loadAuthorPosts(actorID: String, cursor: String?) async throws -> FeedPage
    func loadSavedPosts(cursor: String?) async throws -> FeedPage
    func setPostSaved(_ saved: Bool, post: Post) async throws
    func toggleLike(post: Post, liked: Bool) async throws -> String?
    func toggleRepost(post: Post, reposted: Bool) async throws -> String?
    func deletePost(_ post: Post) async throws
    func publish(text: String, replyTo: Post?, quotePost: Post?, images: [ImageAttachment]) async throws -> Post
    func publish(text: String, replyTo: Post?, quotePost: Post?, images: [ImageAttachment], video: VideoAttachment?)
        async throws -> Post
    func loadDrafts(cursor: String?) async throws -> SavedPostDraftPage
    func loadDraft(id: String) async throws -> ComposerDraft
    func saveDraft(_ draft: ComposerDraft, id: String?) async throws -> String
    func deleteDraft(id: String) async throws
    func setFollowing(_ following: Bool, actorID: String) async throws -> String?
    func loadModerationPreferences() async throws -> ModerationPolicy.Preferences
    func moderationState(actorID: String) async throws -> ModerationState
    func setMuted(_ muted: Bool, actorID: String) async throws
    func setBlocked(_ blocked: Bool, actorID: String, blockURI: String?) async throws -> String?
    func report(_ subject: ReportSubject, reason: String) async throws
}

extension BlueskyService {
    func restoreAccount(onLocalAccount: @MainActor @Sendable (String) -> Void) async throws -> Account? {
        try await restoreAccount()
    }

    func loadProfileConnections(actorID: String, kind: ProfileConnectionKind, cursor: String?) async throws
        -> ProfileConnectionsPage {
        throw ServiceError.invalidResponse
    }

    func loadProfileEdit(accountID: String) async throws -> EditableProfile { throw ServiceError.profileUnavailable }
    func saveProfileEdit(_ draft: ProfileEdit, original: EditableProfile, accountID: String) async throws
        -> ProfileEditResult {
        throw ServiceError.profileUnavailable
    }

    func loadSavedPosts(cursor: String?) async throws -> FeedPage { throw ServiceError.invalidResponse }
    func setPostSaved(_ saved: Bool, post: Post) async throws { throw ServiceError.invalidResponse }

    func loadDrafts(cursor: String?) async throws -> SavedPostDraftPage {
        throw SavedPostDraftError.unavailable("Drafts are unavailable. Try again.")
    }
    func loadDraft(id: String) async throws -> ComposerDraft {
        throw SavedPostDraftError.unavailable("This draft is unavailable. Try again.")
    }
    func saveDraft(_ draft: ComposerDraft, id: String?) async throws -> String {
        throw SavedPostDraftError.unavailable("The draft could not be saved. Try again.")
    }
    func deleteDraft(id: String) async throws {
        throw SavedPostDraftError.unavailable("The draft could not be deleted. Try again.")
    }
    func publish(text: String, replyTo: Post?, quotePost: Post?, images: [ImageAttachment], video: VideoAttachment?)
        async throws -> Post {
        guard video == nil else { throw ServiceError.videoUploadUnavailable }
        return try await publish(text: text, replyTo: replyTo, quotePost: quotePost, images: images)
    }
    func suggestAccounts(query: String) async throws -> [Post.Author] {
        try await searchAccounts(query: query, cursor: nil).accounts
    }
    func searchAccounts(query: String, cursor: String?) async throws -> AccountSearchPage {
        throw ServiceError.invalidResponse
    }
    func searchPosts(query: String, cursor: String?, authorID: String? = nil) async throws -> FeedPage {
        throw ServiceError.invalidResponse
    }
    func loadSubscribedFeeds() async throws -> [CustomFeed] { [] }
    func loadCustomFeed(uri: String, cursor: String?) async throws -> FeedPage { throw CustomFeedError.unavailable }
    func deletePost(_ post: Post) async throws { throw ServiceError.invalidResponse }
    func loadModerationPreferences() async throws -> ModerationPolicy.Preferences { throw ServiceError.invalidResponse }
    func moderationState(actorID: String) async throws -> ModerationState { throw ServiceError.invalidResponse }
    func setMuted(_ muted: Bool, actorID: String) async throws { throw ServiceError.invalidResponse }
    func setBlocked(_ blocked: Bool, actorID: String, blockURI: String?) async throws -> String? {
        throw ServiceError.invalidResponse
    }
    func report(_ subject: ReportSubject, reason: String) async throws { throw ServiceError.invalidResponse }
    func loadThread(uri: String) async throws -> ThreadResult {
        ThreadResult(posts: try await loadPost(uri: uri), mutedPostIDs: [])
    }
}