From 2cde31a52348e7a5d35e645649a2435fcd85cb8b Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 28 Apr 2024 21:34:12 -0700 Subject: [PATCH] Create syncStreamContents function to replace FeedlySyncStreamContentsOperation. --- .../FeedlyAccountDelegate.swift | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Account/Sources/Account/AccountDelegates/FeedlyAccountDelegate.swift b/Account/Sources/Account/AccountDelegates/FeedlyAccountDelegate.swift index 0c21f8898..2cdb7a20d 100644 --- a/Account/Sources/Account/AccountDelegates/FeedlyAccountDelegate.swift +++ b/Account/Sources/Account/AccountDelegates/FeedlyAccountDelegate.swift @@ -644,6 +644,12 @@ final class FeedlyAccountDelegate: AccountDelegate { return articleIDs } + func updateAccountFeeds(parsedItems: Set) async throws { + + let feedIDsAndItems = parsedItemsKeyedByFeedURL(parsedItems) + try await updateAccountFeedsWithItems(feedIDsAndItems: feedIDsAndItems) + } + func updateAccountFeedsWithItems(feedIDsAndItems: [String: Set]) async throws { // To replace FeedlyUpdateAccountFeedsWithItemsOperation @@ -722,9 +728,7 @@ final class FeedlyAccountDelegate: AccountDelegate { for articleIDs in Array(allArticleIDs).chunked(into: feedlyAPILimitBatchSize) { let parsedItems = try await fetchParsedItems(articleIDs: Set(articleIDs)) - let feedIDsAndItems = parsedItemsKeyedByFeedURL(parsedItems) - - try await updateAccountFeedsWithItems(feedIDsAndItems: feedIDsAndItems) + try await updateAccountFeeds(parsedItems: parsedItems) } } @@ -812,12 +816,12 @@ final class FeedlyAccountDelegate: AccountDelegate { try await caller.getFeeds(for: url, count: 1, localeIdentifier: Locale.current.identifier) } - func fetchStreamContents(resource: FeedlyResourceID, continuation: String? = nil, newerThan: Date?, unreadOnly: Bool? = nil) async throws -> Set { + func fetchStreamContents(resourceID: FeedlyResourceID, continuation: String? = nil, newerThan: Date?, unreadOnly: Bool? = nil) async throws -> Set { // To replace FeedlyGetStreamContentsOperation do { - let stream = try await caller.getStreamContents(for: resource, continuation: continuation, newerThan: newerThan, unreadOnly: unreadOnly) + let stream = try await caller.getStreamContents(for: resourceID, continuation: continuation, newerThan: newerThan, unreadOnly: unreadOnly) return parsedItems(with: Set(stream.items)) } catch { os_log(.debug, log: self.log, "Unable to get stream contents: %{public}@.", error as NSError) @@ -936,11 +940,19 @@ final class FeedlyAccountDelegate: AccountDelegate { // To replace FeedlyIngestStreamArticleIDsOperation guard let account else { return } - + let allArticleIDs = try await fetchAllArticleIDs() try await account.createStatusesIfNeeded(articleIDs: allArticleIDs) } + func syncStreamContents(feedResourceID: FeedlyFeedResourceID) async throws { + + // To replace FeedlySyncStreamContentsOperation + + let parsedItems = try await fetchStreamContents(resourceID: feedResourceID, newerThan: nil) + try await updateAccountFeeds(parsedItems: parsedItems) + } + // MARK: Suspend and Resume (for iOS) /// Suspend all network activity