wip
This commit is contained in:
parent
49f1028d69
commit
9e07aed5fd
|
@ -33,12 +33,11 @@
|
||||||
"Contacts.Add.explanation" = "Contact or group/channel name are usually JID in format name@domain.ltd (like email)";
|
"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.Add.serverError" = "Contact adding dailed. Server returned error";
|
||||||
"Contacts.deleteContact" = "Delete contact";
|
"Contacts.deleteContact" = "Delete contact";
|
||||||
"Contacts.Delete.deleteFromDevice" = "Delete from device";
|
|
||||||
"Contacts.Delete.deleteCompletely" = "Delete completely";
|
"Contacts.Delete.deleteCompletely" = "Delete completely";
|
||||||
"Contacts.sendMessage" = "Send message";
|
"Contacts.sendMessage" = "Send message";
|
||||||
"Contacts.editContact" = "Edit contact";
|
"Contacts.editContact" = "Edit contact";
|
||||||
"Contacts.selectContact" = "Select 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.";
|
"Contacts.Delete.error" = "Contact not deleted. Server returns error.";
|
||||||
|
|
||||||
// MARK: Chats list screen
|
// MARK: Chats list screen
|
||||||
|
|
|
@ -91,14 +91,6 @@ private struct ContactsScreenRow: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder private var deleteConfirmation: some View {
|
@ViewBuilder private var deleteConfirmation: some View {
|
||||||
Button(role: .destructive) {
|
|
||||||
Task {
|
|
||||||
await deleteFromDevice()
|
|
||||||
}
|
|
||||||
} label: {
|
|
||||||
Text(L10n.Contacts.Delete.deleteFromDevice)
|
|
||||||
}
|
|
||||||
|
|
||||||
Button(role: .destructive) {
|
Button(role: .destructive) {
|
||||||
Task {
|
Task {
|
||||||
await deleteCompletely()
|
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 {
|
private func deleteCompletely() async {
|
||||||
router.showModal {
|
router.showModal {
|
||||||
LoadingScreen()
|
LoadingScreen()
|
||||||
|
@ -135,7 +114,7 @@ private struct ContactsScreenRow: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
// try await clientsStore.deleteRoster(roster)
|
try await wrapper.deleteContact(contact)
|
||||||
} catch {
|
} catch {
|
||||||
router.showAlert(
|
router.showAlert(
|
||||||
.alert,
|
.alert,
|
||||||
|
|
|
@ -24,6 +24,7 @@ struct MainTabScreen: View {
|
||||||
switch selectedTab {
|
switch selectedTab {
|
||||||
case .chats:
|
case .chats:
|
||||||
Text("chats")
|
Text("chats")
|
||||||
|
Spacer()
|
||||||
// ChatsListScreen()
|
// ChatsListScreen()
|
||||||
|
|
||||||
case .contacts:
|
case .contacts:
|
||||||
|
@ -31,6 +32,7 @@ struct MainTabScreen: View {
|
||||||
|
|
||||||
case .settings:
|
case .settings:
|
||||||
Text("settings")
|
Text("settings")
|
||||||
|
Spacer()
|
||||||
// SettingsScreen()
|
// SettingsScreen()
|
||||||
// .environment(\.settingsParent, .main)
|
// .environment(\.settingsParent, .main)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
enum AimErrors: Error {
|
enum AimErrors: Error {
|
||||||
case loginError
|
case loginError
|
||||||
|
case contactRemoveError
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,12 +42,16 @@ extension MonalXmppWrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
func addContact(contactJid: String, forAccountID: Int) async {
|
func addContact(contactJid: String, forAccountID: Int) async {
|
||||||
await withCheckedContinuation { [weak self] cnt in
|
let contact = MLContact.createContact(fromJid: contactJid, andAccountID: NSNumber(value: forAccountID))
|
||||||
let contact = MLContact.createContact(fromJid: contactJid, andAccountID: NSNumber(value: forAccountID))
|
xmpp.add(contact)
|
||||||
self?.xmpp.add(contact)
|
}
|
||||||
cnt.resume()
|
|
||||||
|
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue