597787a6c9
- HTTPClient: replace isRefreshing bool with shared Task to safely coalesce concurrent 401 refresh attempts; surface JSON serialization error instead of silently dropping request body - AuthService.logout: always clear Keychain tokens via defer, even when refresh token is absent, preventing stale access token - NotificationsAPIService: remove updateAppBadge (UIKit call moved to @MainActor NotificationsViewModel); drop unused UIKit import - NotificationsViewModel: guard startPolling() against duplicate tasks; update badge directly on @MainActor instead of hopping to actor - VerifyEmailView: replace Timer (never invalidated) with async Task cancelled in .onDisappear - NotificationsView: use Text(date, style: .relative) — auto-updates without custom formatter; remove duplicate Date extension - SettingsView: handle logoutAll errors explicitly with alert instead of silently proceeding with local logout - MaydayLiveActivity/Info.plist: add NSExtensionPrincipalClass so the widget extension is discoverable by the system - Live Activity widget: replace frozen duration(from:) with Text(date, style: .timer); replace frozen relativeFormatted with Text(date, style: .relative); localize status badge to Russian Co-authored-by: robonen <26167508+robonen@users.noreply.github.com>
42 lines
1.2 KiB
Swift
42 lines
1.2 KiB
Swift
import Foundation
|
|
|
|
actor NotificationsAPIService {
|
|
static let shared = NotificationsAPIService()
|
|
private let client = HTTPClient.shared
|
|
|
|
private init() {}
|
|
|
|
func getNotifications(page: Int = 1, perPage: Int = 20) async throws -> NotificationsPage {
|
|
try await client.request(.getNotifications(page: page, perPage: perPage))
|
|
}
|
|
|
|
func markAsRead(id: UUID) async throws {
|
|
let _: AppNotification = try await client.request(.markAsRead(id: id))
|
|
}
|
|
|
|
func getSessions() async throws -> [SessionResponse] {
|
|
try await client.request(.getSessions)
|
|
}
|
|
|
|
func deleteSession(id: UUID) async throws {
|
|
let _: EmptyResponse = try await client.request(.deleteSession(id: id))
|
|
}
|
|
|
|
func logoutAll() async throws -> Int {
|
|
let response: LogoutAllResponse = try await client.request(.logoutAll)
|
|
return response.revokedSessions
|
|
}
|
|
|
|
func changePassword(current: String, new: String) async throws -> UserResponse {
|
|
try await client.request(.changePassword(current: current, new: new))
|
|
}
|
|
}
|
|
|
|
struct LogoutAllResponse: Decodable {
|
|
let revokedSessions: Int
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case revokedSessions = "revoked_sessions"
|
|
}
|
|
}
|