|
@@ -147,49 +147,22 @@ class ContactDetailViewController: UITableViewController {
|
|
|
|
|
|
private func handleCellAction(for index: Int) {
|
|
|
if index == 0 {
|
|
|
- coordinator?.archiveChat()
|
|
|
+ toggleArchiveChat()
|
|
|
} else if index == 1 {
|
|
|
toggleBlockContact()
|
|
|
} else {
|
|
|
safe_assert(index == 2)
|
|
|
showDeleteChatConfirmationAlert()
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- private func askToChatWith(contactId: Int) {
|
|
|
- let dcContact = DcContact(id: contactId)
|
|
|
- let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), dcContact.nameNAddr),
|
|
|
- message: nil,
|
|
|
- preferredStyle: .safeActionSheet)
|
|
|
- alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
|
|
|
- self.dismiss(animated: true, completion: nil)
|
|
|
- let chatId = Int(dc_create_chat_by_contact_id(mailboxPointer, UInt32(contactId)))
|
|
|
- self.coordinator?.showChat(chatId: chatId)
|
|
|
- }))
|
|
|
- alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: { _ in
|
|
|
- self.dismiss(animated: true, completion: nil)
|
|
|
- }))
|
|
|
- present(alert, animated: true, completion: nil)
|
|
|
+
|
|
|
+ private func toggleArchiveChat() {
|
|
|
+ let archived = viewModel.toggleArchiveChat()
|
|
|
+ updateArchiveChatCell(archived: archived)
|
|
|
}
|
|
|
|
|
|
- private func toggleBlockContact() {
|
|
|
- if viewModel.contact.isBlocked {
|
|
|
- let alert = UIAlertController(title: String.localized("ask_unblock_contact"), message: nil, preferredStyle: .safeActionSheet)
|
|
|
- alert.addAction(UIAlertAction(title: String.localized("menu_unblock_contact"), style: .default, handler: { _ in
|
|
|
- self.viewModel.contact.unblock()
|
|
|
- self.updateBlockContactCell()
|
|
|
- }))
|
|
|
- alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
|
|
|
- present(alert, animated: true, completion: nil)
|
|
|
- } else {
|
|
|
- let alert = UIAlertController(title: String.localized("ask_block_contact"), message: nil, preferredStyle: .safeActionSheet)
|
|
|
- alert.addAction(UIAlertAction(title: String.localized("menu_block_contact"), style: .destructive, handler: { _ in
|
|
|
- self.viewModel.contact.block()
|
|
|
- self.updateBlockContactCell()
|
|
|
- }))
|
|
|
- alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
|
|
|
- present(alert, animated: true, completion: nil)
|
|
|
- }
|
|
|
+ private func updateArchiveChatCell(archived: Bool) {
|
|
|
+ archiveChatCell.actionTitle = archived ? String.localized("menu_unarchive_chat") : String.localized("menu_archive_chat")
|
|
|
}
|
|
|
|
|
|
private func updateBlockContactCell() {
|
|
@@ -197,19 +170,14 @@ class ContactDetailViewController: UITableViewController {
|
|
|
blockContactCell.actionColor = viewModel.contact.isBlocked ? SystemColor.blue.uiColor : UIColor.red
|
|
|
}
|
|
|
|
|
|
- private func showNotificationSetup() {
|
|
|
- let notificationSetupAlert = UIAlertController(title: "Notifications Setup is not implemented yet",
|
|
|
- message: "But you get an idea where this is going",
|
|
|
- preferredStyle: .safeActionSheet)
|
|
|
- let cancelAction = UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil)
|
|
|
- notificationSetupAlert.addAction(cancelAction)
|
|
|
- present(notificationSetupAlert, animated: true, completion: nil)
|
|
|
- }
|
|
|
|
|
|
@objc private func editButtonPressed() {
|
|
|
coordinator?.showEditContact(contactId: viewModel.contactId)
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
+// MARK: alerts
|
|
|
+extension ContactDetailViewController {
|
|
|
private func showDeleteChatConfirmationAlert() {
|
|
|
let alert = UIAlertController(
|
|
|
title: nil,
|
|
@@ -222,4 +190,52 @@ class ContactDetailViewController: UITableViewController {
|
|
|
alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
|
|
|
self.present(alert, animated: true, completion: nil)
|
|
|
}
|
|
|
+
|
|
|
+ private func showNotificationSetup() {
|
|
|
+ let notificationSetupAlert = UIAlertController(
|
|
|
+ title: "Notifications Setup is not implemented yet",
|
|
|
+ message: "But you get an idea where this is going",
|
|
|
+ preferredStyle: .safeActionSheet)
|
|
|
+ let cancelAction = UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil)
|
|
|
+ notificationSetupAlert.addAction(cancelAction)
|
|
|
+ present(notificationSetupAlert, animated: true, completion: nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ private func toggleBlockContact() {
|
|
|
+ if viewModel.contact.isBlocked {
|
|
|
+ let alert = UIAlertController(title: String.localized("ask_unblock_contact"), message: nil, preferredStyle: .safeActionSheet)
|
|
|
+ alert.addAction(UIAlertAction(title: String.localized("menu_unblock_contact"), style: .default, handler: { _ in
|
|
|
+ self.viewModel.contact.unblock()
|
|
|
+ self.updateBlockContactCell()
|
|
|
+ }))
|
|
|
+ alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
|
|
|
+ present(alert, animated: true, completion: nil)
|
|
|
+ } else {
|
|
|
+ let alert = UIAlertController(title: String.localized("ask_block_contact"), message: nil, preferredStyle: .safeActionSheet)
|
|
|
+ alert.addAction(UIAlertAction(title: String.localized("menu_block_contact"), style: .destructive, handler: { _ in
|
|
|
+ self.viewModel.contact.block()
|
|
|
+ self.updateBlockContactCell()
|
|
|
+ }))
|
|
|
+ alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
|
|
|
+ present(alert, animated: true, completion: nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private func askToChatWith(contactId: Int) {
|
|
|
+ let dcContact = DcContact(id: contactId)
|
|
|
+ let alert = UIAlertController(title: String.localizedStringWithFormat(
|
|
|
+ String.localized("ask_start_chat_with"), dcContact.nameNAddr),
|
|
|
+ message: nil,
|
|
|
+ preferredStyle: .safeActionSheet)
|
|
|
+ alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
|
|
|
+ self.dismiss(animated: true, completion: nil)
|
|
|
+ let chatId = Int(dc_create_chat_by_contact_id(mailboxPointer, UInt32(contactId)))
|
|
|
+ self.coordinator?.showChat(chatId: chatId)
|
|
|
+ }))
|
|
|
+ alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: { _ in
|
|
|
+ self.dismiss(animated: true, completion: nil)
|
|
|
+ }))
|
|
|
+ present(alert, animated: true, completion: nil)
|
|
|
+ }
|
|
|
+
|
|
|
}
|