                     collectionView.contentOffset = offset
                 }
 
-                completion?()
-
                 CATransaction.commit()
+
+                DispatchQueue.main.async {
+                    completion?()
+                }
             })
         }
     }


        MessageManager.getHistory(subscription, lastMessageDate: nil) { [weak self] in
            guard let messages = self?.subscription.fetchMessages() else { return }
//
            self?.appendMessages(messages: Array(messages), updateScrollPosition: false, completion: {
                self?.activityIndicator.stopAnimating()
                self?.scrollToBottom()

        super.viewWillAppear(animated)

        view?.layoutSubviews()
        collectionView?.layoutSubviews()
        scrollToBottom()
    }

