add delay, move createInvitation

This commit is contained in:
Evgeny Poberezkin 2023-12-04 19:51:00 +00:00
parent 6d583ad057
commit 3c7adfbce7
2 changed files with 8 additions and 13 deletions

View File

@ -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")

View File

@ -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 }
}