mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-23 10:15:57 +00:00
* ios: share extension (#4414) * ios: add share extension target * ios: Add UI * ios: send file from share-sheet * image utils * ShareError * error handling; ui-cleanup * progress bar; completion for direct chat * cleanup * cleanup * ios: unify filter and sort between forward and share sheets * ios: match share sheet styling with the main app * ios: fix text input stroke width * ios: align compose views * more of the same... * ShareAPI * remove combine * minor * Better error descriptions --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: enable file sending workers in share extension (#4474) * ios: align compose background, row height and fallback images for share-sheet (#4467) Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: coordinate database access between share extension, the app and notifications extension (#4472) * ios: database management proposal * Add SEState * Global event loop * minor * reset state * use apiCreateItem for local chats * simplify waiting for suspension * loading bar * Dismiss share sheet with error --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * send image message (#4481) Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: improve share extension completion handling (#4486) * improve completion handling * minor * show only spinner for group send * rework event loop, errorAlert * group chat timeout loading bar * state machine WIP * event loop actor * alert * errors text * default * file error --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: add remaining share types; process attachment in background on launch (#4510) * add remaining share types; process attachment in background on launch * cleanup diff * revert `makeVideoQualityLower` * reduce diff * reduce diff * iOS15 support * process events when sharing link and text * cleanup * remove video file on failure * cleanup CompletionHandler --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: share extension - additional alerts and media previews (#4521) * add remaining share types; process attachment in background on launch * cleanup diff * revert `makeVideoQualityLower` * reduce diff * reduce diff * iOS15 support * process events when sharing link and text * cleanup * remove video file on failure * cleanup CompletionHandler * media previews * network timeout alert * revert framework compiler optimisation flag * suspend chat after sheet dismiss * activate chat * update * fix search * sendMessageColor, file preview, chat deselect, simplify error action * cleanup * interupt database closing when sheet is reopened quickly * cleanup redundant alert check * restore package * refactor previews, remove link preview * show link preview when becomes available * comment * dont fail on invalid image * suspend --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: descriptive database errors (#4527) * ios: set share extension as inactive when suspending chat --------- Co-authored-by: Arturs Krumins <auth@levitatingpineapple.com>
198 lines
7.4 KiB
Swift
198 lines
7.4 KiB
Swift
//
|
|
// ContactConnectionInfo.swift
|
|
// SimpleX (iOS)
|
|
//
|
|
// Created by Evgeny on 06/10/2022.
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import SimpleXChat
|
|
|
|
struct ContactConnectionInfo: View {
|
|
@EnvironmentObject var m: ChatModel
|
|
@EnvironmentObject var theme: AppTheme
|
|
@Environment(\.dismiss) var dismiss: DismissAction
|
|
@State var contactConnection: PendingContactConnection
|
|
@State private var alert: CCInfoAlert?
|
|
@State private var localAlias = ""
|
|
@State private var showIncognitoSheet = false
|
|
@FocusState private var aliasTextFieldFocused: Bool
|
|
|
|
enum CCInfoAlert: Identifiable {
|
|
case deleteInvitationAlert
|
|
case error(title: LocalizedStringKey, error: LocalizedStringKey?)
|
|
|
|
var id: String {
|
|
switch self {
|
|
case .deleteInvitationAlert: return "deleteInvitationAlert"
|
|
case let .error(title, _): return "error \(title)"
|
|
}
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
NavigationView {
|
|
let v = List {
|
|
Group {
|
|
Text(contactConnection.initiated ? "You invited a contact" : "You accepted connection")
|
|
.font(.largeTitle)
|
|
.bold()
|
|
.padding(.bottom)
|
|
|
|
Text(contactConnectionText(contactConnection))
|
|
}
|
|
.listRowBackground(Color.clear)
|
|
.listRowSeparator(.hidden)
|
|
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
|
|
.onTapGesture { aliasTextFieldFocused = false }
|
|
|
|
Section {
|
|
if contactConnection.groupLinkId == nil {
|
|
settingsRow("pencil", color: theme.colors.secondary) {
|
|
TextField("Set contact name…", text: $localAlias)
|
|
.autocapitalization(.none)
|
|
.autocorrectionDisabled(true)
|
|
.focused($aliasTextFieldFocused)
|
|
.submitLabel(.done)
|
|
.onSubmit(setConnectionAlias)
|
|
}
|
|
.onTapGesture { aliasTextFieldFocused = true }
|
|
}
|
|
|
|
if contactConnection.initiated,
|
|
let connReqInv = contactConnection.connReqInv {
|
|
SimpleXLinkQRCode(uri: simplexChatLink(connReqInv))
|
|
incognitoEnabled()
|
|
shareLinkButton(connReqInv, theme.colors.secondary)
|
|
oneTimeLinkLearnMoreButton(theme.colors.secondary)
|
|
} else {
|
|
incognitoEnabled()
|
|
oneTimeLinkLearnMoreButton(theme.colors.secondary)
|
|
}
|
|
} footer: {
|
|
sharedProfileInfo(contactConnection.incognito)
|
|
.foregroundColor(theme.colors.secondary)
|
|
}
|
|
|
|
Section {
|
|
Button(role: .destructive) {
|
|
alert = .deleteInvitationAlert
|
|
} label: {
|
|
Label("Delete connection", systemImage: "trash")
|
|
.foregroundColor(Color.red)
|
|
}
|
|
}
|
|
}
|
|
.modifier(ThemedBackground(grouped: true))
|
|
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)
|
|
}
|
|
}
|
|
.alert(item: $alert) { _alert in
|
|
switch _alert {
|
|
case .deleteInvitationAlert:
|
|
return deleteContactConnectionAlert(contactConnection) { a in
|
|
alert = .error(title: a.title, error: a.message)
|
|
} success: {
|
|
dismiss()
|
|
}
|
|
case let .error(title, error): return mkAlert(title: title, message: error)
|
|
}
|
|
}
|
|
.onAppear {
|
|
localAlias = contactConnection.localAlias
|
|
}
|
|
}
|
|
|
|
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
|
|
m.updateContactConnection(conn)
|
|
dismiss()
|
|
}
|
|
}
|
|
} catch {
|
|
logger.error("setContactAlias error: \(responseError(error))")
|
|
contactConnection.localAlias = prevAlias
|
|
}
|
|
}
|
|
}
|
|
|
|
private func contactConnectionText(_ contactConnection: PendingContactConnection) -> LocalizedStringKey {
|
|
contactConnection.viaContactUri
|
|
? (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!"
|
|
)
|
|
: "You will be connected when your contact's device is online, please wait or check later!"
|
|
}
|
|
|
|
@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")
|
|
.foregroundColor(theme.colors.primary)
|
|
.font(.system(size: 14))
|
|
}
|
|
.onTapGesture {
|
|
showIncognitoSheet = true
|
|
}
|
|
.padding(.leading, 36)
|
|
}
|
|
.sheet(isPresented: $showIncognitoSheet) {
|
|
IncognitoHelp()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private func shareLinkButton(_ connReqInvitation: String, _ secondaryColor: Color) -> some View {
|
|
Button {
|
|
showShareSheet(items: [simplexChatLink(connReqInvitation)])
|
|
} label: {
|
|
settingsRow("square.and.arrow.up", color: secondaryColor) {
|
|
Text("Share 1-time link")
|
|
}
|
|
}
|
|
}
|
|
|
|
private func oneTimeLinkLearnMoreButton(_ secondaryColor: Color) -> some View {
|
|
NavigationLink {
|
|
AddContactLearnMore(showTitle: false)
|
|
.navigationTitle("One-time invitation link")
|
|
.modifier(ThemedBackground())
|
|
.navigationBarTitleDisplayMode(.large)
|
|
} label: {
|
|
settingsRow("info.circle", color: secondaryColor) {
|
|
Text("Learn more")
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ContactConnectionInfo_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
ContactConnectionInfo(contactConnection: PendingContactConnection.getSampleData())
|
|
}
|
|
}
|