IMChatPrivateSetViewController.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // IMChatPrivateSetViewController.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/11/13.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. import RongIMLib
  10. class IMChatPrivateSetViewController: BaseViewController {
  11. /// 会话目标
  12. var targetId : String?
  13. /// 会话类型
  14. var type : RCConversationType?
  15. typealias BackClosure = () -> Void
  16. var backClosure : BackClosure?
  17. let sections = [["置顶聊天","屏蔽消息"],
  18. ["清空聊天记录"]]
  19. override func viewDidLoad() {
  20. super.viewDidLoad()
  21. setupViews()
  22. setupLayouts()
  23. }
  24. override func setupViews() {
  25. navigationBar.title = "聊天信息"
  26. view.addSubview(tableView)
  27. }
  28. override func setupLayouts() {
  29. tableView.snp.makeConstraints { (make) in
  30. make.right.left.bottom.equalToSuperview()
  31. make.top.equalTo(kNavBarTotalHeight)
  32. }
  33. }
  34. private lazy var tableView: UITableView = {
  35. let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
  36. tableView.backgroundColor = kf7f8faColor
  37. tableView.delegate = self
  38. tableView.dataSource = self
  39. tableView.rowHeight = 48
  40. tableView.separatorStyle = .none
  41. return tableView
  42. }()
  43. override func didMove(toParent parent: UIViewController?) {
  44. if !(parent != nil) {
  45. }
  46. }
  47. }
  48. extension IMChatPrivateSetViewController: UITableViewDelegate,UITableViewDataSource {
  49. func numberOfSections(in tableView: UITableView) -> Int {
  50. return sections.count
  51. }
  52. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  53. return sections[section].count
  54. }
  55. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  56. switch indexPath.section {
  57. case 0:
  58. let cell = IMChatPrivateSetOneTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  59. cell.title = sections[indexPath.section][indexPath.row]
  60. cell.type = type
  61. cell.targetId = targetId
  62. return cell
  63. case 1:
  64. let cell = IMChatPrivateSetTwoTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  65. cell.title = sections[indexPath.section][indexPath.row]
  66. cell.type = type
  67. cell.targetId = targetId
  68. return cell
  69. default:
  70. return UITableViewCell()
  71. }
  72. }
  73. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  74. switch indexPath.section {
  75. case 1:
  76. RCIMClient.shared()?.clearHistoryMessages(type!, targetId: targetId!, recordTime: 0, clearRemote: true, success: { [weak self] in
  77. DispatchQueue.main.async {
  78. if let backClosure = self?.backClosure {
  79. backClosure()
  80. }
  81. SwiftProgressHUD.shared().showText("清理成功!")
  82. }
  83. }, error: { (errorCode) in
  84. DispatchQueue.main.async {
  85. SwiftProgressHUD.shared().showText("清理失败!")
  86. }
  87. })
  88. break
  89. default:
  90. break
  91. }
  92. }
  93. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  94. return nil
  95. }
  96. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  97. return 10
  98. }
  99. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  100. return nil
  101. }
  102. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  103. return 0.0000001
  104. }
  105. }