Files
iOS/Sources/App/Settings/Notifications/NotificationRateLimitsAPI.swift
Bruno Pantaleão Gonçalves c59cd48a6d Migrate Notification settings + leaf screens to SwiftUI (#4562)
## Summary
Migrate the notification settings screen and its three leaf screens to
SwiftUI:
- `NotificationSettingsView`: permission status, learn-more link, sounds
/ categories / rate-limit / debug navigation, badge reset + auto-clear,
push ID share, push ID reset.
- `NotificationSoundsView`: imported / bundled / system segmented lists,
audio playback, swipe delete, `.fileImporter`, file-sharing + system
import, AKConverter progress HUD, alert handling.
- `NotificationRateLimitView`: pull-to-refresh on iOS, toolbar refresh
on Catalyst, 1-second reset countdown, retry state, parent
remaining-count callback.
- `NotificationDebugNotificationsView`: `UserDefaults`-backed toggles.

Removes the Eureka `row(for:)` extensions in
`NotificationRateLimitsAPI.swift`, deletes the four old
`*ViewController.swift` files, and rewires `SettingsItem.notifications`
and `NotificationManager.openSettingsFor` to the SwiftUI view.

## Screenshots
_Pending — to be added before merge._

## Link to pull request in Documentation repository
Documentation: home-assistant/companion.home-assistant#

## Any other notes
Part of a five-PR Eureka → SwiftUI migration tracked in
`UIKitToSwiftUIMigration.md` (siblings: #4560, #4561, #4563, #4564). The
`Eureka`, `ColorPickerRow`, and `ViewRow` pods stay until all slices
land.

**Reconciliation with #4563:** the categories PR temporarily embeds
`NotificationCategoryListView` inside the old
`NotificationSettingsViewController` via `UIHostingController`. This PR
deletes that controller entirely; after both merge, the
`categoriesDestination` in `NotificationSettingsView` should link
directly to `NotificationCategoryListView` from the categories PR.

`bundle exec fastlane lint` passes. Not build-verified locally yet.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-28 20:55:21 +02:00

51 lines
1.7 KiB
Swift

import Foundation
import PromiseKit
import Shared
struct RateLimitResponse: Decodable {
var target: String
struct RateLimits: Decodable {
var attempts: Int
var successful: Int
var errors: Int
var total: Int
var maximum: Int
var remaining: Int
var resetsAt: Date
}
var rateLimits: RateLimits
}
class NotificationRateLimitsAPI {
class func rateLimits(pushID: String) -> Promise<RateLimitResponse> {
firstly { () -> Promise<URLRequest> in
do {
var urlRequest = URLRequest(url: URL(
string: "https://mobile-apps.home-assistant.io/api/checkRateLimits"
)!)
urlRequest.httpMethod = "POST"
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
urlRequest.httpBody = try JSONSerialization.data(withJSONObject: [
"push_token": pushID,
])
return .value(urlRequest)
} catch {
return .init(error: error)
}
}.then {
URLSession.shared.dataTask(.promise, with: $0)
}.map { data, _ throws -> RateLimitResponse in
let decoder = with(JSONDecoder()) {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.sss'Z'"
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.timeZone = TimeZone(identifier: "UTC")
$0.dateDecodingStrategy = .formatted(dateFormatter)
}
return try decoder.decode(RateLimitResponse.self, from: data)
}
}
}