mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
convery additional uses of viewerPublisher to fetchViewer
This commit is contained in:
parent
5dff87a8e9
commit
70c4b1c690
4 changed files with 16 additions and 39 deletions
|
|
@ -80,13 +80,14 @@ final class ShareExtensionViewModel: ObservableObject {
|
|||
.store(in: &subscriptions)
|
||||
|
||||
// Using viewerPublisher to get fast feedback for auth/network errors
|
||||
services.dataService.viewerPublisher()
|
||||
.sink { [weak self] completion in
|
||||
guard case let .failure(error) = completion else { return }
|
||||
self?.debugText = "saveArticleError: \(error)"
|
||||
self?.status = .failed(error: .unknown(description: ""))
|
||||
} receiveValue: { _ in }
|
||||
.store(in: &subscriptions)
|
||||
Task {
|
||||
do {
|
||||
_ = try await services.dataService.fetchViewer()
|
||||
} catch {
|
||||
debugText = "saveArticleError: \(error)"
|
||||
status = .failed(error: .unknown(description: ""))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -91,10 +91,10 @@ struct InnerRootView: View {
|
|||
if viewModel.webLinkPath != nil {
|
||||
viewModel.webLinkPath = nil
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) {
|
||||
viewModel.onOpenURL(url: url)
|
||||
Task { await viewModel.onOpenURL(url: url) }
|
||||
}
|
||||
} else {
|
||||
viewModel.onOpenURL(url: url)
|
||||
Task { await viewModel.onOpenURL(url: url) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ public final class RootViewModel: ObservableObject {
|
|||
@Published var snackbarMessage: String?
|
||||
@Published var showSnackbar = false
|
||||
|
||||
public var subscriptions = Set<AnyCancellable>()
|
||||
|
||||
public init() {
|
||||
registerFonts()
|
||||
|
||||
|
|
@ -57,7 +55,7 @@ public final class RootViewModel: ObservableObject {
|
|||
)
|
||||
}
|
||||
|
||||
func onOpenURL(url: URL) {
|
||||
@MainActor func onOpenURL(url: URL) async {
|
||||
guard let linkRequestID = DeepLink.make(from: url)?.linkRequestID else { return }
|
||||
|
||||
if let username = services.dataService.currentViewer?.username {
|
||||
|
|
@ -66,17 +64,10 @@ public final class RootViewModel: ObservableObject {
|
|||
return
|
||||
}
|
||||
|
||||
services.dataService.viewerPublisher().sink(
|
||||
receiveCompletion: { completion in
|
||||
guard case let .failure(error) = completion else { return }
|
||||
print(error)
|
||||
},
|
||||
receiveValue: { [weak self] viewer in
|
||||
let path = self?.linkRequestPath(username: viewer.username, requestID: linkRequestID) ?? ""
|
||||
self?.webLinkPath = SafariWebLinkPath(id: UUID(), path: path)
|
||||
}
|
||||
)
|
||||
.store(in: &subscriptions)
|
||||
if let viewer = try? await services.dataService.fetchViewer() {
|
||||
let path = linkRequestPath(username: viewer.username, requestID: linkRequestID)
|
||||
webLinkPath = SafariWebLinkPath(id: UUID(), path: path)
|
||||
}
|
||||
}
|
||||
|
||||
func triggerPushNotificationRequestIfNeeded() {
|
||||
|
|
|
|||
|
|
@ -44,23 +44,8 @@ public extension DataService {
|
|||
}
|
||||
}
|
||||
|
||||
public extension DataService {
|
||||
@available(*, deprecated, message: "use async version instead")
|
||||
func viewerPublisher() -> AnyPublisher<Viewer, BasicError> {
|
||||
internalViewerPublisher()
|
||||
.handleEvents(receiveOutput: {
|
||||
// Persist ID so AppDelegate can use it to register Intercom users at launch time
|
||||
if UserDefaults.standard.string(forKey: Keys.userIdKey) == nil {
|
||||
UserDefaults.standard.setValue($0.userID, forKey: Keys.userIdKey)
|
||||
DataService.registerIntercomUser?($0.userID)
|
||||
}
|
||||
})
|
||||
.receive(on: DispatchQueue.main)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
|
||||
extension DataService {
|
||||
@available(*, deprecated, message: "use async version instead")
|
||||
func internalViewerPublisher() -> AnyPublisher<Viewer, BasicError> {
|
||||
let selection = Selection<Viewer, Objects.User> {
|
||||
Viewer(
|
||||
Loading…
Reference in a new issue