IMChatViewController.swift 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. //
  2. // IMChatViewController.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2020/6/8.
  6. // Copyright © 2020 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import CocoaLumberjack
  10. import O2OA_Auth_SDK
  11. import BSImagePicker
  12. import Photos
  13. import Alamofire
  14. import AlamofireImage
  15. import SwiftyJSON
  16. import QuickLook
  17. class IMChatViewController: UIViewController {
  18. // MARK: - IBOutlet
  19. //消息列表
  20. @IBOutlet weak var tableView: UITableView!
  21. //消息输入框
  22. @IBOutlet weak var messageInputView: UITextField!
  23. //底部工具栏的高度约束
  24. @IBOutlet weak var bottomBarHeightConstraint: NSLayoutConstraint!
  25. //底部工具栏
  26. @IBOutlet weak var bottomBar: UIView!
  27. private let emojiBarHeight = 196
  28. //表情窗口
  29. private lazy var emojiBar: IMChatEmojiBarView = {
  30. let view = Bundle.main.loadNibNamed("IMChatEmojiBarView", owner: self, options: nil)?.first as! IMChatEmojiBarView
  31. view.frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: emojiBarHeight.toCGFloat)
  32. return view
  33. }()
  34. //语音录制按钮
  35. private lazy var audioBtnView: IMChatAudioView = {
  36. let view = Bundle.main.loadNibNamed("IMChatAudioView", owner: self, options: nil)?.first as! IMChatAudioView
  37. view.frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: emojiBarHeight.toCGFloat)
  38. view.delegate = self
  39. return view
  40. }()
  41. //预览文件
  42. private lazy var previewVC: CloudFilePreviewController = {
  43. return CloudFilePreviewController()
  44. }()
  45. private lazy var viewModel: IMViewModel = {
  46. return IMViewModel()
  47. }()
  48. // MARK: - properties
  49. var conversation: IMConversationInfo? = nil
  50. private var chatMessageList: [IMMessageInfo] = []
  51. private var page = 1
  52. private var isShowEmoji = false
  53. private var isShowAudioView = false
  54. private var bottomBarHeight = 64 //底部输入框 表情按钮 的高度
  55. private let bottomToolbarHeight = 46 //底部工具栏 麦克风 相册 相机等按钮的位置
  56. // MARK: - functions
  57. override func viewDidLoad() {
  58. super.viewDidLoad()
  59. self.tableView.delegate = self
  60. self.tableView.dataSource = self
  61. self.tableView.register(UINib(nibName: "IMChatMessageViewCell", bundle: nil), forCellReuseIdentifier: "IMChatMessageViewCell")
  62. self.tableView.register(UINib(nibName: "IMChatMessageSendViewCell", bundle: nil), forCellReuseIdentifier: "IMChatMessageSendViewCell")
  63. self.tableView.separatorStyle = .none
  64. self.tableView.rowHeight = UITableView.automaticDimension
  65. self.tableView.estimatedRowHeight = 144
  66. self.messageInputView.delegate = self
  67. //底部安全距离 老机型没有
  68. self.bottomBarHeight = Int(iPhoneX ? 64 + IPHONEX_BOTTOM_SAFE_HEIGHT: 64) + self.bottomToolbarHeight
  69. self.bottomBarHeightConstraint.constant = self.bottomBarHeight.toCGFloat
  70. self.bottomBar.topBorder(width: 1, borderColor: base_gray_color.alpha(0.5))
  71. self.messageInputView.backgroundColor = base_gray_color
  72. //标题
  73. if self.conversation?.type == o2_im_conversation_type_single {
  74. if let c = self.conversation {
  75. var person = ""
  76. c.personList?.forEach({ (p) in
  77. if p != O2AuthSDK.shared.myInfo()?.distinguishedName {
  78. person = p
  79. }
  80. })
  81. if !person.isEmpty {
  82. self.title = person.split("@").first ?? ""
  83. }
  84. }
  85. } else {
  86. self.title = self.conversation?.title
  87. }
  88. //获取聊天数据
  89. self.loadMsgList(page: page)
  90. //阅读
  91. self.viewModel.readConversation(conversationId: self.conversation?.id)
  92. }
  93. override func viewWillAppear(_ animated: Bool) {
  94. NotificationCenter.default.addObserver(self, selector: #selector(receiveMessageFromWs(notice:)), name: OONotification.websocket.notificationName, object: nil)
  95. }
  96. override func viewWillDisappear(_ animated: Bool) {
  97. NotificationCenter.default.removeObserver(self)
  98. }
  99. @objc private func receiveMessageFromWs(notice: Notification) {
  100. DDLogDebug("接收到websocket im 消息")
  101. if let message = notice.object as? IMMessageInfo {
  102. if message.conversationId == self.conversation?.id {
  103. self.chatMessageList.append(message)
  104. self.scrollMessageToBottom()
  105. self.viewModel.readConversation(conversationId: self.conversation?.id)
  106. }
  107. }
  108. }
  109. //获取消息
  110. private func loadMsgList(page: Int) {
  111. if let c = self.conversation, let id = c.id {
  112. self.viewModel.myMsgPageList(page: page, conversationId: id).then { (list) in
  113. self.chatMessageList = list
  114. self.scrollMessageToBottom()
  115. }
  116. } else {
  117. self.showError(title: "参数错误!!!")
  118. }
  119. }
  120. //刷新tableview 滚动到底部
  121. private func scrollMessageToBottom() {
  122. DispatchQueue.main.async {
  123. self.tableView.reloadData()
  124. if self.chatMessageList.count > 0 {
  125. self.tableView.scrollToRow(at: IndexPath(row: self.chatMessageList.count - 1, section: 0), at: .bottom, animated: true)
  126. }
  127. }
  128. }
  129. //发送文本消息
  130. private func sendTextMessage() {
  131. guard let msg = self.messageInputView.text else {
  132. return
  133. }
  134. self.messageInputView.text = ""
  135. let body = IMMessageBodyInfo()
  136. body.type = o2_im_msg_type_text
  137. body.body = msg
  138. sendMessage(body: body)
  139. }
  140. //发送表情消息
  141. private func sendEmojiMessage(emoji: String) {
  142. let body = IMMessageBodyInfo()
  143. body.type = o2_im_msg_type_emoji
  144. body.body = emoji
  145. sendMessage(body: body)
  146. }
  147. //发送消息到服务器
  148. private func sendMessage(body: IMMessageBodyInfo) {
  149. let message = IMMessageInfo()
  150. message.body = body.toJSONString()
  151. message.id = UUID().uuidString
  152. message.conversationId = self.conversation?.id
  153. message.createPerson = O2AuthSDK.shared.myInfo()?.distinguishedName
  154. message.createTime = Date().formatterDate(formatter: "yyyy-MM-dd HH:mm:ss")
  155. //添加到界面
  156. self.chatMessageList.append(message)
  157. self.scrollMessageToBottom()
  158. //发送消息到服务器
  159. self.viewModel.sendMsg(msg: message)
  160. .then { (result) in
  161. DDLogDebug("发送消息成功 \(result)")
  162. self.viewModel.readConversation(conversationId: self.conversation?.id)
  163. }.catch { (error) in
  164. DDLogError(error.localizedDescription)
  165. self.showError(title: "发送消息失败!")
  166. }
  167. }
  168. //选择照片
  169. private func chooseImage() {
  170. let vc = FileBSImagePickerViewController().bsImagePicker()
  171. vc.settings.fetch.assets.supportedMediaTypes = [.image]
  172. presentImagePicker(vc, select: { (asset) in
  173. //选中一个
  174. }, deselect: { (asset) in
  175. //取消选中一个
  176. }, cancel: { (assets) in
  177. //取消
  178. }, finish: { (assets) in
  179. //结果
  180. if assets.count > 0 {
  181. switch assets[0].mediaType {
  182. case .image:
  183. let options = PHImageRequestOptions()
  184. options.isSynchronous = true
  185. options.deliveryMode = .fastFormat
  186. options.resizeMode = .none
  187. PHImageManager.default().requestImageData(for: assets[0], options: options) { (imageData, result, imageOrientation, dict) in
  188. guard let data = imageData else {
  189. return
  190. }
  191. var newData = data
  192. //处理图片旋转的问题
  193. if imageOrientation != UIImage.Orientation.up {
  194. let newImage = UIImage(data: data)?.fixOrientation()
  195. if newImage != nil {
  196. newData = newImage!.pngData()!
  197. }
  198. }
  199. var fileName = ""
  200. if dict?["PHImageFileURLKey"] != nil {
  201. let fileURL = dict?["PHImageFileURLKey"] as! URL
  202. fileName = fileURL.lastPathComponent
  203. } else {
  204. fileName = "\(UUID().uuidString).png"
  205. }
  206. let localFilePath = self.storageLocalImage(imageData: newData, fileName: fileName)
  207. let msgId = self.prepareForSendImageMsg(filePath: localFilePath)
  208. self.uploadImageAndSendMsg(messageId: msgId, imageData: newData, fileName: fileName)
  209. }
  210. break
  211. default:
  212. //
  213. DDLogError("不支持的类型")
  214. self.showError(title: "不支持的类型!")
  215. break
  216. }
  217. }
  218. }, completion: nil)
  219. }
  220. //临时存储本地
  221. private func storageLocalImage(imageData: Data, fileName: String) -> String {
  222. let fileTempPath = FileUtil.share.cacheDir().appendingPathComponent(fileName)
  223. do {
  224. try imageData.write(to: fileTempPath)
  225. return fileTempPath.path
  226. } catch {
  227. print(error.localizedDescription)
  228. return fileTempPath.path
  229. }
  230. }
  231. //发送消息前 先载入界面
  232. private func prepareForSendImageMsg(filePath: String) -> String {
  233. let body = IMMessageBodyInfo()
  234. body.type = o2_im_msg_type_image
  235. body.body = o2_im_msg_body_image
  236. body.fileTempPath = filePath
  237. let message = IMMessageInfo()
  238. let msgId = UUID().uuidString
  239. message.body = body.toJSONString()
  240. message.id = msgId
  241. message.conversationId = self.conversation?.id
  242. message.createPerson = O2AuthSDK.shared.myInfo()?.distinguishedName
  243. message.createTime = Date().formatterDate(formatter: "yyyy-MM-dd HH:mm:ss")
  244. //添加到界面
  245. self.chatMessageList.append(message)
  246. self.scrollMessageToBottom()
  247. return msgId
  248. }
  249. //发送消息前 先载入界面
  250. private func prepareForSendFileMsg(tempMessage: IMMessageBodyInfo) -> String {
  251. let message = IMMessageInfo()
  252. let msgId = UUID().uuidString
  253. message.body = tempMessage.toJSONString()
  254. message.id = msgId
  255. message.conversationId = self.conversation?.id
  256. message.createPerson = O2AuthSDK.shared.myInfo()?.distinguishedName
  257. message.createTime = Date().formatterDate(formatter: "yyyy-MM-dd HH:mm:ss")
  258. //添加到界面
  259. self.chatMessageList.append(message)
  260. self.scrollMessageToBottom()
  261. return msgId
  262. }
  263. //上传图片到服务器并发送消息
  264. private func uploadImageAndSendMsg(messageId: String, imageData: Data, fileName: String) {
  265. guard let cId = self.conversation?.id else {
  266. return
  267. }
  268. self.viewModel.uploadFile(conversationId: cId, type: o2_im_msg_type_image, fileName: fileName, file: imageData).then { attachId in
  269. DDLogDebug("上传图片成功: \(attachId)")
  270. guard let message = self.chatMessageList.first (where: { (info) -> Bool in
  271. return info.id == messageId
  272. }) else {
  273. DDLogDebug("没有找到对应的消息")
  274. return
  275. }
  276. let body = IMMessageBodyInfo.deserialize(from: message.body)
  277. body?.fileId = attachId
  278. body?.fileTempPath = nil
  279. message.body = body?.toJSONString()
  280. //发送消息到服务器
  281. self.viewModel.sendMsg(msg: message)
  282. .then { (result) in
  283. DDLogDebug("图片消息 发送成功 \(result)")
  284. self.viewModel.readConversation(conversationId: self.conversation?.id)
  285. }.catch { (error) in
  286. DDLogError(error.localizedDescription)
  287. self.showError(title: "发送消息失败!")
  288. }
  289. }.catch { err in
  290. self.showError(title: "上传错误,\(err.localizedDescription)")
  291. }
  292. }
  293. //上传图片 音频 等文件到服务器并发送消息
  294. private func uploadFileAndSendMsg(messageId: String, data: Data, fileName: String, type: String) {
  295. guard let cId = self.conversation?.id else {
  296. return
  297. }
  298. self.viewModel.uploadFile(conversationId: cId, type: type, fileName: fileName, file: data).then { attachId in
  299. DDLogDebug("上传图片成功: \(attachId)")
  300. guard let message = self.chatMessageList.first (where: { (info) -> Bool in
  301. return info.id == messageId
  302. }) else {
  303. DDLogDebug("没有找到对应的消息")
  304. return
  305. }
  306. let body = IMMessageBodyInfo.deserialize(from: message.body)
  307. body?.fileId = attachId
  308. body?.fileTempPath = nil
  309. message.body = body?.toJSONString()
  310. //发送消息到服务器
  311. self.viewModel.sendMsg(msg: message)
  312. .then { (result) in
  313. DDLogDebug("图片消息 发送成功 \(result)")
  314. self.viewModel.readConversation(conversationId: self.conversation?.id)
  315. }.catch { (error) in
  316. DDLogError(error.localizedDescription)
  317. self.showError(title: "发送消息失败!")
  318. }
  319. }.catch { err in
  320. self.showError(title: "上传错误,\(err.localizedDescription)")
  321. }
  322. }
  323. // MARK: - IBAction
  324. //点击表情按钮
  325. @IBAction func clickEmojiBtn(_ sender: UIButton) {
  326. self.isShowEmoji.toggle()
  327. self.view.endEditing(true)
  328. if self.isShowEmoji {
  329. //audio view 先关闭
  330. self.isShowAudioView = false
  331. self.audioBtnView.removeFromSuperview()
  332. //开始添加emojiBar
  333. self.bottomBarHeightConstraint.constant = self.bottomBarHeight.toCGFloat + self.emojiBarHeight.toCGFloat
  334. self.emojiBar.delegate = self
  335. self.emojiBar.translatesAutoresizingMaskIntoConstraints = false
  336. self.bottomBar.addSubview(self.emojiBar)
  337. let top = NSLayoutConstraint(item: self.emojiBar, attribute: .top, relatedBy: .equal, toItem: self.emojiBar.superview!, attribute: .top, multiplier: 1, constant: CGFloat(self.bottomBarHeight))
  338. let width = NSLayoutConstraint(item: self.emojiBar, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: SCREEN_WIDTH)
  339. let height = NSLayoutConstraint(item: self.emojiBar, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: self.emojiBarHeight.toCGFloat)
  340. NSLayoutConstraint.activate([top, width, height])
  341. } else {
  342. self.bottomBarHeightConstraint.constant = self.bottomBarHeight.toCGFloat
  343. self.emojiBar.removeFromSuperview()
  344. }
  345. self.view.layoutIfNeeded()
  346. }
  347. @IBAction func micBtnClick(_ sender: UIButton) {
  348. DDLogDebug("点击了麦克风按钮")
  349. self.isShowAudioView.toggle()
  350. self.view.endEditing(true)
  351. if self.isShowAudioView {
  352. //emoji view 先关闭
  353. self.isShowEmoji = false
  354. self.emojiBar.removeFromSuperview()
  355. //开始添加emojiBar
  356. self.bottomBarHeightConstraint.constant = self.bottomBarHeight.toCGFloat + self.emojiBarHeight.toCGFloat
  357. self.audioBtnView.translatesAutoresizingMaskIntoConstraints = false
  358. self.bottomBar.addSubview(self.audioBtnView)
  359. let top = NSLayoutConstraint(item: self.audioBtnView, attribute: .top, relatedBy: .equal, toItem: self.audioBtnView.superview!, attribute: .top, multiplier: 1, constant: CGFloat(self.bottomBarHeight))
  360. let width = NSLayoutConstraint(item: self.audioBtnView, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: SCREEN_WIDTH)
  361. let height = NSLayoutConstraint(item: self.audioBtnView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: self.emojiBarHeight.toCGFloat)
  362. NSLayoutConstraint.activate([top, width, height])
  363. }else {
  364. self.bottomBarHeightConstraint.constant = self.bottomBarHeight.toCGFloat
  365. self.audioBtnView.removeFromSuperview()
  366. }
  367. self.view.layoutIfNeeded()
  368. }
  369. @IBAction func imgBtnClick(_ sender: UIButton) {
  370. DDLogDebug("点击了图片按钮")
  371. self.chooseImage()
  372. }
  373. @IBAction func cameraBtnClick(_ sender: UIButton) {
  374. DDLogDebug("点击了相机按钮")
  375. self.takePhoto(delegate: self)
  376. }
  377. @IBAction func locationBtnClick(_ sender: UIButton) {
  378. DDLogDebug("点击了位置按钮")
  379. }
  380. }
  381. // MARK: - 录音delegate
  382. extension IMChatViewController: IMChatAudioViewDelegate {
  383. func sendVoice(path: String, voice: Data, duration: String) {
  384. let msg = IMMessageBodyInfo()
  385. msg.fileTempPath = path
  386. msg.body = o2_im_msg_body_audio
  387. msg.type = o2_im_msg_type_audio
  388. msg.audioDuration = duration
  389. let msgId = self.prepareForSendFileMsg(tempMessage: msg)
  390. let fileName = path.split("/").last ?? "MySound.ilbc"
  391. DDLogDebug("音频文件:\(fileName)")
  392. self.uploadFileAndSendMsg(messageId: msgId, data: voice, fileName: fileName, type: o2_im_msg_type_audio)
  393. }
  394. }
  395. // MARK: - 拍照delegate
  396. extension IMChatViewController: UIImagePickerControllerDelegate & UINavigationControllerDelegate {
  397. func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
  398. if let image = info[.editedImage] as? UIImage {
  399. let fileName = "\(UUID().uuidString).png"
  400. let newData = image.pngData()!
  401. let localFilePath = self.storageLocalImage(imageData: newData, fileName: fileName)
  402. let msgId = self.prepareForSendImageMsg(filePath: localFilePath)
  403. self.uploadImageAndSendMsg(messageId: msgId, imageData: newData, fileName: fileName)
  404. } else {
  405. DDLogError("没有选择到图片!")
  406. }
  407. picker.dismiss(animated: true, completion: nil)
  408. // var newData = data
  409. // //处理图片旋转的问题
  410. // if imageOrientation != UIImage.Orientation.up {
  411. // let newImage = UIImage(data: data)?.fixOrientation()
  412. // if newImage != nil {
  413. // newData = newImage!.pngData()!
  414. // }
  415. // }
  416. // var fileName = ""
  417. // if dict?["PHImageFileURLKey"] != nil {
  418. // let fileURL = dict?["PHImageFileURLKey"] as! URL
  419. // fileName = fileURL.lastPathComponent
  420. // } else {
  421. // fileName = "\(UUID().uuidString).png"
  422. // }
  423. }
  424. }
  425. // MARK: - 图片消息点击 delegate
  426. extension IMChatViewController: IMChatMessageDelegate {
  427. func clickImageMessage(fileId: String?, tempPath: String?) {
  428. if let id = fileId {
  429. self.showLoading()
  430. O2IMFileManager.shared
  431. .getFileLocalUrl(fileId: id)
  432. .always {
  433. self.hideLoading()
  434. }.then { (path) in
  435. let currentURL = NSURL(fileURLWithPath: path.path)
  436. DDLogDebug(currentURL.description)
  437. DDLogDebug(path.path)
  438. if QLPreviewController.canPreview(currentURL) {
  439. self.previewVC.currentFileURLS.removeAll()
  440. self.previewVC.currentFileURLS.append(currentURL)
  441. self.previewVC.reloadData()
  442. self.pushVC(self.previewVC)
  443. } else {
  444. self.showError(title: "当前文件类型不支持预览!")
  445. }
  446. }
  447. .catch { (error) in
  448. DDLogError(error.localizedDescription)
  449. self.showError(title: "获取文件异常!")
  450. }
  451. }else if let temp = tempPath {
  452. let currentURL = NSURL(fileURLWithPath: temp)
  453. DDLogDebug(currentURL.description)
  454. DDLogDebug(temp)
  455. if QLPreviewController.canPreview(currentURL) {
  456. self.previewVC.currentFileURLS.removeAll()
  457. self.previewVC.currentFileURLS.append(currentURL)
  458. self.previewVC.reloadData()
  459. self.pushVC(self.previewVC)
  460. } else {
  461. self.showError(title: "当前文件类型不支持预览!")
  462. }
  463. }
  464. }
  465. }
  466. // MARK: - 表情点击 delegate
  467. extension IMChatViewController: IMChatEmojiBarClickDelegate {
  468. func clickEmoji(emoji: String) {
  469. DDLogDebug("发送表情消息 \(emoji)")
  470. self.sendEmojiMessage(emoji: emoji)
  471. }
  472. }
  473. // MARK: - tableview delegate
  474. extension IMChatViewController: UITableViewDelegate, UITableViewDataSource {
  475. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  476. return self.chatMessageList.count
  477. }
  478. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  479. let msg = self.chatMessageList[indexPath.row]
  480. if msg.createPerson == O2AuthSDK.shared.myInfo()?.distinguishedName { //发送者
  481. if let cell = tableView.dequeueReusableCell(withIdentifier: "IMChatMessageSendViewCell", for: indexPath) as? IMChatMessageSendViewCell {
  482. cell.setContent(item: self.chatMessageList[indexPath.row])
  483. cell.delegate = self
  484. return cell
  485. }
  486. } else {
  487. if let cell = tableView.dequeueReusableCell(withIdentifier: "IMChatMessageViewCell", for: indexPath) as? IMChatMessageViewCell {
  488. cell.setContent(item: self.chatMessageList[indexPath.row])
  489. cell.delegate = self
  490. return cell
  491. }
  492. }
  493. return UITableViewCell()
  494. }
  495. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  496. tableView.deselectRow(at: indexPath, animated: false)
  497. }
  498. }
  499. // MARK: - textField delegate
  500. extension IMChatViewController: UITextFieldDelegate {
  501. func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
  502. DDLogDebug("准备开始输入......")
  503. closeOtherView()
  504. return true
  505. }
  506. private func closeOtherView() {
  507. self.isShowEmoji = false
  508. self.isShowAudioView = false
  509. self.bottomBarHeightConstraint.constant = self.bottomBarHeight.toCGFloat
  510. self.view.layoutIfNeeded()
  511. }
  512. func textFieldShouldReturn(_ textField: UITextField) -> Bool {
  513. DDLogDebug("回车。。。。")
  514. self.sendTextMessage()
  515. return true
  516. }
  517. }