-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPushNotificationRoute.swift
More file actions
50 lines (40 loc) · 1.07 KB
/
Copy pathPushNotificationRoute.swift
File metadata and controls
50 lines (40 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// PushNotificationRoute.swift
// DevLog
//
// Created by opfic on 3/8/26.
//
import Foundation
import Combine
enum AppRoute: Equatable, Identifiable {
case todoDetail(String)
var id: String {
switch self {
case .todoDetail(let todoId):
return "todo:\(todoId)"
}
}
}
final class PushNotificationRoute {
static let shared = PushNotificationRoute()
func observe() -> AnyPublisher<AppRoute, Never> {
subject
.compactMap { $0 }
.eraseToAnyPublisher()
}
private let subject = CurrentValueSubject<AppRoute?, Never>(nil)
private init() { }
func handlePushTap(userInfo: [AnyHashable: Any]) {
guard let todoId = extractTodoId(from: userInfo) else { return }
subject.send(.todoDetail(todoId))
}
func clear() {
subject.send(nil)
}
private func extractTodoId(from userInfo: [AnyHashable: Any]) -> String? {
guard let todoId = userInfo["todoId"] as? String, !todoId.isEmpty else {
return nil
}
return todoId
}
}