Fix message display missing when going from a conversation with few messages (not enough to fill screen) to conversation with many messages

This commit is contained in:
Christophe Deschamps 2024-02-16 08:03:52 +01:00
parent 965ee5a476
commit f85e0b5118

View file

@ -113,7 +113,7 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour
override func viewWillDisappear(_ animated: Bool) { override func viewWillDisappear(_ animated: Bool) {
if ChatConversationTableViewModel.sharedModel.getNBMessages() > 0 { if ChatConversationTableViewModel.sharedModel.getNBMessages() > 0 {
scrollToBottom(animated: false) scrollToBottom(animated: false, async:false)
} }
NotificationCenter.default.removeObserver(self, name: Notification.Name("LinphoneFriendPresenceUpdate"), object: nil) NotificationCenter.default.removeObserver(self, name: Notification.Name("LinphoneFriendPresenceUpdate"), object: nil)
NotificationCenter.default.removeObserver(self) NotificationCenter.default.removeObserver(self)
@ -130,8 +130,12 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour
self.collectionView.scrollToItem(at: IndexPath(row: messageIndex, section: 0), at: .bottom, animated: false) self.collectionView.scrollToItem(at: IndexPath(row: messageIndex, section: 0), at: .bottom, animated: false)
} }
func scrollToBottom(animated: Bool){ func scrollToBottom(animated: Bool, async: Bool = true){
DispatchQueue.main.async{ if (async) {
DispatchQueue.main.async{
self.collectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .top, animated: animated)
}
} else {
self.collectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .top, animated: animated) self.collectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .top, animated: animated)
} }
ChatConversationViewSwift.markAsRead(ChatConversationViewModel.sharedModel.chatRoom?.getCobject) ChatConversationViewSwift.markAsRead(ChatConversationViewModel.sharedModel.chatRoom?.getCobject)