From 2f03cc409cafb224dae6083a84f61cbb4770f66c Mon Sep 17 00:00:00 2001 From: Angel Terziev Date: Tue, 11 Sep 2018 11:35:32 +0300 Subject: [PATCH] NY-3327: iOS: Call participants are not sorted correctly. NY-3320: iOS: Fake call is created when cancel call on select participants. NY-3281: iOS: Banner to rejoin a conference call in progress - Missing call members and call duration --- .../AddParticipantsProtocols.swift | 1 + .../AddParticipantsInteractor.swift | 9 ++++++++ .../Presenter/AddParticipantsPresenter.swift | 16 +++++++++++++- .../Interactor/MessageInteractor.swift | 7 ++++++ .../Message/Presenter/MessagePresenter.swift | 6 ++++- .../Message/Protocols/MessageProtocols.swift | 3 +++ Nynja/Modules/Message/View/MessageVC.swift | 2 +- Nynja/Services/NynjaCommunicatorService.swift | 22 +++++++++++++++---- Podfile | 2 +- 9 files changed, 60 insertions(+), 8 deletions(-) diff --git a/Nynja/Modules/AddParticipants/AddParticipantsProtocols.swift b/Nynja/Modules/AddParticipants/AddParticipantsProtocols.swift index 9cdfd4b04..2fa7f664f 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 8a8099072..30271cbc4 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 3e53f80dd..606214421 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 97927d23d..65c67220c 100644 --- a/Nynja/Modules/Message/Interactor/MessageInteractor.swift +++ b/Nynja/Modules/Message/Interactor/MessageInteractor.swift @@ -332,6 +332,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 19581446b..4c183ef3f 100644 --- a/Nynja/Modules/Message/Presenter/MessagePresenter.swift +++ b/Nynja/Modules/Message/Presenter/MessagePresenter.swift @@ -697,7 +697,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], @@ -1001,6 +1001,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 00012dff7..cceb02a18 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 b90ec0a97..691882e1e 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 4662818e6..399caa465 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 804873610..b08fb1ca0 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' -- GitLab