diff --git a/GliaWidgets.xcodeproj/project.pbxproj b/GliaWidgets.xcodeproj/project.pbxproj index 2c39a0b4a..0c622bca5 100644 --- a/GliaWidgets.xcodeproj/project.pbxproj +++ b/GliaWidgets.xcodeproj/project.pbxproj @@ -598,6 +598,7 @@ C06A7584296EC9DC006B69A2 /* NumberSlotStyle.Accessibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = C06A7583296EC9DC006B69A2 /* NumberSlotStyle.Accessibility.swift */; }; C06A7586296ECC57006B69A2 /* VisitorCodeStyle.Accessibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = C06A7585296ECC57006B69A2 /* VisitorCodeStyle.Accessibility.swift */; }; C06A7588296ECD75006B69A2 /* Theme+VisitorCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = C06A7587296ECD75006B69A2 /* Theme+VisitorCode.swift */; }; + C07666752ACAD76C00BB8375 /* LiveObservationConfirmationPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07666742ACAD76C00BB8375 /* LiveObservationConfirmationPresenter.swift */; }; C07F62462ABC322B003EFC97 /* OrientationManager.Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07F62452ABC322B003EFC97 /* OrientationManager.Mock.swift */; }; C07F62772AC1BA2B003EFC97 /* UIViewController+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07F62762AC1BA2B003EFC97 /* UIViewController+Extensions.swift */; }; C07F62832AC33BB9003EFC97 /* UIView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07F62822AC33BB9003EFC97 /* UIView+Extensions.swift */; }; @@ -1340,6 +1341,7 @@ C06A7583296EC9DC006B69A2 /* NumberSlotStyle.Accessibility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumberSlotStyle.Accessibility.swift; sourceTree = ""; }; C06A7585296ECC57006B69A2 /* VisitorCodeStyle.Accessibility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VisitorCodeStyle.Accessibility.swift; sourceTree = ""; }; C06A7587296ECD75006B69A2 /* Theme+VisitorCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Theme+VisitorCode.swift"; sourceTree = ""; }; + C07666742ACAD76C00BB8375 /* LiveObservationConfirmationPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveObservationConfirmationPresenter.swift; sourceTree = ""; }; C07F62452ABC322B003EFC97 /* OrientationManager.Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrientationManager.Mock.swift; sourceTree = ""; }; C07F62762AC1BA2B003EFC97 /* UIViewController+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Extensions.swift"; sourceTree = ""; }; C07F62822AC33BB9003EFC97 /* UIView+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Extensions.swift"; sourceTree = ""; }; @@ -2335,6 +2337,7 @@ 1A0EDF8925E8E20A0076D1AD /* Popover */, 1A6EBB2325ADE35500EE325D /* MediaUpgrade */, 1A63B2F1257A3F2D00508478 /* Alert */, + C07666742ACAD76C00BB8375 /* LiveObservationConfirmationPresenter.swift */, ); path = Common; sourceTree = ""; @@ -4344,6 +4347,7 @@ 75CF8D6329B7DD8300CB1524 /* SecureConversations+ConfirmationStyle+RemoteConfig.swift in Sources */, 1A475BB325DE831F00296D55 /* BadgeView.swift in Sources */, 1A38A8A8258B652B0089DE7B /* OperatorChatMessageStyle.swift in Sources */, + C07666752ACAD76C00BB8375 /* LiveObservationConfirmationPresenter.swift in Sources */, 1A7CA8212574D6760047CBBE /* ConnectOperatorView.swift in Sources */, 755D187329A6A6860009F5E8 /* WelcomeStyle+MessageTextViewActiveStyle.swift in Sources */, 9AB196D427C3D7FD00FD60AB /* Interactor.Environment.Mock.swift in Sources */, diff --git a/GliaWidgets/Sources/Interactor/Interactor.swift b/GliaWidgets/Sources/Interactor/Interactor.swift index 95ab3e77e..25bb84a5a 100644 --- a/GliaWidgets/Sources/Interactor/Interactor.swift +++ b/GliaWidgets/Sources/Interactor/Interactor.swift @@ -140,8 +140,6 @@ extension Interactor { success: @escaping () -> Void, failure: @escaping (CoreSdkClient.SalemoveError) -> Void ) { - state = .enqueueing - let options = mediaType == .audio || mediaType == .video ? CoreSdkClient.EngagementOptions(mediaDirection: .twoWay) : nil diff --git a/GliaWidgets/Sources/ViewController/Common/LiveObservationConfirmationPresenter.swift b/GliaWidgets/Sources/ViewController/Common/LiveObservationConfirmationPresenter.swift new file mode 100644 index 000000000..964deec31 --- /dev/null +++ b/GliaWidgets/Sources/ViewController/Common/LiveObservationConfirmationPresenter.swift @@ -0,0 +1,30 @@ +import UIKit + +protocol LiveObservationConfirmationPresenter: DismissalAndPresentationController where Self: UIViewController { + var viewFactory: ViewFactory { get } + + func offerScreenShare( + with conf: ScreenShareOfferAlertConfiguration, + accepted: @escaping () -> Void, + declined: @escaping () -> Void + ) +} + +extension LiveObservationConfirmationPresenter { + func showLiveObservationConfirmationAlert( + with conf: ConfirmationAlertConfiguration, + accepted: @escaping () -> Void, + declined: @escaping () -> Void + ) { + let alert = AlertViewController( + kind: .liveObservationConfirmation( + conf, + accepted: accepted, + declined: declined + ), + viewFactory: self.viewFactory + ) + + replacePresentedOfferIfPossible(with: alert) + } +} diff --git a/GliaWidgets/Sources/ViewController/EngagementViewController.swift b/GliaWidgets/Sources/ViewController/EngagementViewController.swift index 09db258dc..df518b5b1 100644 --- a/GliaWidgets/Sources/ViewController/EngagementViewController.swift +++ b/GliaWidgets/Sources/ViewController/EngagementViewController.swift @@ -1,6 +1,6 @@ import UIKit -class EngagementViewController: UIViewController, AlertPresenter, MediaUpgradePresenter, ScreenShareOfferPresenter { +class EngagementViewController: UIViewController, AlertPresenter, MediaUpgradePresenter, ScreenShareOfferPresenter, LiveObservationConfirmationPresenter { let viewFactory: ViewFactory private var viewModel: CommonEngagementModel @@ -63,6 +63,12 @@ class EngagementViewController: UIViewController, AlertPresenter, MediaUpgradePr view?.header.showEndButton() case .showEndScreenShareButton: view?.header.showEndScreenSharingButton() + case .showLiveObservationConfirmation(let conf, let accepted, let declined): + self.showLiveObservationConfirmationAlert( + with: conf, + accepted: accepted, + declined: declined + ) } } } diff --git a/GliaWidgets/Sources/ViewModel/Chat/ChatViewModel.swift b/GliaWidgets/Sources/ViewModel/Chat/ChatViewModel.swift index 3f1495faf..f302c20ab 100644 --- a/GliaWidgets/Sources/ViewModel/Chat/ChatViewModel.swift +++ b/GliaWidgets/Sources/ViewModel/Chat/ChatViewModel.swift @@ -177,11 +177,12 @@ class ChatViewModel: EngagementViewModel { // or in case if engagement has been restored. if history.isEmpty || self.environment.getCurrentEngagement() != nil { - self.enqueue(mediaType: .text) + interactor.state = .enqueueing } } } + // swiftlint:disable function_body_length override func update(for state: InteractorState) { super.update(for: state) @@ -198,7 +199,15 @@ class ChatViewModel: EngagementViewModel { action?(.queue) action?(.scrollToBottom(animated: true)) - + engagementAction?(.showLiveObservationConfirmation( + self.alertConfiguration.liveObservationConfirmation, + accepted: { [weak self] in + self?.enqueue(mediaType: .text) + }, + declined: { [weak self] in + self?.endSession() + } + )) case .engaged(let engagedOperator): let name = engagedOperator?.firstName let pictureUrl = engagedOperator?.picture?.url @@ -247,11 +256,11 @@ class ChatViewModel: EngagementViewModel { } } } - default: break } } + // swiftlint:enable function_body_length override func interactorEvent(_ event: InteractorEvent) { super.interactorEvent(event) diff --git a/GliaWidgets/Sources/ViewModel/EngagementViewModel.swift b/GliaWidgets/Sources/ViewModel/EngagementViewModel.swift index e1e615749..d0b108d85 100644 --- a/GliaWidgets/Sources/ViewModel/EngagementViewModel.swift +++ b/GliaWidgets/Sources/ViewModel/EngagementViewModel.swift @@ -191,6 +191,19 @@ class EngagementViewModel: CommonEngagementModel { ) } + func showAlert( + accepted: @escaping () -> Void, + declined: @escaping () -> Void + ) { + let conf = self.alertConfiguration.liveObservationConfirmation + engagementAction?( + .showLiveObservationConfirmation( + conf, + accepted: accepted, + declined: declined + )) + } + func showAlert(for error: Error) { showAlert(with: alertConfiguration.unexpectedError) } @@ -360,6 +373,11 @@ extension EngagementViewModel { accepted: () -> Void, declined: () -> Void ) + case showLiveObservationConfirmation( + ConfirmationAlertConfiguration, + accepted: () -> Void, + declined: () -> Void + ) case showEndButton case showEndScreenShareButton }