mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 11:08:06 +00:00
Refactor resetDisplayedChatRoom function for better performance and to avoid crashes
This commit is contained in:
parent
e3dd3f5a86
commit
34ff5bcf16
1 changed files with 10 additions and 5 deletions
|
|
@ -1740,18 +1740,23 @@ class ConversationViewModel: ObservableObject {
|
|||
}
|
||||
|
||||
func resetDisplayedChatRoom(conversationsList: [ConversationModel]) {
|
||||
guard !conversationsList.isEmpty else {
|
||||
Log.info("\(ConversationViewModel.TAG) The conversation list is empty.")
|
||||
return
|
||||
}
|
||||
|
||||
if !self.conversationMessagesSection.isEmpty && !self.conversationMessagesSection[0].rows.isEmpty {
|
||||
if self.displayedConversation != nil {
|
||||
if let displayedConversation = self.displayedConversation {
|
||||
conversationsList.forEach { conversation in
|
||||
if conversation.id == self.displayedConversation!.id {
|
||||
if conversation.id == displayedConversation.id {
|
||||
self.displayedConversation = conversation
|
||||
self.computeComposingLabel()
|
||||
|
||||
if self.displayedConversation != nil {
|
||||
if let updatedDisplayedConversation = self.displayedConversation {
|
||||
CoreContext.shared.doOnCoreQueue { _ in
|
||||
let historyEventsSizeTmp = self.displayedConversation!.chatRoom.historyEventsSize
|
||||
let historyEventsSizeTmp = updatedDisplayedConversation.chatRoom.historyEventsSize
|
||||
if self.displayedConversationHistorySize < historyEventsSizeTmp {
|
||||
let eventLogList = self.displayedConversation!.chatRoom.getHistoryRangeEvents(begin: 0, end: historyEventsSizeTmp - self.displayedConversationHistorySize)
|
||||
let eventLogList = updatedDisplayedConversation.chatRoom.getHistoryRangeEvents(begin: 0, end: historyEventsSizeTmp - self.displayedConversationHistorySize)
|
||||
|
||||
if !eventLogList.isEmpty {
|
||||
self.getNewMessages(eventLogs: eventLogList)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue