mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-25 09:52:14 +00:00
* initial implementation of textbox * paste to connect box implemented (and tested) in android * first pass at pastebox in iOS * clean up iOS implementation * put paste link page in for groups in android * initial inclusion in iOS UI * refactor naming * lint kotlin * fix typo * ios: update "connect via link" ui, refactor connecting via link to use the one function * android: update paste link UI * add russian translations * update translations Co-authored-by: JRoberts <8711996+jr-simplex@users.noreply.github.com> * update translations Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Co-authored-by: JRoberts <8711996+jr-simplex@users.noreply.github.com>
94 lines
3.0 KiB
Swift
94 lines
3.0 KiB
Swift
//
|
|
// NewChatButton.swift
|
|
// SimpleX
|
|
//
|
|
// Created by Evgeny Poberezkin on 31/01/2022.
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct NewChatButton: View {
|
|
@State private var showAddChat = false
|
|
@State private var addContact = false
|
|
@State private var connReqInvitation: String = ""
|
|
@State private var scanToConnect = false
|
|
@State private var pasteToConnect = false
|
|
|
|
var body: some View {
|
|
Button { showAddChat = true } label: {
|
|
Image(systemName: "person.crop.circle.badge.plus")
|
|
}
|
|
.confirmationDialog("Add contact to start a new chat", isPresented: $showAddChat, titleVisibility: .visible) {
|
|
Button("Create link / QR code") { addContactAction() }
|
|
Button("Paste received link") { pasteToConnect = true }
|
|
Button("Scan QR code") { scanToConnect = true }
|
|
}
|
|
.sheet(isPresented: $addContact, content: {
|
|
AddContactView(connReqInvitation: connReqInvitation)
|
|
})
|
|
.sheet(isPresented: $scanToConnect, content: {
|
|
ScanToConnectView(openedSheet: $scanToConnect)
|
|
})
|
|
.sheet(isPresented: $pasteToConnect, content: {
|
|
PasteToConnectView(openedSheet: $pasteToConnect)
|
|
})
|
|
}
|
|
|
|
func addContactAction() {
|
|
do {
|
|
connReqInvitation = try apiAddContact()
|
|
addContact = true
|
|
} catch {
|
|
DispatchQueue.global().async {
|
|
connectionErrorAlert(error)
|
|
}
|
|
logger.error("NewChatButton.addContactAction apiAddContact error: \(error.localizedDescription)")
|
|
}
|
|
}
|
|
}
|
|
|
|
enum ConnReqType: Equatable {
|
|
case contact
|
|
case invitation
|
|
}
|
|
|
|
func connectViaLink(_ connectionLink: String, _ openedSheet: Binding<Bool>? = nil) {
|
|
Task {
|
|
do {
|
|
let res = try await apiConnect(connReq: connectionLink)
|
|
DispatchQueue.main.async {
|
|
openedSheet?.wrappedValue = false
|
|
if let connReqType = res {
|
|
connectionReqSentAlert(connReqType)
|
|
}
|
|
}
|
|
} catch {
|
|
logger.error("connectViaLink apiConnect error: \(responseError(error))")
|
|
DispatchQueue.main.async {
|
|
openedSheet?.wrappedValue = false
|
|
connectionErrorAlert(error)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func connectionErrorAlert(_ error: Error) {
|
|
AlertManager.shared.showAlertMsg(title: "Connection error", message: "Error: \(error.localizedDescription)")
|
|
}
|
|
|
|
func connectionReqSentAlert(_ type: ConnReqType) {
|
|
AlertManager.shared.showAlertMsg(
|
|
title: "Connection request sent!",
|
|
message: type == .contact
|
|
? "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!"
|
|
)
|
|
}
|
|
|
|
struct NewChatButton_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
NewChatButton()
|
|
}
|
|
}
|