From 4cd0d933094857a1cee04a91bb699c6c41fcae52 Mon Sep 17 00:00:00 2001 From: Ehud Adler Date: Wed, 13 Mar 2019 00:26:18 -0400 Subject: [PATCH] Fix notification bug --- ...ler+UNUserNotificationCenterDelegate.swift | 22 +++++++++++++++++++ Classes/Systems/AppRouter/AppController.swift | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/Classes/Systems/AppRouter/AppController+UNUserNotificationCenterDelegate.swift b/Classes/Systems/AppRouter/AppController+UNUserNotificationCenterDelegate.swift index 39538bed5..cc9eb9297 100644 --- a/Classes/Systems/AppRouter/AppController+UNUserNotificationCenterDelegate.swift +++ b/Classes/Systems/AppRouter/AppController+UNUserNotificationCenterDelegate.swift @@ -7,6 +7,7 @@ // import UserNotifications +import GitHubAPI extension AppController: UNUserNotificationCenterDelegate { @@ -33,6 +34,7 @@ extension AppController: UNUserNotificationCenterDelegate { case UNNotificationDismissActionIdentifier: break case UNNotificationDefaultActionIdentifier: if let (path, params) = response.notification.request.content.routableUserInfo { + markNotificationRead(id: response.notification.request.identifier) router.handle(path: path, params: params) } default: print(response.actionIdentifier) @@ -40,4 +42,24 @@ extension AppController: UNUserNotificationCenterDelegate { completionHandler() } + func markNotificationRead(id: String) { + if let githubClient = getAppClient() { + let cache = githubClient.cache + guard var model = cache.get(id: id) as NotificationViewModel?, + !model.read + else { return } + + model.read = true + cache.set(value: model) + + githubClient.client.send(V3MarkThreadsRequest(id: id)) { result in + switch result { + case .success: break + case .failure: + model.read = false + cache.set(value: model) + } + } + } + } } diff --git a/Classes/Systems/AppRouter/AppController.swift b/Classes/Systems/AppRouter/AppController.swift index 777806aea..83481b2ff 100644 --- a/Classes/Systems/AppRouter/AppController.swift +++ b/Classes/Systems/AppRouter/AppController.swift @@ -33,6 +33,10 @@ RouterPropsSource { sessionManager.addListener(listener: self) } + func getAppClient() -> GithubClient? { + return self.appClient + } + func appDidFinishLaunching(with window: UIWindow?) { guard let controller = window?.rootViewController as? AppSplitViewController else { fatalError("App must be setup with a split view controller")