fix: address all PR review comments

- 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>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-13 23:29:19 +00:00
parent 9259a3693a
commit 597787a6c9
9 changed files with 91 additions and 78 deletions
+12 -10
View File
@@ -7,7 +7,7 @@ struct VerifyEmailView: View {
@State private var codeDigits: [String] = Array(repeating: "", count: 6)
@State private var resendCooldown = 0
@FocusState private var focusedIndex: Int?
@State private var resendTimer: Timer?
@State private var cooldownTask: Task<Void, Never>?
var body: some View {
VStack(spacing: 32) {
@@ -64,6 +64,7 @@ struct VerifyEmailView: View {
.navigationTitle("Подтверждение")
.navigationBarTitleDisplayMode(.inline)
.onAppear { focusedIndex = 0 }
.onDisappear { cooldownTask?.cancel() }
}
private func handleDigitChange(index: Int, value: String) {
@@ -99,21 +100,22 @@ struct VerifyEmailView: View {
private func resendCode() async {
do {
try await AuthService.shared.resendCode(email: email)
resendCooldown = 60
startCooldownTimer()
startCooldown()
} catch {
authViewModel.error = error.localizedDescription
}
}
private func startCooldownTimer() {
resendTimer?.invalidate()
resendTimer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
if resendCooldown > 0 {
resendCooldown -= 1
} else {
resendTimer?.invalidate()
private func startCooldown() {
cooldownTask?.cancel()
cooldownTask = Task {
for remaining in stride(from: 60, through: 1, by: -1) {
guard !Task.isCancelled else { return }
resendCooldown = remaining
try? await Task.sleep(for: .seconds(1))
}
guard !Task.isCancelled else { return }
resendCooldown = 0
}
}
}
@@ -104,7 +104,7 @@ struct NotificationRowView: View {
Text(notification.subject)
.font(.body)
.fontWeight(notification.isRead ? .regular : .semibold)
Text(notification.createdAt.relativeFormatted)
Text(notification.createdAt, style: .relative)
.font(.caption)
.foregroundStyle(.secondary)
}
@@ -114,15 +114,3 @@ struct NotificationRowView: View {
.padding(.vertical, 4)
}
}
extension Date {
var relativeFormatted: String {
Date.relativeDateTimeFormatter.localizedString(for: self, relativeTo: Date())
}
private static let relativeDateTimeFormatter: RelativeDateTimeFormatter = {
let formatter = RelativeDateTimeFormatter()
formatter.locale = Locale(identifier: "ru_RU")
return formatter
}()
}
+18 -2
View File
@@ -7,6 +7,7 @@ struct SettingsView: View {
@State private var showChangePassword = false
@State private var showSessions = false
@State private var showLogoutAllConfirm = false
@State private var logoutAllError: String?
var body: some View {
NavigationStack {
@@ -81,12 +82,27 @@ struct SettingsView: View {
) {
Button("Выйти везде", role: .destructive) {
Task {
_ = try? await NotificationsAPIService.shared.logoutAll()
await authViewModel.logout()
do {
_ = try await NotificationsAPIService.shared.logoutAll()
await authViewModel.logout()
} catch {
logoutAllError = error.localizedDescription
}
}
}
Button("Отмена", role: .cancel) {}
}
.alert(
"Ошибка",
isPresented: Binding(
get: { logoutAllError != nil },
set: { if !$0 { logoutAllError = nil } }
)
) {
Button("OK") { logoutAllError = nil }
} message: {
Text(logoutAllError ?? "")
}
.task {
await viewModel.loadSessions()
}