Merge pull request #1193 from omnivore-app/fix/current-viewer-main-thread

Make sure we access currentViewer on the main thread
This commit is contained in:
Jackson Harper 2022-09-14 21:24:04 +08:00 committed by GitHub
commit ba948ab4cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View file

@ -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)

View file

@ -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 {

View file

@ -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 {