forked from mirrors/linphone-iphone
Optimize computeChatRoomsList execution frequency
This commit is contained in:
parent
20da49167c
commit
a9854bc378
2 changed files with 30 additions and 12 deletions
|
|
@ -208,7 +208,6 @@ struct UIList: UIViewRepresentable {
|
|||
|
||||
if isScrolledToBottom && conversationViewModel.displayedConversationUnreadMessagesCount > 0 {
|
||||
conversationViewModel.markAsRead()
|
||||
conversationsListViewModel.computeChatRoomsList(filter: "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -467,7 +466,6 @@ struct UIList: UIViewRepresentable {
|
|||
|
||||
if self.parent.isScrolledToBottom && self.parent.conversationViewModel.displayedConversationUnreadMessagesCount > 0 {
|
||||
self.parent.conversationViewModel.markAsRead()
|
||||
self.parent.conversationsListViewModel.computeChatRoomsList(filter: "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,16 +65,36 @@ class ConversationsListViewModel: ObservableObject {
|
|||
|
||||
func addConversationDelegate() {
|
||||
coreContext.doOnCoreQueue { core in
|
||||
let account = core.defaultAccount
|
||||
let chatRoomsCounter = account?.chatRooms != nil ? account!.chatRooms.count : core.chatRooms.count
|
||||
|
||||
self.coreConversationDelegate = CoreDelegateStub(onMessagesReceived: { (_: Core, _: ChatRoom, _: [ChatMessage]) in
|
||||
self.computeChatRoomsList(filter: "")
|
||||
}, onMessageSent: { (_: Core, _: ChatRoom, _: ChatMessage) in
|
||||
self.computeChatRoomsList(filter: "")
|
||||
}, onChatRoomRead: { (_: Core, _: ChatRoom) in
|
||||
self.computeChatRoomsList(filter: "")
|
||||
}, onChatRoomStateChanged: { (core: Core, chatRoom: ChatRoom, state: ChatRoom.State) in
|
||||
self.coreConversationDelegate = CoreDelegateStub(onMessagesReceived: { (_: Core, chatRoom: ChatRoom, _: [ChatMessage]) in
|
||||
let model = ConversationModel(chatRoom: chatRoom)
|
||||
DispatchQueue.main.async {
|
||||
if let index = self.conversationsList.firstIndex(where: { $0.chatRoom === chatRoom }) {
|
||||
self.conversationsList.remove(at: index)
|
||||
}
|
||||
self.conversationsList.insert(model, at: 0)
|
||||
}
|
||||
self.updateUnreadMessagesCount()
|
||||
}, onMessageSent: { (_: Core, chatRoom: ChatRoom, _: ChatMessage) in
|
||||
let model = ConversationModel(chatRoom: chatRoom)
|
||||
DispatchQueue.main.async {
|
||||
if let index = self.conversationsList.firstIndex(where: { $0.chatRoom === chatRoom }) {
|
||||
self.conversationsList.remove(at: index)
|
||||
}
|
||||
self.conversationsList.insert(model, at: 0)
|
||||
}
|
||||
self.updateUnreadMessagesCount()
|
||||
}, onChatRoomRead: { (_: Core, chatRoom: ChatRoom) in
|
||||
let model = ConversationModel(chatRoom: chatRoom)
|
||||
DispatchQueue.main.async {
|
||||
if let index = self.conversationsList.firstIndex(where: { $0.chatRoom === chatRoom }) {
|
||||
self.conversationsList.remove(at: index)
|
||||
self.conversationsList.insert(model, at: index)
|
||||
} else {
|
||||
self.conversationsList.insert(model, at: 0)
|
||||
}
|
||||
}
|
||||
self.updateUnreadMessagesCount()
|
||||
}, onChatRoomStateChanged: { (core: Core, _: ChatRoom, state: ChatRoom.State) in
|
||||
// Log.info("[ConversationsListViewModel] Conversation [${LinphoneUtils.getChatRoomId(chatRoom)}] state changed [$state]")
|
||||
if core.globalState == .On {
|
||||
switch state {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue