Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Fix notification bug #2689

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import UserNotifications
import GitHubAPI

extension AppController: UNUserNotificationCenterDelegate {

Expand All @@ -33,11 +34,32 @@ 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)
}
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)
}
}
}
}
}
4 changes: 4 additions & 0 deletions Classes/Systems/AppRouter/AppController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ RouterPropsSource {
sessionManager.addListener(listener: self)
}

func getAppClient() -> GithubClient? {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit weird to me... think it would be nice if we can keep the reading logic in one place.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem so how should I get the app client in the extension?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, that's a question I don't know I can answer :(

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make it public or create a getter, or I could move the extension into the main class

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like option 3 would be the best for now.

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")
Expand Down