SimpleX-Chat/apps/ios/Shared/Views/Chat/ComposeMessage/ContextContactRequestActionsView.swift

83 lines
2.7 KiB
Swift
Raw Normal View History

//
// 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
@UserDefault(DEFAULT_TOOLBAR_MATERIAL) private var toolbarMaterial = ToolbarMaterial.defaultMaterial
2025-06-25 21:13:27 +01:00
@State private var inProgress = false
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-25 21:13:27 +01:00
.frame(maxWidth: .infinity, minHeight: 60)
2025-06-25 21:13:27 +01:00
Button {
if ChatModel.shared.addressShortLinkDataSet {
2025-06-25 21:13:27 +01:00
acceptRequest()
} else {
2025-06-25 21:13:27 +01:00
showAcceptRequestAlert()
}
2025-06-25 21:13:27 +01:00
} label: {
Label("Accept", systemImage: "checkmark")
}
2025-06-25 21:13:27 +01:00
.frame(maxWidth: .infinity, minHeight: 60)
}
2025-06-25 21:13:27 +01:00
.disabled(inProgress)
.frame(maxWidth: .infinity)
.background(ToolbarMaterial.material(toolbarMaterial))
}
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-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 }
}
}
}
#Preview {
ContextContactRequestActionsView(
contactRequestId: 1
)
}