Avoid using multiple threads in the conversation model

This commit is contained in:
Benoit Martins 2025-01-30 16:41:10 +01:00
parent a9854bc378
commit a3c20e3ae7

View file

@ -205,7 +205,6 @@ class ConversationModel: ObservableObject, Identifiable {
} }
func getContentTextMessage() { func getContentTextMessage() {
coreContext.doOnCoreQueue { _ in
let lastMessage = self.chatRoom.lastMessageInHistory let lastMessage = self.chatRoom.lastMessageInHistory
if lastMessage != nil { if lastMessage != nil {
var fromAddressFriend = lastMessage!.fromAddress != nil var fromAddressFriend = lastMessage!.fromAddress != nil
@ -236,19 +235,17 @@ class ConversationModel: ObservableObject, Identifiable {
let lastMessageStateTmp = lastMessage?.state.rawValue ?? 0 let lastMessageStateTmp = lastMessage?.state.rawValue ?? 0
DispatchQueue.main.async { // DispatchQueue.main.async {
self.lastMessageText = lastMessageTextTmp self.lastMessageText = lastMessageTextTmp
self.lastMessageIsOutgoing = lastMessageIsOutgoingTmp self.lastMessageIsOutgoing = lastMessageIsOutgoingTmp
self.lastMessageState = lastMessageStateTmp self.lastMessageState = lastMessageStateTmp
} // }
}
} }
} }
func getChatRoomSubject() { func getChatRoomSubject() {
coreContext.doOnCoreQueue { _ in
let addressFriend = (self.chatRoom.participants.first != nil && self.chatRoom.participants.first!.address != nil) let addressFriend = (self.chatRoom.participants.first != nil && self.chatRoom.participants.first!.address != nil)
? self.contactsManager.getFriendWithAddress(address: self.chatRoom.participants.first?.address) ? self.contactsManager.getFriendWithAddress(address: self.chatRoom.participants.first?.address)
: nil : nil
@ -296,21 +293,18 @@ class ConversationModel: ObservableObject, Identifiable {
participantsAddressTmp.append(participant.address?.asStringUriOnly() ?? "") participantsAddressTmp.append(participant.address?.asStringUriOnly() ?? "")
} }
DispatchQueue.main.async { // DispatchQueue.main.async {
self.subject = subjectTmp self.subject = subjectTmp
self.avatarModel = avatarModelTmp self.avatarModel = avatarModelTmp
self.participantsAddress = participantsAddressTmp self.participantsAddress = participantsAddressTmp
} // }
}
} }
func getUnreadMessagesCount() { func getUnreadMessagesCount() {
coreContext.doOnCoreQueue { _ in
let unreadMessagesCountTmp = self.chatRoom.unreadMessagesCount let unreadMessagesCountTmp = self.chatRoom.unreadMessagesCount
DispatchQueue.main.async { // DispatchQueue.main.async {
self.unreadMessagesCount = unreadMessagesCountTmp self.unreadMessagesCount = unreadMessagesCountTmp
} // }
}
} }
func refreshAvatarModel() { func refreshAvatarModel() {