2022-10-01 10:57:18 +01:00
|
|
|
//
|
|
|
|
// ContactConnectionInfo.swift
|
|
|
|
// SimpleX (iOS)
|
|
|
|
//
|
2022-10-06 15:02:58 +01:00
|
|
|
// Created by Evgeny on 06/10/2022.
|
2022-10-01 10:57:18 +01:00
|
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import SimpleXChat
|
|
|
|
|
|
|
|
struct ContactConnectionInfo: View {
|
|
|
|
@EnvironmentObject var m: ChatModel
|
2024-07-03 22:42:13 +01:00
|
|
|
@EnvironmentObject var theme: AppTheme
|
2022-10-06 15:02:58 +01:00
|
|
|
@Environment(\.dismiss) var dismiss: DismissAction
|
|
|
|
@State var contactConnection: PendingContactConnection
|
2025-04-14 21:25:32 +01:00
|
|
|
@State private var showShortLink: Bool = true
|
2022-10-06 15:02:58 +01:00
|
|
|
@State private var alert: CCInfoAlert?
|
|
|
|
@State private var localAlias = ""
|
2023-08-08 17:26:56 +04:00
|
|
|
@State private var showIncognitoSheet = false
|
2022-10-06 15:02:58 +01:00
|
|
|
@FocusState private var aliasTextFieldFocused: Bool
|
|
|
|
|
|
|
|
enum CCInfoAlert: Identifiable {
|
|
|
|
case deleteInvitationAlert
|
2024-07-28 17:54:58 +01:00
|
|
|
case error(title: LocalizedStringKey, error: LocalizedStringKey?)
|
2022-10-06 15:02:58 +01:00
|
|
|
|
|
|
|
var id: String {
|
|
|
|
switch self {
|
|
|
|
case .deleteInvitationAlert: return "deleteInvitationAlert"
|
|
|
|
case let .error(title, _): return "error \(title)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-01 10:57:18 +01:00
|
|
|
|
|
|
|
var body: some View {
|
2022-10-06 15:02:58 +01:00
|
|
|
NavigationView {
|
2023-08-08 17:26:56 +04:00
|
|
|
let v = List {
|
2022-10-06 15:02:58 +01:00
|
|
|
Group {
|
2023-08-08 17:26:56 +04:00
|
|
|
Text(contactConnection.initiated ? "You invited a contact" : "You accepted connection")
|
2022-10-06 15:02:58 +01:00
|
|
|
.font(.largeTitle)
|
|
|
|
.bold()
|
2023-08-08 17:26:56 +04:00
|
|
|
.padding(.bottom)
|
2022-10-01 10:57:18 +01:00
|
|
|
|
2022-10-06 15:02:58 +01:00
|
|
|
Text(contactConnectionText(contactConnection))
|
2022-10-01 10:57:18 +01:00
|
|
|
}
|
2022-10-06 15:02:58 +01:00
|
|
|
.listRowBackground(Color.clear)
|
|
|
|
.listRowSeparator(.hidden)
|
|
|
|
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
|
|
|
|
.onTapGesture { aliasTextFieldFocused = false }
|
2022-10-01 10:57:18 +01:00
|
|
|
|
2022-10-06 15:02:58 +01:00
|
|
|
Section {
|
2022-11-04 15:33:29 +04:00
|
|
|
if contactConnection.groupLinkId == nil {
|
2024-07-03 22:42:13 +01:00
|
|
|
settingsRow("pencil", color: theme.colors.secondary) {
|
2022-11-04 15:33:29 +04:00
|
|
|
TextField("Set contact name…", text: $localAlias)
|
|
|
|
.autocapitalization(.none)
|
|
|
|
.autocorrectionDisabled(true)
|
|
|
|
.focused($aliasTextFieldFocused)
|
|
|
|
.submitLabel(.done)
|
|
|
|
.onSubmit(setConnectionAlias)
|
|
|
|
}
|
2023-04-28 14:11:32 +04:00
|
|
|
.onTapGesture { aliasTextFieldFocused = true }
|
2022-10-06 15:02:58 +01:00
|
|
|
}
|
|
|
|
|
2022-10-15 15:47:04 +04:00
|
|
|
if contactConnection.initiated,
|
2025-04-14 21:25:32 +01:00
|
|
|
let connLinkInv = contactConnection.connLinkInv {
|
|
|
|
SimpleXCreatedLinkQRCode(link: connLinkInv, short: $showShortLink)
|
|
|
|
.id("simplex-invitation-qrcode-\(connLinkInv.simplexChatUri(short: showShortLink))")
|
2023-08-08 17:26:56 +04:00
|
|
|
incognitoEnabled()
|
2025-04-14 21:25:32 +01:00
|
|
|
shareLinkButton(connLinkInv, short: showShortLink)
|
|
|
|
oneTimeLinkLearnMoreButton()
|
2023-04-28 14:11:32 +04:00
|
|
|
} else {
|
2023-08-08 17:26:56 +04:00
|
|
|
incognitoEnabled()
|
2025-04-14 21:25:32 +01:00
|
|
|
oneTimeLinkLearnMoreButton()
|
|
|
|
}
|
|
|
|
} header: {
|
|
|
|
if let connLinkInv = contactConnection.connLinkInv, connLinkInv.connShortLink != nil {
|
|
|
|
ToggleShortLinkHeader(text: Text(""), link: connLinkInv, short: $showShortLink)
|
2022-10-06 15:02:58 +01:00
|
|
|
}
|
2023-08-08 17:26:56 +04:00
|
|
|
} footer: {
|
|
|
|
sharedProfileInfo(contactConnection.incognito)
|
2024-07-03 22:42:13 +01:00
|
|
|
.foregroundColor(theme.colors.secondary)
|
2023-04-28 14:11:32 +04:00
|
|
|
}
|
2022-10-01 10:57:18 +01:00
|
|
|
|
2023-04-28 14:11:32 +04:00
|
|
|
Section {
|
2022-10-06 15:02:58 +01:00
|
|
|
Button(role: .destructive) {
|
|
|
|
alert = .deleteInvitationAlert
|
|
|
|
} label: {
|
|
|
|
Label("Delete connection", systemImage: "trash")
|
|
|
|
.foregroundColor(Color.red)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-03 22:42:13 +01:00
|
|
|
.modifier(ThemedBackground(grouped: true))
|
2023-08-08 17:26:56 +04:00
|
|
|
if #available(iOS 16, *) {
|
|
|
|
v
|
|
|
|
} else {
|
|
|
|
// navigationBarHidden is added conditionally,
|
|
|
|
// because the view jumps in iOS 17 if this is added,
|
|
|
|
// and on iOS 16+ it is hidden without it.
|
|
|
|
v.navigationBarHidden(true)
|
|
|
|
}
|
2022-10-06 15:02:58 +01:00
|
|
|
}
|
|
|
|
.alert(item: $alert) { _alert in
|
|
|
|
switch _alert {
|
|
|
|
case .deleteInvitationAlert:
|
|
|
|
return deleteContactConnectionAlert(contactConnection) { a in
|
|
|
|
alert = .error(title: a.title, error: a.message)
|
|
|
|
} success: {
|
|
|
|
dismiss()
|
|
|
|
}
|
2024-07-28 17:54:58 +01:00
|
|
|
case let .error(title, error): return mkAlert(title: title, message: error)
|
2022-10-06 15:02:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.onAppear {
|
|
|
|
localAlias = contactConnection.localAlias
|
|
|
|
}
|
|
|
|
}
|
2022-10-01 10:57:18 +01:00
|
|
|
|
2022-10-06 15:02:58 +01:00
|
|
|
private func setConnectionAlias() {
|
|
|
|
if localAlias == contactConnection.localAlias {
|
|
|
|
aliasTextFieldFocused = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
Task {
|
|
|
|
let prevAlias = contactConnection.localAlias
|
|
|
|
contactConnection.localAlias = localAlias
|
|
|
|
do {
|
|
|
|
if let conn = try await apiSetConnectionAlias(connId: contactConnection.pccConnId, localAlias: localAlias) {
|
|
|
|
await MainActor.run {
|
|
|
|
contactConnection = conn
|
2023-10-31 09:44:57 +00:00
|
|
|
m.updateContactConnection(conn)
|
2022-10-06 15:02:58 +01:00
|
|
|
dismiss()
|
|
|
|
}
|
2022-10-01 10:57:18 +01:00
|
|
|
}
|
2022-10-06 15:02:58 +01:00
|
|
|
} catch {
|
|
|
|
logger.error("setContactAlias error: \(responseError(error))")
|
|
|
|
contactConnection.localAlias = prevAlias
|
2022-10-01 10:57:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-06 15:02:58 +01:00
|
|
|
|
|
|
|
private func contactConnectionText(_ contactConnection: PendingContactConnection) -> LocalizedStringKey {
|
|
|
|
contactConnection.viaContactUri
|
2022-11-05 17:48:57 +04:00
|
|
|
? (contactConnection.groupLinkId != nil
|
|
|
|
? "You will be connected to group when the group host's device is online, please wait or check later!"
|
|
|
|
: "You will be connected when your connection request is accepted, please wait or check later!"
|
|
|
|
)
|
2022-10-06 15:02:58 +01:00
|
|
|
: "You will be connected when your contact's device is online, please wait or check later!"
|
|
|
|
}
|
2023-08-08 17:26:56 +04:00
|
|
|
|
|
|
|
@ViewBuilder private func incognitoEnabled() -> some View {
|
|
|
|
if contactConnection.incognito {
|
|
|
|
ZStack(alignment: .leading) {
|
|
|
|
Image(systemName: "theatermasks.fill")
|
|
|
|
.frame(maxWidth: 24, maxHeight: 24, alignment: .center)
|
|
|
|
.foregroundColor(Color.indigo)
|
|
|
|
.font(.system(size: 14))
|
|
|
|
HStack(spacing: 6) {
|
|
|
|
Text("Incognito")
|
|
|
|
Image(systemName: "info.circle")
|
2024-07-03 22:42:13 +01:00
|
|
|
.foregroundColor(theme.colors.primary)
|
2023-08-08 17:26:56 +04:00
|
|
|
.font(.system(size: 14))
|
|
|
|
}
|
|
|
|
.onTapGesture {
|
|
|
|
showIncognitoSheet = true
|
|
|
|
}
|
|
|
|
.padding(.leading, 36)
|
|
|
|
}
|
|
|
|
.sheet(isPresented: $showIncognitoSheet) {
|
|
|
|
IncognitoHelp()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-01 10:57:18 +01:00
|
|
|
}
|
|
|
|
|
2025-04-14 21:25:32 +01:00
|
|
|
private func shareLinkButton(_ connLinkInvitation: CreatedConnLink, short: Bool) -> some View {
|
ios: rework UX of creating new connection (#3482)
* ios: connection UI (wip)
* custom search
* rework invite
* connect paste link ui
* scan rework, process errors, other fixes
* scan layout
* clear link on cancel
* improved search
* further improve search
* animation
* connect on paste in search
* layout
* layout
* layout
* layout, add conn
* delete unused invitation, create used invitation chat
* remove old views
* regular paste button
* new chat menu
* previews
* increase spacing
* animation, fix alerts
* swipe
* change text
* less sensitive gesture
* layout
* search cancel button transition
* slow down chat list animation (uses deprecated modifiers)
* icons
* update code scanner, layout
* manage camera permissions
* ask to delete unused invitation
* comment
* remove onDismiss
* don't filter chats on link in search, allow to paste text with link
* cleanup link after connection
* filter chat by link
* revert change
* show link descr
* disabled search
* underline
* filter own group
* simplify
* no animation
* add delay, move createInvitation
* update library
* possible fix for ios 15
* add explicit frame to qr code
* update library
* Revert "add explicit frame to qr code"
This reverts commit 95c7d31e47b3da39b5985cd57638885c45b77de1.
* remove comment
* fix pasteboardHasURLs, disable paste button based on it
* align help texts with changed button names
Co-authored-by: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
* update library
* Revert "fix pasteboardHasURLs, disable paste button based on it"
This reverts commit 46f63572e90dbf460faab9ce694181209712bd00.
* remove unused var
* restore disabled
* export localizations
---------
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
Co-authored-by: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
2023-12-29 16:29:49 +04:00
|
|
|
Button {
|
2025-04-14 21:25:32 +01:00
|
|
|
showShareSheet(items: [connLinkInvitation.simplexChatUri(short: short)])
|
ios: rework UX of creating new connection (#3482)
* ios: connection UI (wip)
* custom search
* rework invite
* connect paste link ui
* scan rework, process errors, other fixes
* scan layout
* clear link on cancel
* improved search
* further improve search
* animation
* connect on paste in search
* layout
* layout
* layout
* layout, add conn
* delete unused invitation, create used invitation chat
* remove old views
* regular paste button
* new chat menu
* previews
* increase spacing
* animation, fix alerts
* swipe
* change text
* less sensitive gesture
* layout
* search cancel button transition
* slow down chat list animation (uses deprecated modifiers)
* icons
* update code scanner, layout
* manage camera permissions
* ask to delete unused invitation
* comment
* remove onDismiss
* don't filter chats on link in search, allow to paste text with link
* cleanup link after connection
* filter chat by link
* revert change
* show link descr
* disabled search
* underline
* filter own group
* simplify
* no animation
* add delay, move createInvitation
* update library
* possible fix for ios 15
* add explicit frame to qr code
* update library
* Revert "add explicit frame to qr code"
This reverts commit 95c7d31e47b3da39b5985cd57638885c45b77de1.
* remove comment
* fix pasteboardHasURLs, disable paste button based on it
* align help texts with changed button names
Co-authored-by: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
* update library
* Revert "fix pasteboardHasURLs, disable paste button based on it"
This reverts commit 46f63572e90dbf460faab9ce694181209712bd00.
* remove unused var
* restore disabled
* export localizations
---------
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
Co-authored-by: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
2023-12-29 16:29:49 +04:00
|
|
|
} label: {
|
2025-04-14 21:25:32 +01:00
|
|
|
Label("Share 1-time link", systemImage: "square.and.arrow.up")
|
ios: rework UX of creating new connection (#3482)
* ios: connection UI (wip)
* custom search
* rework invite
* connect paste link ui
* scan rework, process errors, other fixes
* scan layout
* clear link on cancel
* improved search
* further improve search
* animation
* connect on paste in search
* layout
* layout
* layout
* layout, add conn
* delete unused invitation, create used invitation chat
* remove old views
* regular paste button
* new chat menu
* previews
* increase spacing
* animation, fix alerts
* swipe
* change text
* less sensitive gesture
* layout
* search cancel button transition
* slow down chat list animation (uses deprecated modifiers)
* icons
* update code scanner, layout
* manage camera permissions
* ask to delete unused invitation
* comment
* remove onDismiss
* don't filter chats on link in search, allow to paste text with link
* cleanup link after connection
* filter chat by link
* revert change
* show link descr
* disabled search
* underline
* filter own group
* simplify
* no animation
* add delay, move createInvitation
* update library
* possible fix for ios 15
* add explicit frame to qr code
* update library
* Revert "add explicit frame to qr code"
This reverts commit 95c7d31e47b3da39b5985cd57638885c45b77de1.
* remove comment
* fix pasteboardHasURLs, disable paste button based on it
* align help texts with changed button names
Co-authored-by: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
* update library
* Revert "fix pasteboardHasURLs, disable paste button based on it"
This reverts commit 46f63572e90dbf460faab9ce694181209712bd00.
* remove unused var
* restore disabled
* export localizations
---------
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
Co-authored-by: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
2023-12-29 16:29:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-14 21:25:32 +01:00
|
|
|
private func oneTimeLinkLearnMoreButton() -> some View {
|
ios: rework UX of creating new connection (#3482)
* ios: connection UI (wip)
* custom search
* rework invite
* connect paste link ui
* scan rework, process errors, other fixes
* scan layout
* clear link on cancel
* improved search
* further improve search
* animation
* connect on paste in search
* layout
* layout
* layout
* layout, add conn
* delete unused invitation, create used invitation chat
* remove old views
* regular paste button
* new chat menu
* previews
* increase spacing
* animation, fix alerts
* swipe
* change text
* less sensitive gesture
* layout
* search cancel button transition
* slow down chat list animation (uses deprecated modifiers)
* icons
* update code scanner, layout
* manage camera permissions
* ask to delete unused invitation
* comment
* remove onDismiss
* don't filter chats on link in search, allow to paste text with link
* cleanup link after connection
* filter chat by link
* revert change
* show link descr
* disabled search
* underline
* filter own group
* simplify
* no animation
* add delay, move createInvitation
* update library
* possible fix for ios 15
* add explicit frame to qr code
* update library
* Revert "add explicit frame to qr code"
This reverts commit 95c7d31e47b3da39b5985cd57638885c45b77de1.
* remove comment
* fix pasteboardHasURLs, disable paste button based on it
* align help texts with changed button names
Co-authored-by: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
* update library
* Revert "fix pasteboardHasURLs, disable paste button based on it"
This reverts commit 46f63572e90dbf460faab9ce694181209712bd00.
* remove unused var
* restore disabled
* export localizations
---------
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
Co-authored-by: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
2023-12-29 16:29:49 +04:00
|
|
|
NavigationLink {
|
|
|
|
AddContactLearnMore(showTitle: false)
|
|
|
|
.navigationTitle("One-time invitation link")
|
2024-07-03 22:42:13 +01:00
|
|
|
.modifier(ThemedBackground())
|
ios: rework UX of creating new connection (#3482)
* ios: connection UI (wip)
* custom search
* rework invite
* connect paste link ui
* scan rework, process errors, other fixes
* scan layout
* clear link on cancel
* improved search
* further improve search
* animation
* connect on paste in search
* layout
* layout
* layout
* layout, add conn
* delete unused invitation, create used invitation chat
* remove old views
* regular paste button
* new chat menu
* previews
* increase spacing
* animation, fix alerts
* swipe
* change text
* less sensitive gesture
* layout
* search cancel button transition
* slow down chat list animation (uses deprecated modifiers)
* icons
* update code scanner, layout
* manage camera permissions
* ask to delete unused invitation
* comment
* remove onDismiss
* don't filter chats on link in search, allow to paste text with link
* cleanup link after connection
* filter chat by link
* revert change
* show link descr
* disabled search
* underline
* filter own group
* simplify
* no animation
* add delay, move createInvitation
* update library
* possible fix for ios 15
* add explicit frame to qr code
* update library
* Revert "add explicit frame to qr code"
This reverts commit 95c7d31e47b3da39b5985cd57638885c45b77de1.
* remove comment
* fix pasteboardHasURLs, disable paste button based on it
* align help texts with changed button names
Co-authored-by: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
* update library
* Revert "fix pasteboardHasURLs, disable paste button based on it"
This reverts commit 46f63572e90dbf460faab9ce694181209712bd00.
* remove unused var
* restore disabled
* export localizations
---------
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
Co-authored-by: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
2023-12-29 16:29:49 +04:00
|
|
|
.navigationBarTitleDisplayMode(.large)
|
|
|
|
} label: {
|
2025-04-14 21:25:32 +01:00
|
|
|
Label("Learn more", systemImage: "info.circle")
|
ios: rework UX of creating new connection (#3482)
* ios: connection UI (wip)
* custom search
* rework invite
* connect paste link ui
* scan rework, process errors, other fixes
* scan layout
* clear link on cancel
* improved search
* further improve search
* animation
* connect on paste in search
* layout
* layout
* layout
* layout, add conn
* delete unused invitation, create used invitation chat
* remove old views
* regular paste button
* new chat menu
* previews
* increase spacing
* animation, fix alerts
* swipe
* change text
* less sensitive gesture
* layout
* search cancel button transition
* slow down chat list animation (uses deprecated modifiers)
* icons
* update code scanner, layout
* manage camera permissions
* ask to delete unused invitation
* comment
* remove onDismiss
* don't filter chats on link in search, allow to paste text with link
* cleanup link after connection
* filter chat by link
* revert change
* show link descr
* disabled search
* underline
* filter own group
* simplify
* no animation
* add delay, move createInvitation
* update library
* possible fix for ios 15
* add explicit frame to qr code
* update library
* Revert "add explicit frame to qr code"
This reverts commit 95c7d31e47b3da39b5985cd57638885c45b77de1.
* remove comment
* fix pasteboardHasURLs, disable paste button based on it
* align help texts with changed button names
Co-authored-by: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
* update library
* Revert "fix pasteboardHasURLs, disable paste button based on it"
This reverts commit 46f63572e90dbf460faab9ce694181209712bd00.
* remove unused var
* restore disabled
* export localizations
---------
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
Co-authored-by: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
2023-12-29 16:29:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-01 10:57:18 +01:00
|
|
|
struct ContactConnectionInfo_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2022-10-06 15:02:58 +01:00
|
|
|
ContactConnectionInfo(contactConnection: PendingContactConnection.getSampleData())
|
2022-10-01 10:57:18 +01:00
|
|
|
}
|
|
|
|
}
|