ask to delete unused invitation
This commit is contained in:
parent
230b5aeb92
commit
9e75e63962
@ -87,8 +87,8 @@ final class ChatModel: ObservableObject {
|
|||||||
@Published var showCallView = false
|
@Published var showCallView = false
|
||||||
// remote desktop
|
// remote desktop
|
||||||
@Published var remoteCtrlSession: RemoteCtrlSession?
|
@Published var remoteCtrlSession: RemoteCtrlSession?
|
||||||
// currently showing invitation connection id
|
// currently showing invitation connection
|
||||||
@Published var invitationConnId: String?
|
@Published var showingInvitation: ShowingInvitation?
|
||||||
// audio recording and playback
|
// audio recording and playback
|
||||||
@Published var stopPreviousRecPlay: URL? = nil // coordinates currently playing source
|
@Published var stopPreviousRecPlay: URL? = nil // coordinates currently playing source
|
||||||
@Published var draft: ComposeState?
|
@Published var draft: ComposeState?
|
||||||
@ -621,11 +621,16 @@ final class ChatModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dismissConnReqView(_ id: String) {
|
func dismissConnReqView(_ id: String) {
|
||||||
if id == invitationConnId {
|
if id == showingInvitation?.connId {
|
||||||
|
markShowingInvitationUsed()
|
||||||
dismissAllSheets()
|
dismissAllSheets()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func markShowingInvitationUsed() {
|
||||||
|
showingInvitation?.connChatUsed = true
|
||||||
|
}
|
||||||
|
|
||||||
func removeChat(_ id: String) {
|
func removeChat(_ id: String) {
|
||||||
withAnimation {
|
withAnimation {
|
||||||
chats.removeAll(where: { $0.id == id })
|
chats.removeAll(where: { $0.id == id })
|
||||||
@ -702,6 +707,11 @@ final class ChatModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ShowingInvitation {
|
||||||
|
var connId: String
|
||||||
|
var connChatUsed: Bool
|
||||||
|
}
|
||||||
|
|
||||||
struct NTFContactRequest {
|
struct NTFContactRequest {
|
||||||
var incognito: Bool
|
var incognito: Bool
|
||||||
var chatId: String
|
var chatId: String
|
||||||
|
@ -36,7 +36,11 @@ struct NewChatMenuButton: View {
|
|||||||
.scaledToFit()
|
.scaledToFit()
|
||||||
.frame(width: 24, height: 24)
|
.frame(width: 24, height: 24)
|
||||||
}
|
}
|
||||||
.sheet(item: $newChatMenuOption) { opt in
|
.sheet(item: $newChatMenuOption, onDismiss: {
|
||||||
|
if case .newContact = newChatMenuOption {
|
||||||
|
|
||||||
|
}
|
||||||
|
}) { opt in
|
||||||
switch opt {
|
switch opt {
|
||||||
case .newContact: NewChatView(selection: .invite)
|
case .newContact: NewChatView(selection: .invite)
|
||||||
case .newGroup: AddGroupView()
|
case .newGroup: AddGroupView()
|
||||||
|
@ -45,7 +45,6 @@ struct NewChatView: View {
|
|||||||
@State var selection: NewChatOption
|
@State var selection: NewChatOption
|
||||||
@State var showQRCodeScanner = false
|
@State var showQRCodeScanner = false
|
||||||
@State private var invitationUsed: Bool = false
|
@State private var invitationUsed: Bool = false
|
||||||
@State private var connectionChatCreated: Bool = false
|
|
||||||
@State private var contactConnection: PendingContactConnection? = nil
|
@State private var contactConnection: PendingContactConnection? = nil
|
||||||
@State private var connReqInvitation: String = ""
|
@State private var connReqInvitation: String = ""
|
||||||
@State private var creatingConnReq = false
|
@State private var creatingConnReq = false
|
||||||
@ -65,6 +64,7 @@ struct NewChatView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding()
|
.padding()
|
||||||
|
.padding(.top)
|
||||||
|
|
||||||
Picker("New chat", selection: $selection) {
|
Picker("New chat", selection: $selection) {
|
||||||
Label("Add contact", systemImage: "link")
|
Label("Add contact", systemImage: "link")
|
||||||
@ -116,20 +116,28 @@ struct NewChatView: View {
|
|||||||
createInvitation(selection)
|
createInvitation(selection)
|
||||||
}
|
}
|
||||||
.onChange(of: invitationUsed) { used in
|
.onChange(of: invitationUsed) { used in
|
||||||
if used && !connectionChatCreated,
|
if used && !(m.showingInvitation?.connChatUsed ?? true) {
|
||||||
let conn = contactConnection {
|
m.markShowingInvitationUsed()
|
||||||
m.updateContactConnection(conn)
|
|
||||||
connectionChatCreated = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onDisappear {
|
.onDisappear {
|
||||||
m.invitationConnId = nil
|
if !(m.showingInvitation?.connChatUsed ?? true),
|
||||||
if !connectionChatCreated,
|
|
||||||
let conn = contactConnection {
|
let conn = contactConnection {
|
||||||
Task {
|
AlertManager.shared.showAlert(Alert(
|
||||||
try await apiDeleteChat(type: .contactConnection, id: conn.apiId)
|
title: Text("Keep unused invitation?"),
|
||||||
}
|
message: Text("You can view invitation link again in connection details."),
|
||||||
|
primaryButton: .default(Text("Keep")) {},
|
||||||
|
secondaryButton: .destructive(Text("Delete")) {
|
||||||
|
Task {
|
||||||
|
await deleteChat(Chat(
|
||||||
|
chatInfo: .contactConnection(contactConnection: conn),
|
||||||
|
chatItems: []
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
m.showingInvitation = nil
|
||||||
}
|
}
|
||||||
.alert(item: $alert) { a in
|
.alert(item: $alert) { a in
|
||||||
switch(a) {
|
switch(a) {
|
||||||
@ -165,9 +173,10 @@ struct NewChatView: View {
|
|||||||
let (r, apiAlert) = await apiAddContact(incognito: incognitoGroupDefault.get())
|
let (r, apiAlert) = await apiAddContact(incognito: incognitoGroupDefault.get())
|
||||||
if let (connReq, pcc) = r {
|
if let (connReq, pcc) = r {
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
|
m.updateContactConnection(pcc)
|
||||||
|
m.showingInvitation = ShowingInvitation(connId: pcc.id, connChatUsed: false)
|
||||||
connReqInvitation = connReq
|
connReqInvitation = connReq
|
||||||
contactConnection = pcc
|
contactConnection = pcc
|
||||||
m.invitationConnId = pcc.id
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
|
Loading…
Reference in New Issue
Block a user