From 9e07aed5fd999d4004c23f0185a1105641718214 Mon Sep 17 00:00:00 2001 From: Woit Date: Fri, 22 Nov 2024 17:54:07 +0100 Subject: [PATCH] wip --- .../Resources/Strings/Localizable.strings | 3 +-- .../Views/Main/Contacts/ContactsScreen.swift | 23 +------------------ .../another.im/Views/Main/MainTabScreen.swift | 2 ++ Monal/another.im/XMPP/AimErrors.swift | 1 + Monal/another.im/XMPP/MonalXmppWrapper.swift | 14 +++++++---- 5 files changed, 14 insertions(+), 29 deletions(-) diff --git a/Monal/another.im/Resources/Strings/Localizable.strings b/Monal/another.im/Resources/Strings/Localizable.strings index 33cad33..1614e69 100644 --- a/Monal/another.im/Resources/Strings/Localizable.strings +++ b/Monal/another.im/Resources/Strings/Localizable.strings @@ -33,12 +33,11 @@ "Contacts.Add.explanation" = "Contact or group/channel name are usually JID in format name@domain.ltd (like email)"; "Contacts.Add.serverError" = "Contact adding dailed. Server returned error"; "Contacts.deleteContact" = "Delete contact"; -"Contacts.Delete.deleteFromDevice" = "Delete from device"; "Contacts.Delete.deleteCompletely" = "Delete completely"; "Contacts.sendMessage" = "Send message"; "Contacts.editContact" = "Edit contact"; "Contacts.selectContact" = "Select contact"; -"Contacts.Delete.message" = "You can delete contact from this device (contact will be available on other devices), or delete it completely"; +"Contacts.Delete.message" = "Contact will be deleted completelly"; "Contacts.Delete.error" = "Contact not deleted. Server returns error."; // MARK: Chats list screen diff --git a/Monal/another.im/Views/Main/Contacts/ContactsScreen.swift b/Monal/another.im/Views/Main/Contacts/ContactsScreen.swift index 1431ae9..af3d877 100644 --- a/Monal/another.im/Views/Main/Contacts/ContactsScreen.swift +++ b/Monal/another.im/Views/Main/Contacts/ContactsScreen.swift @@ -91,14 +91,6 @@ private struct ContactsScreenRow: View { } @ViewBuilder private var deleteConfirmation: some View { - Button(role: .destructive) { - Task { - await deleteFromDevice() - } - } label: { - Text(L10n.Contacts.Delete.deleteFromDevice) - } - Button(role: .destructive) { Task { await deleteCompletely() @@ -112,19 +104,6 @@ private struct ContactsScreenRow: View { } } - private func deleteFromDevice() async { - router.showModal { - LoadingScreen() - } - - defer { - router.dismissModal() - } - - // var roster = roster - // try? await roster.setLocallyDeleted(true) - } - private func deleteCompletely() async { router.showModal { LoadingScreen() @@ -135,7 +114,7 @@ private struct ContactsScreenRow: View { } do { - // try await clientsStore.deleteRoster(roster) + try await wrapper.deleteContact(contact) } catch { router.showAlert( .alert, diff --git a/Monal/another.im/Views/Main/MainTabScreen.swift b/Monal/another.im/Views/Main/MainTabScreen.swift index c2d0c95..7c8ce89 100644 --- a/Monal/another.im/Views/Main/MainTabScreen.swift +++ b/Monal/another.im/Views/Main/MainTabScreen.swift @@ -24,6 +24,7 @@ struct MainTabScreen: View { switch selectedTab { case .chats: Text("chats") + Spacer() // ChatsListScreen() case .contacts: @@ -31,6 +32,7 @@ struct MainTabScreen: View { case .settings: Text("settings") + Spacer() // SettingsScreen() // .environment(\.settingsParent, .main) } diff --git a/Monal/another.im/XMPP/AimErrors.swift b/Monal/another.im/XMPP/AimErrors.swift index dd621d5..2ac6658 100644 --- a/Monal/another.im/XMPP/AimErrors.swift +++ b/Monal/another.im/XMPP/AimErrors.swift @@ -1,3 +1,4 @@ enum AimErrors: Error { case loginError + case contactRemoveError } diff --git a/Monal/another.im/XMPP/MonalXmppWrapper.swift b/Monal/another.im/XMPP/MonalXmppWrapper.swift index 6da45a3..6a26d72 100644 --- a/Monal/another.im/XMPP/MonalXmppWrapper.swift +++ b/Monal/another.im/XMPP/MonalXmppWrapper.swift @@ -42,12 +42,16 @@ extension MonalXmppWrapper { } func addContact(contactJid: String, forAccountID: Int) async { - await withCheckedContinuation { [weak self] cnt in - let contact = MLContact.createContact(fromJid: contactJid, andAccountID: NSNumber(value: forAccountID)) - self?.xmpp.add(contact) - cnt.resume() + let contact = MLContact.createContact(fromJid: contactJid, andAccountID: NSNumber(value: forAccountID)) + xmpp.add(contact) + } + + func deleteContact(_ contact: Contact) async throws { + if let mlContact = db.contactList().first(where: { $0.contactJid == contact.contactJid }) { + xmpp.remove(mlContact) + } else { + throw AimErrors.contactRemoveError } - NotificationCenter.default.post(name: Notification.Name(kMonalContactRefresh), object: nil) } }