|
@@ -39,24 +39,40 @@ class IMConversationListViewController: UIViewController {
|
|
|
}()
|
|
}()
|
|
|
|
|
|
|
|
private var conversationList: [IMConversationInfo] = []
|
|
private var conversationList: [IMConversationInfo] = []
|
|
|
|
|
+ private var instantMsgList: [InstantMessage] = []
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
super.viewDidLoad()
|
|
|
view.addSubview(tableview)
|
|
view.addSubview(tableview)
|
|
|
view.addSubview(emptyView)
|
|
view.addSubview(emptyView)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(receiveMessageFromWs(notice:)), name: OONotification.websocket.notificationName, object: nil)
|
|
NotificationCenter.default.addObserver(self, selector: #selector(receiveMessageFromWs(notice:)), name: OONotification.websocket.notificationName, object: nil)
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
- getConversationList()
|
|
|
|
|
|
|
+ getInstantMsgList()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ func getInstantMsgList() {
|
|
|
|
|
+ viewModel.getInstantMsgList().then { (list) in
|
|
|
|
|
+ self.instantMsgList = list
|
|
|
|
|
+ self.getConversationList()
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func getConversationList() {
|
|
func getConversationList() {
|
|
|
viewModel.myConversationList().then { (list) in
|
|
viewModel.myConversationList().then { (list) in
|
|
|
self.conversationList = list
|
|
self.conversationList = list
|
|
|
|
|
+ var n = 0
|
|
|
|
|
+ if !self.conversationList.isEmpty {
|
|
|
|
|
+ for item in self.conversationList {
|
|
|
|
|
+ if let number = item.unreadNumber {
|
|
|
|
|
+ n += number
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
DispatchQueue.main.async {
|
|
DispatchQueue.main.async {
|
|
|
if self.conversationList.count > 0 {
|
|
if self.conversationList.count > 0 {
|
|
|
self.emptyView.isHidden = true
|
|
self.emptyView.isHidden = true
|
|
@@ -64,6 +80,7 @@ class IMConversationListViewController: UIViewController {
|
|
|
self.emptyView.isHidden = false
|
|
self.emptyView.isHidden = false
|
|
|
}
|
|
}
|
|
|
self.tableview.reloadData()
|
|
self.tableview.reloadData()
|
|
|
|
|
+ self.refreshRedPoint(number: n)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}.catch { (err) in
|
|
}.catch { (err) in
|
|
@@ -79,7 +96,7 @@ class IMConversationListViewController: UIViewController {
|
|
|
return info.id == message.conversationId
|
|
return info.id == message.conversationId
|
|
|
}) {
|
|
}) {
|
|
|
DDLogDebug("有对应的会话 刷新列表")
|
|
DDLogDebug("有对应的会话 刷新列表")
|
|
|
- var newList: [IMConversationInfo] = []
|
|
|
|
|
|
|
+ var newList: [IMConversationInfo] = []
|
|
|
self.conversationList.forEach { (info) in
|
|
self.conversationList.forEach { (info) in
|
|
|
if message.conversationId != nil && info.id == message.conversationId {
|
|
if message.conversationId != nil && info.id == message.conversationId {
|
|
|
info.lastMessage = message
|
|
info.lastMessage = message
|
|
@@ -91,22 +108,35 @@ class IMConversationListViewController: UIViewController {
|
|
|
DispatchQueue.main.async {
|
|
DispatchQueue.main.async {
|
|
|
self.tableview.reloadData()
|
|
self.tableview.reloadData()
|
|
|
}
|
|
}
|
|
|
- }else {
|
|
|
|
|
|
|
+ } else {
|
|
|
DDLogDebug("没有对应的会话 重新获取会话列表")
|
|
DDLogDebug("没有对应的会话 重新获取会话列表")
|
|
|
- self.getConversationList()
|
|
|
|
|
|
|
+ self.getInstantMsgList()
|
|
|
}
|
|
}
|
|
|
- }else {
|
|
|
|
|
|
|
+ } else {
|
|
|
DDLogError("不正确的消息类型。。。")
|
|
DDLogError("不正确的消息类型。。。")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private func refreshRedPoint(number: Int) {
|
|
|
|
|
+ if number > 0 && number < 100 {
|
|
|
|
|
+ self.navigationController?.tabBarItem.badgeValue = "\(number)"
|
|
|
|
|
+ } else if number >= 100 {
|
|
|
|
|
+ self.navigationController?.tabBarItem.badgeValue = "99.."
|
|
|
|
|
+ }else {
|
|
|
|
|
+ self.navigationController?.tabBarItem.badgeValue = nil
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// MARK: - tableview delegate
|
|
// MARK: - tableview delegate
|
|
|
extension IMConversationListViewController: UITableViewDelegate, UITableViewDataSource {
|
|
extension IMConversationListViewController: UITableViewDelegate, UITableViewDataSource {
|
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
|
|
+ if self.instantMsgList.count > 0 {
|
|
|
|
|
+ return self.conversationList.count + 1
|
|
|
|
|
+ }
|
|
|
return self.conversationList.count
|
|
return self.conversationList.count
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -117,17 +147,38 @@ extension IMConversationListViewController: UITableViewDelegate, UITableViewData
|
|
|
guard let c = cell as? IMConversationItemCell else {
|
|
guard let c = cell as? IMConversationItemCell else {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- c.bindConversation(conversation: self.conversationList[indexPath.row])
|
|
|
|
|
|
|
+ if self.instantMsgList.count > 0 {
|
|
|
|
|
+ if indexPath.row == 0 {
|
|
|
|
|
+ c.setInstantContent(item: self.instantMsgList.last!)
|
|
|
|
|
+ }else {
|
|
|
|
|
+ c.bindConversation(conversation: self.conversationList[indexPath.row - 1])
|
|
|
|
|
+ }
|
|
|
|
|
+ }else {
|
|
|
|
|
+ c.bindConversation(conversation: self.conversationList[indexPath.row])
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
|
return 64
|
|
return 64
|
|
|
}
|
|
}
|
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
DDLogDebug("点击了 row \(indexPath.row)")
|
|
DDLogDebug("点击了 row \(indexPath.row)")
|
|
|
|
|
+ if self.instantMsgList.count > 0 {
|
|
|
|
|
+ if indexPath.row == 0 {
|
|
|
|
|
+ let instantView = IMInstantMessageViewController()
|
|
|
|
|
+ instantView.instantMsgList = self.instantMsgList
|
|
|
|
|
+ self.navigationController?.pushViewController(instantView, animated: true)
|
|
|
|
|
+ }else {
|
|
|
|
|
+ gotoChatView(row: indexPath.row-1)
|
|
|
|
|
+ }
|
|
|
|
|
+ }else {
|
|
|
|
|
+ gotoChatView(row: indexPath.row)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private func gotoChatView(row: Int) {
|
|
|
let chatView = IMChatViewController()
|
|
let chatView = IMChatViewController()
|
|
|
- chatView.conversation = self.conversationList[indexPath.row]
|
|
|
|
|
|
|
+ chatView.conversation = self.conversationList[row]
|
|
|
self.navigationController?.pushViewController(chatView, animated: true)
|
|
self.navigationController?.pushViewController(chatView, animated: true)
|
|
|
}
|
|
}
|
|
|
- //todo can edit
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|