Add native iOS notifications (#64)
This commit is contained in:
@@ -4,6 +4,7 @@ import WidgetKit
|
||||
@MainActor
|
||||
final class AppContext {
|
||||
let core: GotchaCore
|
||||
lazy var notifications = NotificationCoordinator(context: self)
|
||||
private let window: UIWindow
|
||||
private(set) var tabs = UITabBarController()
|
||||
private(set) var navigationControllers: [UINavigationController] = []
|
||||
@@ -96,14 +97,77 @@ final class AppContext {
|
||||
}
|
||||
|
||||
func route(_ activity: ActivityRow) {
|
||||
route(
|
||||
serverId: nil,
|
||||
target: activity.target,
|
||||
owner: activity.owner,
|
||||
repository: activity.repository,
|
||||
number: activity.number,
|
||||
sha: activity.sha
|
||||
)
|
||||
}
|
||||
|
||||
func route(_ notification: NotificationRow) {
|
||||
route(
|
||||
serverId: notification.serverId,
|
||||
target: notification.target,
|
||||
owner: notification.owner,
|
||||
repository: notification.repository,
|
||||
number: notification.number,
|
||||
sha: notification.sha
|
||||
)
|
||||
}
|
||||
|
||||
func route(notificationUserInfo userInfo: [AnyHashable: Any]) {
|
||||
let target: ActivityTargetKind
|
||||
switch userInfo["target"] as? String {
|
||||
case "repository": target = .repository
|
||||
case "issue": target = .issue
|
||||
case "pull": target = .pullRequest
|
||||
case "commit": target = .commit
|
||||
default: target = .none
|
||||
}
|
||||
route(
|
||||
serverId: userInfo["serverId"] as? String,
|
||||
target: target,
|
||||
owner: userInfo["owner"] as? String ?? "",
|
||||
repository: userInfo["repository"] as? String ?? "",
|
||||
number: (userInfo["number"] as? NSNumber)?.int64Value ?? 0,
|
||||
sha: userInfo["sha"] as? String ?? ""
|
||||
)
|
||||
}
|
||||
|
||||
private func route(
|
||||
serverId: String?,
|
||||
target: ActivityTargetKind,
|
||||
owner: String,
|
||||
repository: String,
|
||||
number: Int64,
|
||||
sha: String
|
||||
) {
|
||||
if let serverId {
|
||||
guard let index = core.servers().firstIndex(where: { $0.id == serverId }) else {
|
||||
tabs.present(errorAlert("That notification's server is no longer configured."), animated: true)
|
||||
return
|
||||
}
|
||||
if core.activeServerIndex() != UInt32(index) {
|
||||
do {
|
||||
try selectServer(index: UInt32(index))
|
||||
} catch {
|
||||
tabs.present(errorAlert(error.localizedDescription), animated: true)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
let navigation = navigationControllers[0]
|
||||
switch activity.target {
|
||||
tabs.selectedIndex = 0
|
||||
switch target {
|
||||
case .repository:
|
||||
navigation.pushViewController(
|
||||
IssuesViewController(
|
||||
context: self,
|
||||
owner: activity.owner,
|
||||
repository: activity.repository
|
||||
owner: owner,
|
||||
repository: repository
|
||||
),
|
||||
animated: true
|
||||
)
|
||||
@@ -111,9 +175,9 @@ final class AppContext {
|
||||
navigation.pushViewController(
|
||||
IssueViewController(
|
||||
context: self,
|
||||
owner: activity.owner,
|
||||
repository: activity.repository,
|
||||
number: activity.number
|
||||
owner: owner,
|
||||
repository: repository,
|
||||
number: number
|
||||
),
|
||||
animated: true
|
||||
)
|
||||
@@ -121,9 +185,9 @@ final class AppContext {
|
||||
navigation.pushViewController(
|
||||
PullViewController(
|
||||
context: self,
|
||||
owner: activity.owner,
|
||||
repository: activity.repository,
|
||||
number: activity.number
|
||||
owner: owner,
|
||||
repository: repository,
|
||||
number: number
|
||||
),
|
||||
animated: true
|
||||
)
|
||||
@@ -131,9 +195,9 @@ final class AppContext {
|
||||
navigation.pushViewController(
|
||||
FilesViewController(
|
||||
context: self,
|
||||
owner: activity.owner,
|
||||
repository: activity.repository,
|
||||
sha: activity.sha
|
||||
owner: owner,
|
||||
repository: repository,
|
||||
sha: sha
|
||||
),
|
||||
animated: true
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user