forked from mirrors/linphone-iphone
Replace publisher with delegate in ConversationForwardMessageViewModel
This commit is contained in:
parent
cb58b50e84
commit
035f74f59e
1 changed files with 26 additions and 18 deletions
|
|
@ -36,7 +36,7 @@ class ConversationForwardMessageViewModel: ObservableObject {
|
|||
|
||||
@Published var displayedConversation: ConversationModel?
|
||||
|
||||
private var chatRoomSuscriptions = Set<AnyCancellable?>()
|
||||
private var chatRoomDelegate: ChatRoomDelegate?
|
||||
|
||||
init() {}
|
||||
|
||||
|
|
@ -219,13 +219,31 @@ class ConversationForwardMessageViewModel: ObservableObject {
|
|||
}
|
||||
|
||||
func chatRoomAddDelegate(core: Core, chatRoom: ChatRoom) {
|
||||
self.chatRoomSuscriptions.insert(chatRoom.publisher?.onConferenceJoined?.postOnCoreQueue { (chatRoom: ChatRoom, _: EventLog) in
|
||||
self.chatRoomDelegate = ChatRoomDelegateStub(onStateChanged: { (chatRoom: ChatRoom, state: ChatRoom.State) in
|
||||
let state = chatRoom.state
|
||||
let id = LinphoneUtils.getChatRoomId(room: chatRoom)
|
||||
if state == ChatRoom.State.CreationFailed {
|
||||
Log.error("\(StartConversationViewModel.TAG) Conversation \(id) creation has failed!")
|
||||
if let chatRoomDelegate = self.chatRoomDelegate {
|
||||
chatRoom.removeDelegate(delegate: chatRoomDelegate)
|
||||
}
|
||||
self.chatRoomDelegate = nil
|
||||
DispatchQueue.main.async {
|
||||
self.operationInProgress = false
|
||||
ToastViewModel.shared.toastMessage = "Failed_to_create_conversation_error"
|
||||
ToastViewModel.shared.displayToast = true
|
||||
}
|
||||
}
|
||||
}, onConferenceJoined: { (chatRoom: ChatRoom, _: EventLog) in
|
||||
let state = chatRoom.state
|
||||
let id = LinphoneUtils.getChatRoomId(room: chatRoom)
|
||||
Log.info("\(StartConversationViewModel.TAG) Conversation \(id) \(chatRoom.subject ?? "") state changed: \(state)")
|
||||
if state == ChatRoom.State.Created {
|
||||
Log.info("\(StartConversationViewModel.TAG) Conversation \(id) successfully created")
|
||||
self.chatRoomSuscriptions.removeAll()
|
||||
if let chatRoomDelegate = self.chatRoomDelegate {
|
||||
chatRoom.removeDelegate(delegate: chatRoomDelegate)
|
||||
}
|
||||
self.chatRoomDelegate = nil
|
||||
|
||||
let model = ConversationModel(chatRoom: chatRoom)
|
||||
if self.operationInProgress == false {
|
||||
|
|
@ -245,21 +263,10 @@ class ConversationForwardMessageViewModel: ObservableObject {
|
|||
}
|
||||
} else if state == ChatRoom.State.CreationFailed {
|
||||
Log.error("\(StartConversationViewModel.TAG) Conversation \(id) creation has failed!")
|
||||
self.chatRoomSuscriptions.removeAll()
|
||||
DispatchQueue.main.async {
|
||||
self.operationInProgress = false
|
||||
ToastViewModel.shared.toastMessage = "Failed_to_create_conversation_error"
|
||||
ToastViewModel.shared.displayToast = true
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
self.chatRoomSuscriptions.insert(chatRoom.publisher?.onStateChanged?.postOnCoreQueue { (chatRoom: ChatRoom, state: ChatRoom.State) in
|
||||
let state = chatRoom.state
|
||||
let id = LinphoneUtils.getChatRoomId(room: chatRoom)
|
||||
if state == ChatRoom.State.CreationFailed {
|
||||
Log.error("\(StartConversationViewModel.TAG) Conversation \(id) creation has failed!")
|
||||
self.chatRoomSuscriptions.removeAll()
|
||||
if let chatRoomDelegate = self.chatRoomDelegate {
|
||||
chatRoom.removeDelegate(delegate: chatRoomDelegate)
|
||||
}
|
||||
self.chatRoomDelegate = nil
|
||||
DispatchQueue.main.async {
|
||||
self.operationInProgress = false
|
||||
ToastViewModel.shared.toastMessage = "Failed_to_create_conversation_error"
|
||||
|
|
@ -267,6 +274,7 @@ class ConversationForwardMessageViewModel: ObservableObject {
|
|||
}
|
||||
}
|
||||
})
|
||||
chatRoom.addDelegate(delegate: self.chatRoomDelegate!)
|
||||
}
|
||||
|
||||
func forwardMessage() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue