feat: enhance models and services with Sendable conformance, add preview data for debugging
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import Foundation
|
||||
|
||||
struct LoginResponse: Decodable {
|
||||
struct LoginResponse: Decodable, Sendable {
|
||||
let user: UserResponse
|
||||
let tokens: TokenPair
|
||||
}
|
||||
|
||||
struct RegisterResponse: Decodable {
|
||||
struct RegisterResponse: Decodable, Sendable {
|
||||
let user: UserResponse
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
@@ -20,7 +20,7 @@ struct RegisterResponse: Decodable {
|
||||
}
|
||||
}
|
||||
|
||||
struct VerifyEmailResponse: Decodable {
|
||||
struct VerifyEmailResponse: Decodable, Sendable {
|
||||
let user: UserResponse
|
||||
}
|
||||
|
||||
@@ -64,8 +64,8 @@ actor AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
struct ResendCodeResponse: Decodable {
|
||||
struct ResendCodeResponse: Decodable, Sendable {
|
||||
let message: String
|
||||
}
|
||||
|
||||
struct EmptyResponse: Decodable {}
|
||||
struct EmptyResponse: Decodable, Sendable {}
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
#if DEBUG
|
||||
import Foundation
|
||||
import ActivityKit
|
||||
|
||||
enum PreviewData {
|
||||
nonisolated(unsafe) static var isPreviewMode = false
|
||||
|
||||
static let mockUser = UserResponse(
|
||||
id: UUID(uuidString: "00000000-0000-0000-0000-000000000001")!,
|
||||
email: "demo@mayday.app",
|
||||
status: .active,
|
||||
metadata: nil,
|
||||
emailVerifiedAt: Date(),
|
||||
roles: ["user"],
|
||||
createdAt: Date().addingTimeInterval(-90 * 86400),
|
||||
updatedAt: Date()
|
||||
)
|
||||
|
||||
static let mockNotifications: [AppNotification] = {
|
||||
let now = Date()
|
||||
return [
|
||||
AppNotification(
|
||||
id: UUID(uuidString: "10000000-0000-0000-0000-000000000001")!,
|
||||
topic: "Fire Alert",
|
||||
subject: "Пожарная тревога",
|
||||
body: "Обнаружено задымление на 12 этаже, корпус 9. Необходима немедленная эвакуация персонала.",
|
||||
metadata: ["Здание": "Корпус 9", "Этаж": "12", "Комната": "1A", "Датчик": "SM-4021"],
|
||||
status: .delivered,
|
||||
channel: .push,
|
||||
readAt: nil,
|
||||
createdAt: now.addingTimeInterval(-120),
|
||||
updatedAt: now.addingTimeInterval(-120)
|
||||
),
|
||||
AppNotification(
|
||||
id: UUID(uuidString: "10000000-0000-0000-0000-000000000002")!,
|
||||
topic: "Security Alert",
|
||||
subject: "Нарушение периметра",
|
||||
body: "Зафиксировано несанкционированное проникновение через вход B2. Охрана уведомлена.",
|
||||
metadata: ["Зона": "B2", "Камера": "CAM-17"],
|
||||
status: .delivered,
|
||||
channel: .push,
|
||||
readAt: nil,
|
||||
createdAt: now.addingTimeInterval(-300),
|
||||
updatedAt: now.addingTimeInterval(-300)
|
||||
),
|
||||
AppNotification(
|
||||
id: UUID(uuidString: "10000000-0000-0000-0000-000000000003")!,
|
||||
topic: "Fire Alert",
|
||||
subject: "Пожарная тревога",
|
||||
body: "Сработала пожарная сигнализация в серверной. Автоматическая система пожаротушения активирована.",
|
||||
metadata: ["Здание": "Корпус 9", "Этаж": "12", "Комната": "1A"],
|
||||
status: .read,
|
||||
channel: .push,
|
||||
readAt: now.addingTimeInterval(-3600),
|
||||
createdAt: now.addingTimeInterval(-7200),
|
||||
updatedAt: now.addingTimeInterval(-3600)
|
||||
),
|
||||
AppNotification(
|
||||
id: UUID(uuidString: "10000000-0000-0000-0000-000000000004")!,
|
||||
topic: "Medical Emergency",
|
||||
subject: "Медицинская помощь",
|
||||
body: "Запрос экстренной медицинской помощи на 3 этаже, кабинет 312. Бригада скорой помощи вызвана.",
|
||||
metadata: ["Здание": "Корпус 9", "Этаж": "3", "Комната": "312"],
|
||||
status: .read,
|
||||
channel: .push,
|
||||
readAt: now.addingTimeInterval(-5400),
|
||||
createdAt: now.addingTimeInterval(-7200),
|
||||
updatedAt: now.addingTimeInterval(-5400)
|
||||
),
|
||||
AppNotification(
|
||||
id: UUID(uuidString: "10000000-0000-0000-0000-000000000005")!,
|
||||
topic: "Water Leak",
|
||||
subject: "Затопление",
|
||||
body: "Обнаружена утечка воды в подвальном помещении. Аварийная служба на месте.",
|
||||
metadata: ["Здание": "Корпус 3", "Этаж": "B1"],
|
||||
status: .read,
|
||||
channel: .inApp,
|
||||
readAt: now.addingTimeInterval(-86400),
|
||||
createdAt: now.addingTimeInterval(-90000),
|
||||
updatedAt: now.addingTimeInterval(-86400)
|
||||
),
|
||||
AppNotification(
|
||||
id: UUID(uuidString: "10000000-0000-0000-0000-000000000006")!,
|
||||
topic: "Security Alert",
|
||||
subject: "Тестирование системы",
|
||||
body: "Плановое тестирование системы оповещения. Действий не требуется.",
|
||||
metadata: nil,
|
||||
status: .read,
|
||||
channel: .inApp,
|
||||
readAt: now.addingTimeInterval(-172800),
|
||||
createdAt: now.addingTimeInterval(-180000),
|
||||
updatedAt: now.addingTimeInterval(-172800)
|
||||
),
|
||||
]
|
||||
}()
|
||||
|
||||
static let mockSessions: [SessionResponse] = {
|
||||
let now = Date()
|
||||
return [
|
||||
SessionResponse(
|
||||
id: UUID(uuidString: "20000000-0000-0000-0000-000000000001")!,
|
||||
userAgent: "Mayday/1.0 (iPhone; iOS 18.3)",
|
||||
ipAddress: "192.168.1.42",
|
||||
isCurrent: true,
|
||||
createdAt: now.addingTimeInterval(-3600),
|
||||
expiresAt: now.addingTimeInterval(7 * 86400)
|
||||
),
|
||||
SessionResponse(
|
||||
id: UUID(uuidString: "20000000-0000-0000-0000-000000000002")!,
|
||||
userAgent: "Mayday/1.0 (iPad; iPadOS 18.3)",
|
||||
ipAddress: "192.168.1.100",
|
||||
isCurrent: false,
|
||||
createdAt: now.addingTimeInterval(-86400),
|
||||
expiresAt: now.addingTimeInterval(6 * 86400)
|
||||
),
|
||||
]
|
||||
}()
|
||||
|
||||
static func startMockLiveActivity() async {
|
||||
// End any existing demo activities first
|
||||
for activity in Activity<AlertAttributes>.activities where activity.attributes.alertId == "demo-fire-alert" {
|
||||
let state = activity.content.state
|
||||
await activity.end(ActivityContent(state: state, staleDate: nil), dismissalPolicy: .immediate)
|
||||
}
|
||||
|
||||
let attributes = AlertAttributes(
|
||||
topic: "Fire Alert",
|
||||
alertId: "demo-fire-alert",
|
||||
severity: .critical
|
||||
)
|
||||
let state = AlertAttributes.ContentState(
|
||||
title: "Пожарная тревога",
|
||||
value: "Корпус 9, этаж 12",
|
||||
status: .active,
|
||||
startedAt: Date().addingTimeInterval(-120),
|
||||
updatedAt: Date()
|
||||
)
|
||||
_ = try? Activity<AlertAttributes>.request(
|
||||
attributes: attributes,
|
||||
content: ActivityContent(state: state, staleDate: Date().addingTimeInterval(3600))
|
||||
)
|
||||
}
|
||||
|
||||
static func stopMockLiveActivity() async {
|
||||
for activity in Activity<AlertAttributes>.activities where activity.attributes.alertId == "demo-fire-alert" {
|
||||
let resolvedState = AlertAttributes.ContentState(
|
||||
title: "Пожарная тревога",
|
||||
value: "Корпус 9, этаж 12",
|
||||
status: .resolved,
|
||||
startedAt: activity.content.state.startedAt,
|
||||
updatedAt: Date()
|
||||
)
|
||||
await activity.end(ActivityContent(state: resolvedState, staleDate: nil), dismissalPolicy: .immediate)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -47,7 +47,7 @@ class PushNotificationService: NSObject, ObservableObject, UNUserNotificationCen
|
||||
|
||||
// Update badge
|
||||
if let badge = aps["badge"] as? Int {
|
||||
await UIApplication.shared.setApplicationIconBadgeNumber(badge)
|
||||
try? await UNUserNotificationCenter.current().setBadgeCount(badge)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,9 +85,11 @@ class PushNotificationService: NSObject, ObservableObject, UNUserNotificationCen
|
||||
if currentActivities.count >= 3 {
|
||||
// End the oldest
|
||||
if let oldest = currentActivities.min(by: {
|
||||
$0.contentState.startedAt < $1.contentState.startedAt
|
||||
$0.content.state.startedAt < $1.content.state.startedAt
|
||||
}) {
|
||||
await oldest.end(ActivityContent(state: oldest.contentState, staleDate: nil), dismissalPolicy: .immediate)
|
||||
let finalState = oldest.content.state
|
||||
nonisolated(unsafe) let activity = oldest
|
||||
await activity.end(ActivityContent(state: finalState, staleDate: nil), dismissalPolicy: .immediate)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +119,7 @@ class PushNotificationService: NSObject, ObservableObject, UNUserNotificationCen
|
||||
}
|
||||
|
||||
// MARK: - UNUserNotificationCenterDelegate
|
||||
func userNotificationCenter(
|
||||
nonisolated func userNotificationCenter(
|
||||
_ center: UNUserNotificationCenter,
|
||||
willPresent notification: UNNotification,
|
||||
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
|
||||
@@ -125,7 +127,7 @@ class PushNotificationService: NSObject, ObservableObject, UNUserNotificationCen
|
||||
completionHandler([.banner, .badge, .sound])
|
||||
}
|
||||
|
||||
func userNotificationCenter(
|
||||
nonisolated func userNotificationCenter(
|
||||
_ center: UNUserNotificationCenter,
|
||||
didReceive response: UNNotificationResponse,
|
||||
withCompletionHandler completionHandler: @escaping () -> Void
|
||||
|
||||
Reference in New Issue
Block a user