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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import Foundation
import UIKit
extension MockBlueskyService {
func loadSubscribedFeeds() async throws -> [CustomFeed] {
if failsLoadingFeeds { throw URLError(.notConnectedToInternet) }
return subscribedFeeds
}
func loadCustomFeed(uri: String, cursor: String?) async throws -> FeedPage {
if customFeedUnavailable { throw CustomFeedError.unavailable }
if usesRichScrollFixture {
return cursor == nil ? richScrollFeedPage(authorID: "mae") : FeedPage(posts: [], cursor: nil)
}
let page = try await loadFollowingFeed(cursor: cursor)
return FeedPage(posts: page.posts.filter { $0.author.id == "mae" }, cursor: page.cursor)
}
func loadFollowingFeed(cursor: String?) async throws -> FeedPage {
if cursor == nil { loadState.followingFirstPageLoadCount += 1 }
if ProcessInfo.processInfo.arguments.contains("-ui-testing-pull-refresh-delay") {
try await Task.sleep(for: .seconds(4))
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-three-loading-columns") {
try await Task.sleep(for: .seconds(12))
} else if ProcessInfo.processInfo.arguments.contains("-ui-testing-feed-delay") {
try await Task.sleep(nanoseconds: 5_000_000_000)
}
if usesRichScrollFixture {
return cursor == nil ? richScrollFeedPage() : FeedPage(posts: [], cursor: nil)
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-thread-gap-link") {
guard cursor == nil else { return FeedPage(posts: [], cursor: nil) }
let posts = firstPage
let context = posts.filter { $0.id == "post-1" || $0.id == "post-gap-parent" }
return FeedPage(
posts: posts.filter { $0.id == "post-gap" }, cursor: nil,
replyContexts: ["post-gap": context])
}
guard cursor != nil else {
let repostedBy =
ProcessInfo.processInfo.arguments.contains("-ui-testing-repost-attribution")
? ["post-1": authors[1]] : [:]
if ProcessInfo.processInfo.arguments.contains("-ui-testing-refresh-new-post"),
loadState.followingFirstPageLoadCount > 1 {
let newPosts = (0..<8).map { index in
Post(
id: index == 0 ? "refresh-new-post" : "refresh-new-post-\(index)",
author: authors[index % authors.count],
text: "A new post arrived during refresh."
+ String(repeating: "\nMore from this account.", count: index % 3),
likeCount: 0, repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyIDs: [])
}
return FeedPage(posts: newPosts + firstPage, cursor: "page-2", repostedBy: repostedBy)
}
return FeedPage(posts: firstPage, cursor: "page-2", repostedBy: repostedBy)
}
return FeedPage(
posts: [
withInteractions(
Post(
id: "post-4", author: authors[0], text: "Another quiet moment from the neighborhood.",
likeCount: 12, repostCount: 2, isLiked: false, isReposted: false, imageURLs: [], replyIDs: []))
], cursor: nil)
}
func suggestAccounts(query: String) async throws -> [Post.Author] {
loadState.mentionLookupCount += 1
if ProcessInfo.processInfo.arguments.contains("-ui-testing-mention-failure"),
loadState.mentionLookupCount == 1 {
throw URLError(.notConnectedToInternet)
}
return try await searchAccounts(query: query, cursor: nil).accounts
}
func searchAccounts(query: String, cursor: String?) async throws -> AccountSearchPage {
let matches = authors.filter {
$0.name.localizedCaseInsensitiveContains(query) || $0.handle.localizedCaseInsensitiveContains(query)
}
let start = cursor.flatMap { Int($0) }.flatMap { $0 > 0 ? $0 : nil } ?? (cursor == nil ? 0 : matches.count)
let page = matches.dropFirst(start).prefix(1).map { author in
var author = author
author.bio = profiles.first { $0.author.id == author.id }?.bio
return author
}
return AccountSearchPage(
accounts: page, cursor: start + page.count < matches.count ? String(start + page.count) : nil)
}
func searchPosts(query: String, cursor: String?, authorID: String? = nil) async throws -> FeedPage {
let matches = firstPage.filter {
$0.text.localizedCaseInsensitiveContains(query) && (authorID == nil || $0.author.id == authorID)
}.sorted { ($0.createdAt ?? .distantPast) > ($1.createdAt ?? .distantPast) }
let start = cursor.flatMap { Int($0) }.flatMap { $0 > 0 ? $0 : nil } ?? (cursor == nil ? 0 : matches.count)
let page = Array(matches.dropFirst(start).prefix(1))
return FeedPage(posts: page, cursor: start + page.count < matches.count ? String(start + page.count) : nil)
}
}