mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-12 08:45:07 +00:00
delete via chat list (has bugs)
This commit is contained in:
@@ -773,6 +773,26 @@ func deleteChat(_ chat: Chat, chatDeleteMode: ChatDeleteMode = .full(notify: tru
|
||||
}
|
||||
}
|
||||
|
||||
func deleteChatContact(_ chat: Chat, chatDeleteMode: ChatDeleteMode = .full(notify: true)) async {
|
||||
do {
|
||||
let cInfo = chat.chatInfo
|
||||
let ct = try await apiDeleteContact(id: cInfo.apiId, chatDeleteMode: chatDeleteMode)
|
||||
DispatchQueue.main.async {
|
||||
if case .full = chatDeleteMode {
|
||||
ChatModel.shared.removeChat(cInfo.id)
|
||||
} else {
|
||||
ChatModel.shared.updateContact(ct)
|
||||
}
|
||||
}
|
||||
} catch let error {
|
||||
logger.error("deleteChatContact apiDeleteContact error: \(responseError(error))")
|
||||
AlertManager.shared.showAlertMsg(
|
||||
title: "Error deleting chat!",
|
||||
message: "Error: \(responseError(error))"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func apiClearChat(type: ChatType, id: Int64) async throws -> ChatInfo {
|
||||
let r = await chatSendCmd(.apiClearChat(type: type, id: id), bgTask: false)
|
||||
if case let .chatCleared(_, updatedChatInfo) = r { return updatedChatInfo }
|
||||
|
||||
@@ -32,11 +32,23 @@ struct ChatListNavLink: View {
|
||||
@State private var showJoinGroupDialog = false
|
||||
@State private var showContactConnectionInfo = false
|
||||
@State private var showInvalidJSON = false
|
||||
@State private var showDeleteContactActionSheet = false
|
||||
@State private var contactNavLinkSheet: ContactNavLinkActionSheet? = nil
|
||||
@State private var showConnectContactViaAddressDialog = false
|
||||
@State private var inProgress = false
|
||||
@State private var progressByTimeout = false
|
||||
|
||||
enum ContactNavLinkActionSheet: Identifiable {
|
||||
case deleteConversationActionSheet
|
||||
case notifyDeleteContactActionSheet
|
||||
|
||||
var id: String {
|
||||
switch self {
|
||||
case .deleteConversationActionSheet: return "deleteConversationActionSheet"
|
||||
case .notifyDeleteContactActionSheet: return "notifyDeleteContactActionSheet"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
switch chat.chatInfo {
|
||||
@@ -72,7 +84,7 @@ struct ChatListNavLink: View {
|
||||
.frame(height: rowHeights[dynamicTypeSize])
|
||||
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
|
||||
Button {
|
||||
showDeleteContactActionSheet = true
|
||||
contactNavLinkSheet = .deleteConversationActionSheet
|
||||
} label: {
|
||||
Label("Delete", systemImage: "trash")
|
||||
}
|
||||
@@ -100,7 +112,7 @@ struct ChatListNavLink: View {
|
||||
}
|
||||
Button {
|
||||
if contact.ready || !contact.active {
|
||||
showDeleteContactActionSheet = true
|
||||
contactNavLinkSheet = .deleteConversationActionSheet
|
||||
} else {
|
||||
AlertManager.shared.showAlert(deletePendingContactAlert(chat, contact))
|
||||
}
|
||||
@@ -112,24 +124,36 @@ struct ChatListNavLink: View {
|
||||
.frame(height: rowHeights[dynamicTypeSize])
|
||||
}
|
||||
}
|
||||
.actionSheet(isPresented: $showDeleteContactActionSheet) {
|
||||
if contact.ready && contact.active {
|
||||
.actionSheet(item: $contactNavLinkSheet) { sheet in
|
||||
switch(sheet) {
|
||||
case .deleteConversationActionSheet:
|
||||
return ActionSheet(
|
||||
title: Text("Delete contact?\nThis cannot be undone!"),
|
||||
title: Text("Delete conversation?"),
|
||||
buttons: [
|
||||
.destructive(Text("Delete and notify contact")) { Task { await deleteChat(chat, chatDeleteMode: .full(notify: true)) } },
|
||||
.destructive(Text("Delete")) { Task { await deleteChat(chat, chatDeleteMode: .full(notify: false)) } },
|
||||
.cancel()
|
||||
]
|
||||
)
|
||||
} else {
|
||||
return ActionSheet(
|
||||
title: Text("Delete contact?\nThis cannot be undone!"),
|
||||
buttons: [
|
||||
.destructive(Text("Delete")) { Task { await deleteChat(chat) } },
|
||||
.destructive(Text("Delete conversation")) { Task { await deleteChatContact(chat, chatDeleteMode: .messages) } },
|
||||
.destructive(Text("Delete conversation and contact")) { contactNavLinkSheet = .notifyDeleteContactActionSheet },
|
||||
.cancel()
|
||||
]
|
||||
)
|
||||
case .notifyDeleteContactActionSheet:
|
||||
if contact.ready && contact.active {
|
||||
return ActionSheet(
|
||||
title: Text("Notify contact?\nThis cannot be undone!"),
|
||||
buttons: [
|
||||
.destructive(Text("Delete and notify contact")) { Task { await deleteChatContact(chat, chatDeleteMode: .full(notify: true)) } },
|
||||
.destructive(Text("Delete without notification")) { Task { await deleteChatContact(chat, chatDeleteMode: .full(notify: false)) } },
|
||||
.cancel()
|
||||
]
|
||||
)
|
||||
} else {
|
||||
return ActionSheet(
|
||||
title: Text("Confirm contact deletion.\nThis cannot be undone!"),
|
||||
buttons: [
|
||||
.destructive(Text("Delete")) { Task { await deleteChatContact(chat, chatDeleteMode: .full(notify: false)) } },
|
||||
.cancel()
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user