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

geesawra.industries/old-fella

Old people's social media app

0
1
main
43 lines · 2.0 KB Raw History
import Foundation
import UIKit

extension MockBlueskyService {
    func loadModerationPreferences() async throws -> ModerationPolicy.Preferences {
        let arguments = ProcessInfo.processInfo.arguments
        loadState.preferenceLoadCount += 1
        if arguments.contains("-ui-testing-preferences-fail")
            || (arguments.contains("-ui-testing-preferences-refresh-fail") && loadState.preferenceLoadCount > 1) {
            throw URLError(.notConnectedToInternet)
        }
        let adult = arguments.contains("-ui-testing-adult-media")
        let setting: ModerationPolicy.LabelSetting =
            arguments.contains("-ui-testing-adult-hide")
            ? .hide : (arguments.contains("-ui-testing-adult-warn") ? .warn : .ignore)
        return .init(
            userDID: account.id, adultContentEnabled: adult && !arguments.contains("-ui-testing-adult-disabled"),
            labels: adult ? ["porn": setting] : (arguments.contains("-ui-testing-info-label") ? ["scam": .warn] : [:]),
            labelers: arguments.contains("-ui-testing-content-warnings") || adult
                ? [.init(did: ModerationPolicy.defaultLabelerDID)] : [],
            labelDefinitions: ModerationPolicy.builtInDefinitions,
            mutedWords: arguments.contains("-ui-testing-muted-word") ? [.init(value: "water")] : [])
    }

    func restoreAccount() async throws -> Account? {
        if ProcessInfo.processInfo.arguments.contains("-ui-testing-restore-delay") {
            try await Task.sleep(nanoseconds: 3_000_000_000)
        }
        return restoresAccount ? account : nil
    }

    func signIn(handle: String, appPassword: String, authFactorToken: String?) async throws -> Account {
        if requiresAuthFactorToken && authFactorToken == nil {
            throw ServiceError.authFactorTokenRequired
        }
        if requiresAuthFactorToken && authFactorToken != "aB12c3" {
            throw ServiceError.authFactorTokenRejected
        }
        return account
    }

    func signOut() async throws {}
}