diff options
| author | Fuwn <[email protected]> | 2025-08-28 15:14:10 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-08-28 15:14:10 -0700 |
| commit | a741e13d18a0927e984dfb6eb3d760f49afe3896 (patch) | |
| tree | 34ba76fddeb26c80d902e7c1790a7fd192a52ff3 /Sora/Data | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-a741e13d18a0927e984dfb6eb3d760f49afe3896.tar.xz sora-testing-a741e13d18a0927e984dfb6eb3d760f49afe3896.zip | |
feat: Development commit
Diffstat (limited to 'Sora/Data')
| -rw-r--r-- | Sora/Data/Booru/BooruManager.swift | 8 | ||||
| -rw-r--r-- | Sora/Data/PostGridViewState/PostGridViewState.swift | 8 | ||||
| -rw-r--r-- | Sora/Data/PostGridViewState/PostGridViewStateItem.swift | 6 | ||||
| -rw-r--r-- | Sora/Data/PostWithContext.swift | 19 |
4 files changed, 23 insertions, 18 deletions
diff --git a/Sora/Data/Booru/BooruManager.swift b/Sora/Data/Booru/BooruManager.swift index 59bdf24..5160c9d 100644 --- a/Sora/Data/Booru/BooruManager.swift +++ b/Sora/Data/Booru/BooruManager.swift @@ -102,7 +102,7 @@ class BooruManager: ObservableObject { // swiftlint:disable:this type_body_leng let provider = self.provider let newPosts = await withCheckedContinuation { continuation in DispatchQueue.global(qos: .userInitiated).async { - let parsedPosts = self.parsePosts( + let parsedPosts = BooruManager.parsePosts( from: data, flavor: flavor, provider: provider @@ -238,7 +238,7 @@ class BooruManager: ObservableObject { // swiftlint:disable:this type_body_leng } // MARK: - Private Methods - private func urlForPosts(page: Int, limit: Int, tags: [String]) -> URL? { + func urlForPosts(page: Int, limit: Int, tags: [String]) -> URL? { let tagString = tags.joined(separator: "+") switch flavor { @@ -304,7 +304,7 @@ class BooruManager: ObservableObject { // swiftlint:disable:this type_body_leng } } - nonisolated private func parsePosts( + nonisolated static func parsePosts( from data: Data, flavor: BooruProviderFlavor, provider: BooruProvider @@ -345,7 +345,7 @@ class BooruManager: ObservableObject { // swiftlint:disable:this type_body_leng } } - private func requestURL(_ url: URL) async throws -> Data { + func requestURL(_ url: URL) async throws -> Data { try await AF.request(url, headers: ["User-Agent": userAgent]) .serializingData() .value diff --git a/Sora/Data/PostGridViewState/PostGridViewState.swift b/Sora/Data/PostGridViewState/PostGridViewState.swift deleted file mode 100644 index 266d05c..0000000 --- a/Sora/Data/PostGridViewState/PostGridViewState.swift +++ /dev/null @@ -1,8 +0,0 @@ -import Foundation - -struct PostGridViewState: Equatable { - var posts: [BooruPost] = [] - var currentPage: Int = 1 - var selectedPost: BooruPost? - let createdAt = Date() -} diff --git a/Sora/Data/PostGridViewState/PostGridViewStateItem.swift b/Sora/Data/PostGridViewState/PostGridViewStateItem.swift deleted file mode 100644 index 3eb66c9..0000000 --- a/Sora/Data/PostGridViewState/PostGridViewStateItem.swift +++ /dev/null @@ -1,6 +0,0 @@ -import Foundation - -struct PostGridViewStateItem: Equatable { - let id: UUID - let state: PostGridViewState -} diff --git a/Sora/Data/PostWithContext.swift b/Sora/Data/PostWithContext.swift new file mode 100644 index 0000000..c8cb2f6 --- /dev/null +++ b/Sora/Data/PostWithContext.swift @@ -0,0 +1,19 @@ +import Foundation + +struct PostWithContext: Hashable { + let post: BooruPost + let posts: [BooruPost]? + + init(post: BooruPost, posts: [BooruPost]?) { + self.post = post + self.posts = posts + } + + func hash(into hasher: inout Hasher) { + hasher.combine(post.id) + } + + static func == (lhs: PostWithContext, rhs: PostWithContext) -> Bool { + lhs.post.id == rhs.post.id + } +} |