瀏覽代碼

消息列表置顶完成

南鑫林 5 年之前
父節點
當前提交
9174f6897d

+ 10 - 2
RainbowPlanet/RainbowPlanet/Modules/MessageModule/MessageMain/View/MessageHomeThreeSectionTableViewCell.swift

@@ -35,8 +35,16 @@ class MessageHomeThreeSectionTableViewCell: RCConversationCell {
     
     var conversationModel : ConversationModel? {
         didSet {
-           let rcConversation = RCIMClient.shared()?.getConversation(RCConversationType.ConversationType_PRIVATE, targetId: conversationModel?.targetId)
-           let rcConversationModel = RCConversationModel.init(conversation: rcConversation, extend: "")
+           rcConversation = RCIMClient.shared()?.getConversation(RCConversationType.ConversationType_PRIVATE, targetId: conversationModel?.targetId)
+        }
+    }
+    var rcConversation : RCConversation? {
+        didSet{
+            rcConversationModel = RCConversationModel.init(conversation: rcConversation, extend: "")
+        }
+    }
+    var rcConversationModel : RCConversationModel? {
+        didSet {
             setDataModel(rcConversationModel)
         }
     }

+ 40 - 3
RainbowPlanet/RainbowPlanet/Modules/MessageModule/MessageMain/ViewController/MessageMainViewController.swift

@@ -33,6 +33,7 @@ class MessageMainViewController: BaseViewController {
     var messageIndexModel : MessageIndexModel?
     var users : Array<Any>?
     var conversationModels : Array<ConversationModel>?
+    var rcConversations : Array<RCConversation>?
     
     
     override func viewDidLoad() {
@@ -123,6 +124,7 @@ extension MessageMainViewController {
         self.conversationModels = Mapper<ConversationModel>().mapArray(JSONString: self.users?.description ?? "[]")
         self.tableView.reloadData()
         BaseTabbarViewController.shared.setBadge()
+        NXLLog(self.users)
     }
     
 }
@@ -140,8 +142,6 @@ extension MessageMainViewController {
         vc.messageShowTypes = messageShowTypes
         self.navigationController?.pushViewController(vc, animated: true)
         BaseTabbarViewController.shared.setBadge()
-
-
     }
 }
 
@@ -247,13 +247,50 @@ extension MessageMainViewController: UITableViewDelegate,UITableViewDataSource {
         switch indexPath.section {
         case 0:
             return 107
-        case 1,2:
+        case 1,2,3:
             return 70
         default:
             return 0
         }
     }
     
+    @available(iOS 11.0, *)
+    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
+        switch indexPath.section {
+        case 2:
+            let cell = tableView.cellForRow(at: indexPath) as? MessageHomeThreeSectionTableViewCell
+            let deleteRowAction = UIContextualAction(style: UIContextualAction.Style.destructive, title: "删除") {  [weak self] (contextualAction, view, completionHandler) in
+                guard let strongSelf = self else { return }
+                RCIMClient.shared()?.remove(RCConversationType.ConversationType_PRIVATE, targetId: cell?.rcConversation?.targetId)
+                strongSelf.conversationModels?.remove(at: indexPath.row)
+                tableView.deleteRows(at: [indexPath], with: UITableView.RowAnimation.left)
+            }
+            deleteRowAction.backgroundColor = .red
+            
+            var topRowtitle : String?
+            if cell?.rcConversationModel?.isTop ?? false {
+                topRowtitle = "取消置顶"
+            } else {
+                topRowtitle = "置顶"
+
+            }
+            let topRowAction = UIContextualAction(style: UIContextualAction.Style.destructive, title: topRowtitle) { [weak self] (contextualAction, view, completionHandler) in
+                if cell?.rcConversationModel?.isTop ?? false {
+                    RCIMClient.shared()?.setConversationToTop(RCConversationType.ConversationType_PRIVATE, targetId: cell?.rcConversation?.targetId, isTop: false)
+                } else {
+                    RCIMClient.shared()?.setConversationToTop(RCConversationType.ConversationType_PRIVATE, targetId: cell?.rcConversation?.targetId, isTop: true)
+                }
+                self?.setConversationList()
+            }
+            topRowAction.backgroundColor = kThemeColor
+            let config = UISwipeActionsConfiguration(actions: [deleteRowAction,topRowAction])
+            return config
+        default:
+            return nil
+        }
+       
+    }
+    
     func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
         return 10
     }

+ 6 - 0
RainbowPlanet/RainbowPlanet/Modules/RongCloudIMModule/IMChatPrivateSet/View/IMChatPrivateSetTwoTableViewCell.swift

@@ -7,6 +7,7 @@
 //
 
 import UIKit
+import RongIMLib
 
 class IMChatPrivateSetTwoTableViewCell: UITableViewCell {
 
@@ -57,5 +58,10 @@ class IMChatPrivateSetTwoTableViewCell: UITableViewCell {
             titleLabel.text = title
         }
     }
+    
+    /// 会话目标
+    var targetId : String?
+    /// 会话类型
+    var type : RCConversationType?
 
 }

+ 4 - 0
RainbowPlanet/RainbowPlanet/Modules/RongCloudIMModule/IMChatPrivateSet/ViewController/IMChatPrivateSetViewController.swift

@@ -66,10 +66,14 @@ extension IMChatPrivateSetViewController: UITableViewDelegate,UITableViewDataSou
         case 0:
             let cell = IMChatPrivateSetOneTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
             cell.title =  sections[indexPath.section][indexPath.row]
+            cell.targetId = targetId
+            cell.type = type
             return cell
         case 1:
             let cell = IMChatPrivateSetTwoTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
             cell.title =  sections[indexPath.section][indexPath.row]
+            cell.targetId = targetId
+            cell.type = type
             return cell
         default:
             return UITableViewCell()