IMInstantMessageViewController.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // IMInstantMessageViewController.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2020/6/12.
  6. // Copyright © 2020 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. class IMInstantMessageViewController: UITableViewController {
  10. private lazy var viewModel: IMViewModel = {
  11. return IMViewModel()
  12. }()
  13. var instantMsgList: [InstantMessage] = []
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16. self.title = "通知消息"
  17. self.tableView.register(UINib(nibName: "IMChatMessageViewCell", bundle: nil), forCellReuseIdentifier: "IMChatMessageViewCell")
  18. self.tableView.separatorStyle = .none
  19. // self.tableView.rowHeight = UITableView.automaticDimension
  20. // self.tableView.estimatedRowHeight = 144
  21. self.tableView.backgroundColor = UIColor(hex: "#f3f3f3")
  22. }
  23. override func viewDidAppear(_ animated: Bool) {
  24. self.scrollMessageToBottom()
  25. }
  26. //刷新tableview 滚动到底部
  27. private func scrollMessageToBottom() {
  28. DispatchQueue.main.async {
  29. if self.instantMsgList.count > 0 {
  30. self.tableView.scrollToRow(at: IndexPath(row: self.instantMsgList.count-1, section: 0), at: .bottom, animated: false)
  31. }
  32. }
  33. }
  34. // MARK: - Table view data source
  35. override func numberOfSections(in tableView: UITableView) -> Int {
  36. return 1
  37. }
  38. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  39. return self.instantMsgList.count
  40. }
  41. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  42. if let cell = tableView.dequeueReusableCell(withIdentifier: "IMChatMessageViewCell", for: indexPath) as? IMChatMessageViewCell {
  43. cell.setInstantContent(item: self.instantMsgList[indexPath.row])
  44. cell.delegate = self
  45. return cell
  46. }
  47. return UITableViewCell()
  48. }
  49. override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  50. return cellHeightForInstant(item: self.instantMsgList[indexPath.row])
  51. }
  52. func cellHeightForInstant(item: InstantMessage) -> CGFloat {
  53. if let msg = item.title {
  54. let size = msg.getSizeWithMaxWidth(fontSize: 16, maxWidth: messageWidth)
  55. // 上边距 69 + 文字高度 + 内边距 + 底部空白高度
  56. return 69 + size.height + 28 + 10
  57. }
  58. return 132
  59. }
  60. override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  61. tableView.deselectRow(at: indexPath, animated: false)
  62. }
  63. }
  64. extension IMInstantMessageViewController : IMChatMessageDelegate {
  65. func playAudio(info: IMMessageBodyInfo, id: String?) {
  66. }
  67. func openImageOrFileMessage(info: IMMessageBodyInfo) {
  68. //无需实现
  69. }
  70. func openLocatinMap(info: IMMessageBodyInfo) {
  71. //无需实现
  72. }
  73. func openApplication(storyboard: String) {
  74. if storyboard == "mind" {
  75. // let flutterViewController = O2FlutterViewController()
  76. // flutterViewController.setInitialRoute("mindMap")
  77. // flutterViewController.modalPresentationStyle = .fullScreen
  78. // self.present(flutterViewController, animated: false, completion: nil)
  79. }else {
  80. let storyBoard = UIStoryboard(name: storyboard, bundle: nil)
  81. guard let destVC = storyBoard.instantiateInitialViewController() else {
  82. return
  83. }
  84. destVC.modalPresentationStyle = .fullScreen
  85. if destVC.isKind(of: ZLNavigationController.self) {
  86. self.show(destVC, sender: nil)
  87. }else{
  88. self.navigationController?.pushViewController(destVC, animated: true)
  89. }
  90. }
  91. }
  92. func openWork(workId: String) {
  93. self.openWorkPage(work: workId)
  94. // 已经支持 未结束和结束的工作打开
  95. // self.showLoading()
  96. // self.viewModel.isWorkCompleted(work: workId).always {
  97. // self.hideLoading()
  98. // }.then{ result in
  99. // if result {
  100. // self.showMessage(msg: "工作已经完成了!")
  101. // }else {
  102. // self.openWorkPage(work: workId)
  103. // }
  104. // }.catch {_ in
  105. // self.showMessage(msg: "工作已经完成了!")
  106. // }
  107. }
  108. private func openWorkPage(work: String) {
  109. let storyBoard = UIStoryboard(name: "task", bundle: nil)
  110. let destVC = storyBoard.instantiateViewController(withIdentifier: "todoTaskDetailVC") as! TodoTaskDetailViewController
  111. let json = """
  112. {"work":"\(work)", "workCompleted":"", "title":""}
  113. """
  114. let todo = TodoTask(JSONString: json)
  115. destVC.todoTask = todo
  116. destVC.backFlag = 3 //隐藏就行
  117. self.show(destVC, sender: nil)
  118. }
  119. }