mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
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:
commit
ba948ab4cc
3 changed files with 13 additions and 9 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue