diff --git a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift index 4fe5a34cd..d4449c735 100644 --- a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift +++ b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift @@ -262,7 +262,15 @@ struct WebReaderContainerView: View { } } .task { - await viewModel.loadContent(dataService: dataService, itemID: item.unwrappedID) + if let username = dataService.currentViewer?.username { + await viewModel.loadContent( + dataService: dataService, + username: username, + itemID: item.unwrappedID + ) + } else { + viewModel.errorMessage = "You are not logged in." + } } } #if os(iOS) diff --git a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderViewModel.swift index 0af8e158c..18852a450 100644 --- a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderViewModel.swift @@ -12,14 +12,14 @@ struct SafariWebLink: Identifiable { @Published var articleContent: ArticleContent? @Published var errorMessage: String? - func loadContent(dataService: DataService, itemID: String, retryCount: Int = 0) async { + func loadContent(dataService: DataService, username: String, itemID: String, retryCount: Int = 0) async { errorMessage = nil do { - articleContent = try await dataService.loadArticleContentWithRetries(itemID: itemID) + articleContent = try await dataService.loadArticleContentWithRetries(itemID: itemID, username: username) } catch { if retryCount == 0 { - return await loadContent(dataService: dataService, itemID: itemID, retryCount: 1) + return await loadContent(dataService: dataService, username: username, itemID: itemID, retryCount: 1) } if let fetchError = error as? ContentFetchError { switch fetchError { diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Public/LinkedItemContentLoading.swift b/apple/OmnivoreKit/Sources/Services/DataService/Public/LinkedItemContentLoading.swift index 312c5d5ee..3af0f0737 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Public/LinkedItemContentLoading.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Public/LinkedItemContentLoading.swift @@ -13,17 +13,13 @@ public extension DataService { func loadArticleContentWithRetries( itemID: String, - username: String? = nil, + username: String, requestCount: Int = 1 ) async throws -> ArticleContent { guard requestCount < 7 else { throw ContentFetchError.badData } - guard let username = username ?? currentViewer?.username else { - throw ContentFetchError.unauthorized - } - let fetchedContent = try await loadArticleContent(username: username, itemID: itemID, useCache: true) switch fetchedContent.contentStatus {