-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserTimeZoneSyncHandler.swift
More file actions
37 lines (33 loc) · 1.04 KB
/
Copy pathUserTimeZoneSyncHandler.swift
File metadata and controls
37 lines (33 loc) · 1.04 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
//
// UserTimeZoneSyncHandler.swift
// DevLog
//
// Created by opfic on 3/19/26.
//
import Combine
import DevLogCore
import DevLogData
import UIKit
final class UserTimeZoneSyncHandler {
private let userService: UserService
private let logger = Logger(category: "UserTimeZoneSyncHandler")
private var cancellables = Set<AnyCancellable>()
init(
userService: UserService,
notificationCenter: NotificationCenter = .default
) {
self.userService = userService
notificationCenter.publisher(for: .didRequestUserTimeZoneSync)
.merge(with: notificationCenter.publisher(for: UIApplication.willEnterForegroundNotification))
.sink { [weak self] _ in
Task {
do {
try await self?.userService.updateUserTimeZone()
} catch {
self?.logger.error("Failed to sync user timeZone", error: error)
}
}
}
.store(in: &cancellables)
}
}