Create fetchCollections method.
This commit is contained in:
parent
3612b1e8fd
commit
f7b195a748
|
@ -744,6 +744,22 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
func fetchCollections() async throws -> Set<FeedlyCollection> {
|
||||
|
||||
// To replace FeedlyGetCollectionsOperation
|
||||
|
||||
os_log(.debug, log: log, "Requesting collections.")
|
||||
|
||||
do {
|
||||
let collections = try await caller.getCollections()
|
||||
os_log(.debug, log: self.log, "Received collections: %{public}@", collections.map { $0.id })
|
||||
return collections
|
||||
} catch {
|
||||
os_log(.debug, log: self.log, "Unable to request collections: %{public}@.", error as NSError)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Suspend and Resume (for iOS)
|
||||
|
||||
/// Suspend all network activity
|
||||
|
|
|
@ -364,7 +364,7 @@ func refreshAccessToken(_ refreshRequest: OAuthRefreshAccessTokenRequest) async
|
|||
|
||||
extension FeedlyAPICaller: FeedlyGetCollectionsService {
|
||||
|
||||
func getCollections() async throws -> [FeedlyCollection] {
|
||||
func getCollections() async throws -> Set<FeedlyCollection> {
|
||||
|
||||
guard !isSuspended else { throw TransportError.suspended }
|
||||
|
||||
|
@ -375,7 +375,7 @@ extension FeedlyAPICaller: FeedlyGetCollectionsService {
|
|||
throw URLError(.cannotDecodeContentData)
|
||||
}
|
||||
|
||||
return collections
|
||||
return Set(collections)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,11 +20,19 @@ public struct FeedlyCategory: Decodable, Sendable, Equatable {
|
|||
}
|
||||
}
|
||||
|
||||
public struct FeedlyCollection: Codable, Sendable {
|
||||
public struct FeedlyCollection: Codable, Sendable, Hashable {
|
||||
|
||||
public let feeds: [FeedlyFeed]
|
||||
public let label: String
|
||||
public let id: String
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(id)
|
||||
}
|
||||
|
||||
public static func ==(lhs: FeedlyCollection, rhs: FeedlyCollection) -> Bool {
|
||||
lhs.id == rhs.id && lhs.label == rhs.label && lhs.feeds == rhs.feeds
|
||||
}
|
||||
}
|
||||
|
||||
public struct FeedlyCollectionParser: Sendable {
|
||||
|
@ -244,12 +252,16 @@ public struct FeedlyEntryParser: Sendable {
|
|||
}
|
||||
}
|
||||
|
||||
public struct FeedlyFeed: Codable, Sendable {
|
||||
public struct FeedlyFeed: Codable, Sendable, Equatable {
|
||||
|
||||
public let id: String
|
||||
public let title: String?
|
||||
public let updated: Date?
|
||||
public let website: String?
|
||||
|
||||
public static func ==(lhs: FeedlyFeed, rhs: FeedlyFeed) -> Bool {
|
||||
lhs.id == rhs.id && lhs.title == rhs.title && lhs.updated == rhs.updated && lhs.website == rhs.website
|
||||
}
|
||||
}
|
||||
|
||||
public struct FeedlyFeedParser: Sendable {
|
||||
|
|
|
@ -10,7 +10,7 @@ import Foundation
|
|||
|
||||
public protocol FeedlyGetCollectionsService: AnyObject {
|
||||
|
||||
@MainActor func getCollections() async throws -> [FeedlyCollection]
|
||||
@MainActor func getCollections() async throws -> Set<FeedlyCollection>
|
||||
}
|
||||
|
||||
public protocol FeedlyGetEntriesService: AnyObject {
|
||||
|
|
|
@ -35,7 +35,7 @@ public final class FeedlyGetCollectionsOperation: FeedlyOperation, FeedlyCollect
|
|||
do {
|
||||
let collections = try await service.getCollections()
|
||||
os_log(.debug, log: self.log, "Received collections: %{public}@", collections.map { $0.id })
|
||||
self.collections = collections
|
||||
self.collections = Array(collections)
|
||||
self.didFinish()
|
||||
|
||||
} catch {
|
||||
|
|
Loading…
Reference in New Issue