Эх сурвалжийг харах

feat: 增加个人页发送动态成功后自动刷新的逻辑

陈文艺 1 сар өмнө
parent
commit
4d8299f1f4

+ 11 - 1
Lanu/Manager/Feed/LNFeedManager.swift

@@ -11,10 +11,12 @@ import Foundation
 protocol LNFeedManagerNotify {
     func onFeedCommentCountChanged(id: String, count: Int)
     func onFeedDelete(id: String)
+    func onPostFeedSuccess()
 }
 extension LNFeedManagerNotify {
     func onFeedDelete(id: String) { }
     func onFeedCommentCountChanged(id: String, count: Int) { }
+    func onPostFeedSuccess() { }
 }
 
 
@@ -47,10 +49,14 @@ class LNFeedManager {
     }
     
     func postFeed(item: LNPostFeedItem, queue: DispatchQueue = .main, handler: @escaping (Bool) -> Void) {
-        LNHttpManager.shared.postFeed(item: item) { err in
+        LNHttpManager.shared.postFeed(item: item) { [weak self] err in
             queue.asyncIfNotGlobal {
                 handler(err == nil)
             }
+            
+            if let self, err == nil {
+                notifyPostFeedSuccess()
+            }
         }
     }
     
@@ -83,4 +89,8 @@ extension LNFeedManager {
     func notifyFeedCommentChanged(id: String, count: Int) {
         LNEventDeliver.notifyEvent { ($0 as? LNFeedManagerNotify)?.onFeedCommentCountChanged(id: id, count: count) }
     }
+    
+    func notifyPostFeedSuccess() {
+        LNEventDeliver.notifyEvent { ($0 as? LNFeedManagerNotify)?.onPostFeedSuccess() }
+    }
 }

+ 2 - 6
Lanu/Views/Profile/Feed/LNProfileFeedItemCell.swift

@@ -128,8 +128,6 @@ class LNProfileFeedItemCell: UITableViewCell {
                     itemViews.append(imageView)
                 }
                 photosView.update(itemViews)
-                
-                singlePhotoView.isHidden = true
             }
         }
         
@@ -164,11 +162,9 @@ extension LNProfileFeedItemCell {
     private func toComment() {
         guard let curItem else { return }
         let panel = LNFeedCommentInputPanel()
-        panel.handler = { [weak self] comment in
-            guard let self else { return }
+        panel.handler = { comment in
             LNFeedManager.shared.sendFeedComment(id: curItem.feedItem.id, content: comment)
-            { [weak self] success in
-                guard let self else { return }
+            { success in
                 guard success else { return }
                 curItem.feedItem.commentCount += 1
                 LNFeedManager.shared.notifyFeedCommentChanged(id: curItem.feedItem.id, count: curItem.feedItem.commentCount)

+ 26 - 0
Lanu/Views/Profile/Feed/LNProfileFeedProvider.swift

@@ -32,6 +32,12 @@ class LNProfileFeedProvider: NSObject, LNProfileBaseProvider {
         feedList.count
     }
     
+    override init() {
+        super.init()
+        
+        LNEventDeliver.addObserver(self)
+    }
+    
     func registerCell(tableView: UITableView) {
         tableView.register(LNProfileFeedItemCell.self, forCellReuseIdentifier: LNProfileFeedItemCell.className)
         self.tableView = tableView
@@ -68,6 +74,26 @@ class LNProfileFeedProvider: NSObject, LNProfileBaseProvider {
     }
 }
 
+extension LNProfileFeedProvider: LNFeedManagerNotify {
+    func onPostFeedSuccess() {
+        guard let curDetail else { return }
+        LNFeedManager.shared.getFeedList(uid: curDetail.userNo, next: nil) { [weak self] res in
+            guard let self else { return }
+            guard let res else { return }
+            
+            let curFirst = feedList.first?.feedItem.id ?? ""
+            guard let index = res.list.firstIndex(where: { $0.id == curFirst }) else {
+                return
+            }
+            let newItems = res.list[..<index].map {
+                LNFeedItem(feedItem: $0)
+            }
+            feedList.insert(contentsOf: newItems, at: 0)
+            tableView?.reloadData()
+        }
+    }
+}
+
 extension LNProfileFeedProvider: UITableViewDelegate {
     func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
         guard let view = cell as? LNProfileFeedItemCell, view.isVideo else {

+ 1 - 1
Lanu/Views/Profile/Profile/LNProfileUserDetailView.swift

@@ -136,7 +136,7 @@ extension LNProfileUserDetailView {
         tableView.publisher(for: \.contentSize).removeDuplicates().sink
         { [weak self] newValue in
             guard let self else { return }
-            contentHeight = newValue.height
+            contentHeight = newValue.height + tableView.contentInset.top + tableView.contentInset.bottom
         }.store(in: &bag)
         addSubview(tableView)
         tableView.snp.makeConstraints { make in