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

geesawra.industries/old-fella

Old people's social media app

0
1
main
50 lines · 2.8 KB Raw History
#if DEBUG
    import Foundation

    struct ShareTestService: BlueskyService {
        let mode: String
        let group: URL
        private let account = Account(handle: "test.example", displayName: "Test account", id: "test-account")

        func restoreAccount() async throws -> Account? { account }
        func signIn(handle: String, appPassword: String, authFactorToken: String?) async throws -> Account { account }
        func signOut() async throws {}
        func loadFollowingFeed(cursor: String?) async throws -> FeedPage { FeedPage(posts: [], cursor: nil) }
        func loadNotifications(cursor: String?) async throws -> NotificationPage { throw ServiceError.invalidResponse }
        func markNotificationsRead(seenAt: Date) async throws {}
        func loadPost(uri: String) async throws -> [Post] { [] }
        func loadProfile(actorID: String) async throws -> Profile? { nil }
        func loadAuthorPosts(actorID: String, cursor: String?) async throws -> FeedPage {
            FeedPage(posts: [], cursor: nil)
        }
        func toggleLike(post: Post, liked: Bool) async throws -> String? { nil }
        func toggleRepost(post: Post, reposted: Bool) async throws -> String? { nil }
        func setFollowing(_ following: Bool, actorID: String) async throws -> String? { nil }
        func loadModerationPreferences() async throws -> ModerationPolicy.Preferences {
            .init(userDID: account.id, labelDefinitions: ModerationPolicy.builtInDefinitions)
        }
        func publish(text: String, replyTo: Post?, quotePost: Post?, images: [ImageAttachment]) async throws -> Post {
            try await publish(text: text, replyTo: replyTo, quotePost: quotePost, images: images, video: nil)
        }
        func publish(text: String, replyTo: Post?, quotePost: Post?, images: [ImageAttachment], video: VideoAttachment?)
            async throws -> Post {
            switch mode {
            case "failure":
                throw ActionNotSentError(underlying: ServiceError.requestFailed("The post was not sent. Try again."))
            case "unknown": throw ServiceError.invalidRecordResponse
            default:
                let result: [String: Any] = [
                    "text": text, "photoCount": images.count, "photoAltTexts": images.map(\.altText),
                    "hasVideo": video != nil
                ]
                let data = try JSONSerialization.data(withJSONObject: result)
                try data.write(to: group.appendingPathComponent("ShareTestResult.json"), options: .atomic)
            }
            return Post(
                id: UUID().uuidString,
                author: Post.Author(id: account.id, name: account.displayName, handle: account.handle), text: text,
                likeCount: 0, repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyIDs: [],
                createdAt: Date())
        }
    }
#endif