2025-06-09 16:18:01 +00:00
|
|
|
//
|
|
|
|
// ContextContactRequestActionsView.swift
|
|
|
|
// SimpleX (iOS)
|
|
|
|
//
|
|
|
|
// Created by spaced4ndy on 02.05.2025.
|
|
|
|
// Copyright © 2025 SimpleX Chat. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import SimpleXChat
|
|
|
|
|
|
|
|
struct ContextContactRequestActionsView: View {
|
|
|
|
@EnvironmentObject var theme: AppTheme
|
|
|
|
var contactRequestId: Int64
|
2025-06-23 14:42:00 +01:00
|
|
|
@UserDefault(DEFAULT_TOOLBAR_MATERIAL) private var toolbarMaterial = ToolbarMaterial.defaultMaterial
|
2025-06-25 21:13:27 +01:00
|
|
|
@State private var inProgress = false
|
2025-06-09 16:18:01 +00:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
HStack(spacing: 0) {
|
2025-06-25 21:13:27 +01:00
|
|
|
Button(role: .destructive, action: showRejectRequestAlert) {
|
|
|
|
Label("Reject", systemImage: "multiply")
|
2025-06-09 16:18:01 +00:00
|
|
|
}
|
2025-06-25 21:13:27 +01:00
|
|
|
.frame(maxWidth: .infinity, minHeight: 60)
|
2025-06-09 16:18:01 +00:00
|
|
|
|
2025-06-25 21:13:27 +01:00
|
|
|
Button {
|
2025-06-23 14:42:00 +01:00
|
|
|
if ChatModel.shared.addressShortLinkDataSet {
|
2025-06-25 21:13:27 +01:00
|
|
|
acceptRequest()
|
2025-06-23 14:42:00 +01:00
|
|
|
} else {
|
2025-06-25 21:13:27 +01:00
|
|
|
showAcceptRequestAlert()
|
2025-06-23 14:42:00 +01:00
|
|
|
}
|
2025-06-25 21:13:27 +01:00
|
|
|
} label: {
|
|
|
|
Label("Accept", systemImage: "checkmark")
|
2025-06-09 16:18:01 +00:00
|
|
|
}
|
2025-06-25 21:13:27 +01:00
|
|
|
.frame(maxWidth: .infinity, minHeight: 60)
|
2025-06-09 16:18:01 +00:00
|
|
|
}
|
2025-06-25 21:13:27 +01:00
|
|
|
.disabled(inProgress)
|
2025-06-09 16:18:01 +00:00
|
|
|
.frame(maxWidth: .infinity)
|
2025-06-23 14:42:00 +01:00
|
|
|
.background(ToolbarMaterial.material(toolbarMaterial))
|
2025-06-09 16:18:01 +00:00
|
|
|
}
|
|
|
|
|
2025-06-25 21:13:27 +01:00
|
|
|
private func showRejectRequestAlert() {
|
|
|
|
showAlert(
|
|
|
|
NSLocalizedString("Reject contact request", comment: "alert title"),
|
|
|
|
message: NSLocalizedString("The sender will NOT be notified", comment: "alert message"),
|
|
|
|
actions: {[
|
|
|
|
UIAlertAction(title: NSLocalizedString("Reject", comment: "alert action"), style: .destructive) { _ in
|
|
|
|
Task { await rejectContactRequest(contactRequestId, dismissToChatList: true) }
|
|
|
|
},
|
|
|
|
cancelAlertAction
|
|
|
|
]}
|
|
|
|
)
|
|
|
|
}
|
2025-06-09 16:18:01 +00:00
|
|
|
|
2025-06-25 21:13:27 +01:00
|
|
|
private func showAcceptRequestAlert() {
|
|
|
|
showAlert(
|
|
|
|
NSLocalizedString("Accept contact request", comment: "alert title"),
|
|
|
|
actions: {[
|
|
|
|
UIAlertAction(title: NSLocalizedString("Accept", comment: "alert action"), style: .default) { _ in
|
|
|
|
acceptRequest()
|
|
|
|
},
|
|
|
|
UIAlertAction(title: NSLocalizedString("Accept incognito", comment: "alert action"), style: .default) { _ in
|
|
|
|
acceptRequest(incognito: true)
|
|
|
|
},
|
|
|
|
cancelAlertAction
|
|
|
|
]}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func acceptRequest(incognito: Bool = false) {
|
|
|
|
inProgress = true
|
|
|
|
Task {
|
|
|
|
await acceptContactRequest(incognito: false, contactRequestId: contactRequestId)
|
|
|
|
await MainActor.run { inProgress = false }
|
|
|
|
}
|
|
|
|
}
|
2025-06-09 16:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#Preview {
|
|
|
|
ContextContactRequestActionsView(
|
|
|
|
contactRequestId: 1
|
|
|
|
)
|
|
|
|
}
|