fix: address code review feedback
- SettingsView: replace broken Toggle+constant with a Button that directly opens system notification settings (Toggle was bound to .constant(true) and onChange never fired) - HTTPClient: append query parameters to URL for GET requests instead of putting them in the request body (body is ignored for GET) - PushNotificationService: document why info-severity alerts skip Live Activities - NotificationsViewModel: document polling page-reset behavior Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -150,8 +150,18 @@ actor HTTPClient {
|
|||||||
urlRequest.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
|
urlRequest.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
|
||||||
}
|
}
|
||||||
|
|
||||||
if let body = endpoint.body, endpoint.method != "GET" {
|
if let body = endpoint.body {
|
||||||
urlRequest.httpBody = try? JSONSerialization.data(withJSONObject: body)
|
if endpoint.method == "GET" {
|
||||||
|
// Append query parameters to URL for GET requests
|
||||||
|
if var components = URLComponents(url: url, resolvingAgainstBaseURL: false) {
|
||||||
|
components.queryItems = body.map { key, value in
|
||||||
|
URLQueryItem(name: key, value: "\(value)")
|
||||||
|
}
|
||||||
|
urlRequest.url = components.url
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
urlRequest.httpBody = try? JSONSerialization.data(withJSONObject: body)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (data, response): (Data, URLResponse)
|
let (data, response): (Data, URLResponse)
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ class PushNotificationService: NSObject, ObservableObject, UNUserNotificationCen
|
|||||||
let severityStr = attributes["severity"] as? String,
|
let severityStr = attributes["severity"] as? String,
|
||||||
let severity = Severity(rawValue: severityStr) else { return }
|
let severity = Severity(rawValue: severityStr) else { return }
|
||||||
|
|
||||||
|
// Info-level alerts don't warrant a persistent Live Activity — they are low-priority
|
||||||
|
// and should only appear as a standard banner notification.
|
||||||
guard severity != .info else { return }
|
guard severity != .info else { return }
|
||||||
|
|
||||||
// Limit to 3 concurrent activities
|
// Limit to 3 concurrent activities
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ class NotificationsViewModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func startPolling() {
|
func startPolling() {
|
||||||
|
// Polling always reloads page 1 to pick up new notifications.
|
||||||
|
// Users who have scrolled to older pages will have the list reset on each interval.
|
||||||
pollingTask = Task {
|
pollingTask = Task {
|
||||||
while !Task.isCancelled {
|
while !Task.isCancelled {
|
||||||
try? await Task.sleep(for: .seconds(30))
|
try? await Task.sleep(for: .seconds(30))
|
||||||
|
|||||||
@@ -22,14 +22,13 @@ struct SettingsView: View {
|
|||||||
showChangePassword = true
|
showChangePassword = true
|
||||||
}
|
}
|
||||||
|
|
||||||
Toggle(isOn: .constant(true)) {
|
Button {
|
||||||
Label("Push-уведомления", systemImage: "bell.badge")
|
|
||||||
}
|
|
||||||
.onChange(of: true) { _, _ in
|
|
||||||
// Open system settings
|
|
||||||
if let url = URL(string: UIApplication.openNotificationSettingsURLString) {
|
if let url = URL(string: UIApplication.openNotificationSettingsURLString) {
|
||||||
UIApplication.shared.open(url)
|
UIApplication.shared.open(url)
|
||||||
}
|
}
|
||||||
|
} label: {
|
||||||
|
Label("Push-уведомления", systemImage: "bell.badge")
|
||||||
|
.foregroundStyle(.primary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user