diff --git a/Nynja/Modules/AddParticipants/AddParticipantsProtocols.swift b/Nynja/Modules/AddParticipants/AddParticipantsProtocols.swift index 9cdfd4b04d94112963d628397fe9f7c167e1c375..2fa7f664f23105a2a5f5da4943251c43fa7e68c0 100644 --- a/Nynja/Modules/AddParticipants/AddParticipantsProtocols.swift +++ b/Nynja/Modules/AddParticipants/AddParticipantsProtocols.swift @@ -78,6 +78,7 @@ protocol AddParticipantsInteractorInputProtocol: BaseInteractorProtocol { func createRoom(name: String, avatar: UIImage?, members: [Member]) func getMySelf() -> Contact? func allocateConference() + func discardAllocatedConference() } protocol AddParticipantsInteractorOutputProtocol: class { diff --git a/Nynja/Modules/AddParticipants/Interactor/AddParticipantsInteractor.swift b/Nynja/Modules/AddParticipants/Interactor/AddParticipantsInteractor.swift index 8a8099072f6493b5efb6fc3575fba46226d330a4..30271cbc47e34228ec31f992ad486bc0c57343dc 100644 --- a/Nynja/Modules/AddParticipants/Interactor/AddParticipantsInteractor.swift +++ b/Nynja/Modules/AddParticipants/Interactor/AddParticipantsInteractor.swift @@ -58,6 +58,15 @@ class AddParticipantsInteractor: BaseInteractor, AddParticipantsInteractorInputP subject: room?.name ?? "Unnamed", roomId: room?.id ?? localId) } + + func discardAllocatedConference() { + guard let confId = self.allocateId else {return} + + callService.endConference(requestId: UUID().uuidString, conferenceId: confId) + callService.removeConference(byId: confId) + + self.allocateId = nil + } override func loadData() { super.loadData() diff --git a/Nynja/Modules/AddParticipants/Presenter/AddParticipantsPresenter.swift b/Nynja/Modules/AddParticipants/Presenter/AddParticipantsPresenter.swift index 3e53f80dd02a8494f8778c2ca152ecd5c44d6263..606214421b1999cefe4a5a487173da0296f2455a 100644 --- a/Nynja/Modules/AddParticipants/Presenter/AddParticipantsPresenter.swift +++ b/Nynja/Modules/AddParticipants/Presenter/AddParticipantsPresenter.swift @@ -11,7 +11,15 @@ class AddParticipantsPresenter: BasePresenter, AddParticipantsPresenterProtocol, var room: Room? var roomToCreate = Room() var contacts: [Contact]! - + + private var shouldDiscartAllocatedConference: Bool = true + + deinit { + if shouldDiscartAllocatedConference { + interactor.discardAllocatedConference() + } + } + override var itemsFactory: WCItemsFactory? { if participantsMode == .create { return CreateGroupItemsFactory() @@ -117,19 +125,25 @@ class AddParticipantsPresenter: BasePresenter, AddParticipantsPresenterProtocol, wireFrame.hide(with: .cancel) } case .createGroupCall: + shouldDiscartAllocatedConference = false if contacts.isEmpty { + interactor.discardAllocatedConference() wireFrame.hide(with: .cancel) } else { wireFrame.hide(with: .createGroupCall(callId: interactor.allocateId, contacts: contacts, room: room)) } case .createConferenceCall: + shouldDiscartAllocatedConference = false if contacts.isEmpty { + interactor.discardAllocatedConference() wireFrame.hide(with: .cancel) } else { wireFrame.hide(with: .createConferenceCall(callId: interactor.allocateId, contacts: contacts, room:roomToCreate)) } case .updateGroupCall: + shouldDiscartAllocatedConference = false if contacts.isEmpty { + interactor.discardAllocatedConference() wireFrame.hide(with: .cancel) } else { wireFrame.hide(with: .updateGroupCall(contacts: contacts)) diff --git a/Nynja/Modules/Message/Interactor/MessageInteractor.swift b/Nynja/Modules/Message/Interactor/MessageInteractor.swift index 14c417fdc8290229e942c8578993facc8ee9708c..49fb6950fd03ca3d693e48dbef7381c8caf421ab 100644 --- a/Nynja/Modules/Message/Interactor/MessageInteractor.swift +++ b/Nynja/Modules/Message/Interactor/MessageInteractor.swift @@ -337,6 +337,13 @@ final class MessageInteractor: BaseInteractor, MessageInteractorInputProtocol, H } } + func currentMembersCount() -> UInt { + if let r = self.room, let roomId = r.id { + return callService.currentMembersCountForCallWithRoom(roomId) + } + + return 0; + } // MARK: - Fetch Data private func fetchData() { diff --git a/Nynja/Modules/Message/Presenter/MessagePresenter.swift b/Nynja/Modules/Message/Presenter/MessagePresenter.swift index cbebb3d8c75e31ca5f343a7580a48b250a1d2f54..829da4843794c67b6eb7231963ca9be3e7e06bd7 100644 --- a/Nynja/Modules/Message/Presenter/MessagePresenter.swift +++ b/Nynja/Modules/Message/Presenter/MessagePresenter.swift @@ -686,7 +686,7 @@ class MessagePresenter: BasePresenter, MessagePresenterProtocol, MessageInteract } func didChangeCallInvitationState(_ call: NYNCall) { - self.view.displayRejoinBanner(display: call.isRunning, count: call.participantsCount) + self.view.displayRejoinBanner(display: call.isRunning, count: call.membersCount) } private func createDisplayChatConfiguration(with cells: [BaseChatCellModel], @@ -997,6 +997,10 @@ class MessagePresenter: BasePresenter, MessagePresenterProtocol, MessageInteract interactor.rejoinRunningCall() } + func currentMembersCount() -> UInt { + return interactor.currentMembersCount() + } + func openMarketplaceScreen() { self.wireFrame.openMarketplaceScreen() } diff --git a/Nynja/Modules/Message/Protocols/MessageProtocols.swift b/Nynja/Modules/Message/Protocols/MessageProtocols.swift index 104ea6625a291afc1a97d91e0df9da0ef1d4eb22..a8ecfef1f6e567832b3dc0ba53b63cc657de94cc 100644 --- a/Nynja/Modules/Message/Protocols/MessageProtocols.swift +++ b/Nynja/Modules/Message/Protocols/MessageProtocols.swift @@ -127,6 +127,7 @@ protocol MessagePresenterProtocol: BasePresenterProtocol, func hasCallInProgress() -> Bool func rejoinRunningCall() func openMarketplaceScreen() + func currentMembersCount() -> UInt } //MARK: Interactor - @@ -253,6 +254,8 @@ protocol MessageInteractorInputProtocol: BaseInteractorProtocol, MentionFetchInp func prepareToForward(localId: MessageLocalId) func didSelectForwardTargets(_ targets: ForwardTargets) + + func currentMembersCount() -> UInt } //MARK: View - diff --git a/Nynja/Modules/Message/View/MessageVC.swift b/Nynja/Modules/Message/View/MessageVC.swift index c73c13a70ad8d47af56e8ebd60460ed3b8fbb858..486e9a76d462a1270ea09727d2b106443c42280b 100644 --- a/Nynja/Modules/Message/View/MessageVC.swift +++ b/Nynja/Modules/Message/View/MessageVC.swift @@ -424,7 +424,7 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw mentionCounterView.isHidden = true stickerSearchResultView.isHidden = true - displayRejoinBanner(display: presenter.hasRunningCall(), count: 0) + displayRejoinBanner(display: presenter.hasRunningCall(), count: presenter.currentMembersCount()) } override func prepareForDissappear() { diff --git a/Nynja/Services/NynjaCommunicatorService.swift b/Nynja/Services/NynjaCommunicatorService.swift index 4662818e602201fde80e5475a9c5ca5dedd1be01..399caa465398a4780eeb7daff7732c73709123bd 100644 --- a/Nynja/Services/NynjaCommunicatorService.swift +++ b/Nynja/Services/NynjaCommunicatorService.swift @@ -132,7 +132,7 @@ class NynjaCommunicatorService: NSObject, NynjaCommunicatorDelegate, NYNCallDele isCallInProgress = true let roomName = (room != nil && room?.name != nil) ? room?.name! : "unnamed" - let members = makeMembers(contacts: contacts) + let members = makeMembers(contacts: contacts, room: room) let roomId = (room != nil && room?.id != nil) ? room?.id! : "" let creator = CallCreatorMediator(createId: UUID().uuidString, members: members, @@ -160,7 +160,7 @@ class NynjaCommunicatorService: NSObject, NynjaCommunicatorDelegate, NYNCallDele isCallInProgress = true let roomName = room?.name ?? "unnamed" - let members = makeMembers(contacts: contacts) + let members = makeMembers(contacts: contacts, room: room) let roomId = room?.id ?? "" let creator = CallCreatorMediator(createId: UUID().uuidString, members: members, @@ -180,6 +180,10 @@ class NynjaCommunicatorService: NSObject, NynjaCommunicatorDelegate, NYNCallDele withSubject: subject) } + func removeConference(byId conferenceId: String) { + self.nynComm.getCallManager().removeConference(byId: conferenceId) + } + func endConference(requestId:String, conferenceId: String) { self.nynComm.getCallManager().endConference(withRequestId: requestId, @@ -299,6 +303,14 @@ class NynjaCommunicatorService: NSObject, NynjaCommunicatorDelegate, NYNCallDele } } + func currentMembersCountForCallWithRoom(_ roomId: String) -> UInt { + if let call = self.nynComm.getCallManager().getCallForRunningCall(withRoom: roomId) { + return call.membersCount + } + + return 0 + } + func didChangeConferenceState(_ state: NYNCallState) { if let c = self.call { self.callDelegate?.stateDidChange(call: c, state: state) @@ -365,13 +377,15 @@ class NynjaCommunicatorService: NSObject, NynjaCommunicatorDelegate, NYNCallDele return roster.myContact } - func makeMembers(contacts: [Contact]) -> [Member] { + func makeMembers(contacts: [Contact], room: Room?) -> [Member] { var members = [Member]() for i in contacts { members.append(Member(contact: i)) } - if let mySelf = getMySelf() { + if let r = room, let selfMember = r.selfMember { + members.append(selfMember) + } else if let mySelf = getMySelf() { let myMember = Member(contact: mySelf) members.append(myMember) } diff --git a/Podfile b/Podfile index 804873610e12a33a84a6fcd1985cc7655e9442c5..b08fb1ca05c9bebfd0bd97a4b056c17034f3edba 100644 --- a/Podfile +++ b/Podfile @@ -39,7 +39,7 @@ def commonPodsForNynja pod 'MaterialComponents/FlexibleHeader' pod 'JTAppleCalendar', '~> 7.0' - pod 'NynjaSDK', '= 1.5.2' + pod 'NynjaSDK', '= 1.5.3' pod 'CryptoSwift'