mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 02:58:07 +00:00
Update the unread message counter in onMessageRetracted
This commit is contained in:
parent
773102e4bd
commit
5492a3e3a9
2 changed files with 70 additions and 61 deletions
|
|
@ -183,69 +183,76 @@ class ConversationsListViewModel: ObservableObject {
|
|||
|
||||
func addConversationDelegate() {
|
||||
coreContext.doOnCoreQueue { core in
|
||||
self.coreConversationDelegate = CoreDelegateStub(onMessagesReceived: { (core: Core, chatRoom: ChatRoom, _: [ChatMessage]) in
|
||||
if let defaultAddress = core.defaultAccount?.contactAddress,
|
||||
let localAddress = chatRoom.localAddress,
|
||||
defaultAddress.weakEqual(address2: localAddress) {
|
||||
let idTmp = LinphoneUtils.getChatRoomId(room: chatRoom)
|
||||
let model = self.conversationsList.first(where: { $0.id == idTmp }) ?? ConversationModel(chatRoom: chatRoom)
|
||||
model.getContentTextMessage(chatRoom: chatRoom)
|
||||
let index = self.conversationsList.firstIndex(where: { $0.id == idTmp })
|
||||
DispatchQueue.main.async {
|
||||
if index != nil {
|
||||
self.conversationsList.remove(at: index!)
|
||||
}
|
||||
self.conversationsList.insert(model, at: 0)
|
||||
}
|
||||
SharedMainViewModel.shared.updateUnreadMessagesCount()
|
||||
}
|
||||
}, onMessageSent: { (_: Core, chatRoom: ChatRoom, _: ChatMessage) in
|
||||
if let defaultAddress = core.defaultAccount?.contactAddress,
|
||||
let localAddress = chatRoom.localAddress,
|
||||
defaultAddress.weakEqual(address2: localAddress) {
|
||||
let idTmp = LinphoneUtils.getChatRoomId(room: chatRoom)
|
||||
let model = self.conversationsList.first(where: { $0.id == idTmp }) ?? ConversationModel(chatRoom: chatRoom)
|
||||
model.getContentTextMessage(chatRoom: chatRoom)
|
||||
let index = self.conversationsList.firstIndex(where: { $0.id == idTmp })
|
||||
if index != nil {
|
||||
self.conversationsList[index!].chatMessageRemoveDelegate()
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
if index != nil {
|
||||
self.conversationsList.remove(at: index!)
|
||||
}
|
||||
self.conversationsList.insert(model, at: 0)
|
||||
}
|
||||
SharedMainViewModel.shared.updateUnreadMessagesCount()
|
||||
}
|
||||
}, onChatRoomRead: { (_: Core, chatRoom: ChatRoom) in
|
||||
let idTmp = LinphoneUtils.getChatRoomId(room: chatRoom)
|
||||
let model = self.conversationsList.first(where: { $0.id == idTmp }) ?? ConversationModel(chatRoom: chatRoom)
|
||||
model.getContentTextMessage(chatRoom: chatRoom)
|
||||
if let index = self.conversationsList.firstIndex(where: { $0.id == idTmp }) {
|
||||
DispatchQueue.main.async {
|
||||
self.conversationsList.remove(at: index)
|
||||
self.conversationsList.insert(model, at: index)
|
||||
self.coreConversationDelegate = CoreDelegateStub(
|
||||
onMessagesReceived: { (core: Core, chatRoom: ChatRoom, _: [ChatMessage]) in
|
||||
if let defaultAddress = core.defaultAccount?.contactAddress,
|
||||
let localAddress = chatRoom.localAddress,
|
||||
defaultAddress.weakEqual(address2: localAddress) {
|
||||
let idTmp = LinphoneUtils.getChatRoomId(room: chatRoom)
|
||||
let model = self.conversationsList.first(where: { $0.id == idTmp }) ?? ConversationModel(chatRoom: chatRoom)
|
||||
model.getContentTextMessage(chatRoom: chatRoom)
|
||||
let index = self.conversationsList.firstIndex(where: { $0.id == idTmp })
|
||||
DispatchQueue.main.async {
|
||||
if index != nil {
|
||||
self.conversationsList.remove(at: index!)
|
||||
}
|
||||
self.conversationsList.insert(model, at: 0)
|
||||
}
|
||||
SharedMainViewModel.shared.updateUnreadMessagesCount()
|
||||
}
|
||||
}, onMessageSent: { (_: Core, chatRoom: ChatRoom, _: ChatMessage) in
|
||||
if let defaultAddress = core.defaultAccount?.contactAddress,
|
||||
let localAddress = chatRoom.localAddress,
|
||||
defaultAddress.weakEqual(address2: localAddress) {
|
||||
let idTmp = LinphoneUtils.getChatRoomId(room: chatRoom)
|
||||
let model = self.conversationsList.first(where: { $0.id == idTmp }) ?? ConversationModel(chatRoom: chatRoom)
|
||||
model.getContentTextMessage(chatRoom: chatRoom)
|
||||
let index = self.conversationsList.firstIndex(where: { $0.id == idTmp })
|
||||
if index != nil {
|
||||
self.conversationsList[index!].chatMessageRemoveDelegate()
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
if index != nil {
|
||||
self.conversationsList.remove(at: index!)
|
||||
}
|
||||
self.conversationsList.insert(model, at: 0)
|
||||
}
|
||||
SharedMainViewModel.shared.updateUnreadMessagesCount()
|
||||
}
|
||||
}, onChatRoomRead: { (_: Core, chatRoom: ChatRoom) in
|
||||
let idTmp = LinphoneUtils.getChatRoomId(room: chatRoom)
|
||||
let model = self.conversationsList.first(where: { $0.id == idTmp }) ?? ConversationModel(chatRoom: chatRoom)
|
||||
model.getContentTextMessage(chatRoom: chatRoom)
|
||||
if let index = self.conversationsList.firstIndex(where: { $0.id == idTmp }) {
|
||||
DispatchQueue.main.async {
|
||||
self.conversationsList.remove(at: index)
|
||||
self.conversationsList.insert(model, at: index)
|
||||
}
|
||||
}
|
||||
SharedMainViewModel.shared.updateUnreadMessagesCount()
|
||||
}, onChatRoomStateChanged: { (core: Core, chatroom: ChatRoom, state: ChatRoom.State) in
|
||||
// Log.info("[ConversationsListViewModel] Conversation [${LinphoneUtils.getChatRoomId(chatRoom)}] state changed [$state]")
|
||||
if let defaultAddress = core.defaultAccount?.contactAddress,
|
||||
let localAddress = chatroom.localAddress,
|
||||
defaultAddress.weakEqual(address2: localAddress) {
|
||||
if core.globalState == .On {
|
||||
switch state {
|
||||
case .Created:
|
||||
self.addChatRoom(chatRoom: chatroom)
|
||||
case .Deleted:
|
||||
self.removeChatRoom(chatRoom: chatroom)
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}, onMessageRetracted: { (core: Core, chatRoom: ChatRoom, message: ChatMessage) in
|
||||
let idTmp = LinphoneUtils.getChatRoomId(room: chatRoom)
|
||||
let model = self.conversationsList.first(where: { $0.id == idTmp }) ?? ConversationModel(chatRoom: chatRoom)
|
||||
model.getContentTextMessage(chatRoom: chatRoom)
|
||||
SharedMainViewModel.shared.updateUnreadMessagesCount()
|
||||
}
|
||||
SharedMainViewModel.shared.updateUnreadMessagesCount()
|
||||
}, onChatRoomStateChanged: { (core: Core, chatroom: ChatRoom, state: ChatRoom.State) in
|
||||
// Log.info("[ConversationsListViewModel] Conversation [${LinphoneUtils.getChatRoomId(chatRoom)}] state changed [$state]")
|
||||
if let defaultAddress = core.defaultAccount?.contactAddress,
|
||||
let localAddress = chatroom.localAddress,
|
||||
defaultAddress.weakEqual(address2: localAddress) {
|
||||
if core.globalState == .On {
|
||||
switch state {
|
||||
case .Created:
|
||||
self.addChatRoom(chatRoom: chatroom)
|
||||
case .Deleted:
|
||||
self.removeChatRoom(chatRoom: chatroom)
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
core.addDelegate(delegate: self.coreConversationDelegate!)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ class AccountModel: ObservableObject {
|
|||
self.computeNotificationsCount()
|
||||
}, onChatRoomRead: { (_: Core, _: ChatRoom) in
|
||||
self.computeNotificationsCount()
|
||||
}, onMessageRetracted: { (_: Core, _: ChatRoom, _: ChatMessage) in
|
||||
self.computeNotificationsCount()
|
||||
})
|
||||
core.addDelegate(delegate: coreDelegate!)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue