1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#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