MailboxViewController.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import UIKit
  2. import DcCore
  3. class MailboxViewController: ChatViewController {
  4. override init(dcContext: DcContext, chatId: Int, highlightedMsg: Int? = nil) {
  5. super.init(dcContext: dcContext, chatId: chatId)
  6. hidesBottomBarWhenPushed = true
  7. tableView.allowsSelectionDuringEditing = false
  8. showCustomNavBar = false
  9. }
  10. required init?(coder _: NSCoder) {
  11. fatalError("init(coder:) has not been implemented")
  12. }
  13. override func viewDidLoad() {
  14. super.viewDidLoad()
  15. navigationItem.title = String.localized("menu_deaddrop")
  16. }
  17. override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  18. askToChat(messageId: messageIds[indexPath.row])
  19. }
  20. override func phoneNumberTapped(number: String, indexPath: IndexPath) {}
  21. override func commandTapped(command: String, indexPath: IndexPath) {}
  22. override func urlTapped(url: URL, indexPath: IndexPath) {}
  23. override func imageTapped(indexPath: IndexPath) {
  24. askToChat(messageId: messageIds[indexPath.row])
  25. }
  26. override func avatarTapped(indexPath: IndexPath) {
  27. askToChat(messageId: messageIds[indexPath.row])
  28. }
  29. override func textTapped(indexPath: IndexPath) {
  30. askToChat(messageId: messageIds[indexPath.row])
  31. }
  32. func askToChat(messageId: Int) {
  33. if handleUIMenu() { return }
  34. let message = DcMsg(id: messageId)
  35. if message.isInfo {
  36. return
  37. }
  38. let dcContact = message.fromContact
  39. let title = String.localizedStringWithFormat(String.localized("ask_start_chat_with"), dcContact.nameNAddr)
  40. let alert = UIAlertController(title: title, message: nil, preferredStyle: .safeActionSheet)
  41. alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
  42. let chat = self.dcContext.createChatByMessageId(messageId)
  43. self.showChat(chatId: chat.id)
  44. }))
  45. alert.addAction(UIAlertAction(title: String.localized("menu_block_contact"), style: .destructive, handler: { _ in
  46. dcContact.block()
  47. }))
  48. alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel))
  49. present(alert, animated: true, completion: nil)
  50. }
  51. }