This commit is contained in:
Woit 2024-11-22 17:54:07 +01:00
parent 49f1028d69
commit 9e07aed5fd
5 changed files with 14 additions and 29 deletions

View file

@ -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

View file

@ -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,

View file

@ -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)
}

View file

@ -1,3 +1,4 @@
enum AimErrors: Error {
case loginError
case contactRemoveError
}

View file

@ -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()
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)
}
}