From 3c7adfbce7c132be8c117646940b1738715a6e46 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Mon, 4 Dec 2023 19:51:00 +0000 Subject: [PATCH] add delay, move createInvitation --- .../Shared/Views/NewChat/NewChatView.swift | 19 +++++++------------ .../ios/SimpleX NSE/NotificationService.swift | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/apps/ios/Shared/Views/NewChat/NewChatView.swift b/apps/ios/Shared/Views/NewChat/NewChatView.swift index 7b7b9d2f8..2a77ed15e 100644 --- a/apps/ios/Shared/Views/NewChat/NewChatView.swift +++ b/apps/ios/Shared/Views/NewChat/NewChatView.swift @@ -80,6 +80,9 @@ struct NewChatView: View { case .invite: prepareAndInviteView() .transition(.move(edge: .leading)) + .onAppear { + createInvitation() + } case .connect: ConnectView(showQRCodeScanner: showQRCodeScanner, pastedLink: $pastedLink, alert: $alert) .transition(.move(edge: .trailing)) @@ -109,12 +112,6 @@ struct NewChatView: View { ) } .background(Color(.systemGroupedBackground)) - .onChange(of: selection) { sel in - createInvitation(sel) - } - .onAppear { - createInvitation(selection) - } .onChange(of: invitationUsed) { used in if used && !(m.showingInvitation?.connChatUsed ?? true) { m.markShowingInvitationUsed() @@ -165,11 +162,11 @@ struct NewChatView: View { } } - private func createInvitation(_ selection: NewChatOption) { - if case .invite = selection, - connReqInvitation == "" && contactConnection == nil && !creatingConnReq { + private func createInvitation() { + if connReqInvitation == "" && contactConnection == nil && !creatingConnReq { creatingConnReq = true Task { + _ = try? await Task.sleep(nanoseconds: 250_000000) let (r, apiAlert) = await apiAddContact(incognito: incognitoGroupDefault.get()) if let (connReq, pcc) = r { await MainActor.run { @@ -197,9 +194,7 @@ struct NewChatView: View { } private func retryButton() -> some View { - Button { - createInvitation(selection) - } label: { + Button(action: createInvitation) { VStack(spacing: 6) { Image(systemName: "arrow.counterclockwise") Text("Retry") diff --git a/apps/ios/SimpleX NSE/NotificationService.swift b/apps/ios/SimpleX NSE/NotificationService.swift index ea52f4be8..a80672e8a 100644 --- a/apps/ios/SimpleX NSE/NotificationService.swift +++ b/apps/ios/SimpleX NSE/NotificationService.swift @@ -94,7 +94,7 @@ class NotificationService: UNNotificationServiceExtension { Task { var state = appState for _ in 1...5 { - _ = try await Task.sleep(nanoseconds: suspendingDelay) + _ = try? await Task.sleep(nanoseconds: suspendingDelay) state = appStateGroupDefault.get() if state == .suspended || state != .suspending { break } }