Skip to content

Commit

Permalink
fixup! Display Live Observation alert before normal engagement
Browse files Browse the repository at this point in the history
This PR displays Live Observation confirmation alert before normal engagement.
This alert can't be skipped and needs visitor's manual confirmation to
enqueue.

MOB-2678
  • Loading branch information
rasmustautsglia committed Oct 3, 2023
1 parent ca1ab9f commit 84f13b5
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 73 deletions.
4 changes: 0 additions & 4 deletions GliaWidgets.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,6 @@
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 */; };
Expand Down Expand Up @@ -1341,7 +1340,6 @@
C06A7583296EC9DC006B69A2 /* NumberSlotStyle.Accessibility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumberSlotStyle.Accessibility.swift; sourceTree = "<group>"; };
C06A7585296ECC57006B69A2 /* VisitorCodeStyle.Accessibility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VisitorCodeStyle.Accessibility.swift; sourceTree = "<group>"; };
C06A7587296ECD75006B69A2 /* Theme+VisitorCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Theme+VisitorCode.swift"; sourceTree = "<group>"; };
C07666742ACAD76C00BB8375 /* LiveObservationConfirmationPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveObservationConfirmationPresenter.swift; sourceTree = "<group>"; };
C07F62452ABC322B003EFC97 /* OrientationManager.Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrientationManager.Mock.swift; sourceTree = "<group>"; };
C07F62762AC1BA2B003EFC97 /* UIViewController+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Extensions.swift"; sourceTree = "<group>"; };
C07F62822AC33BB9003EFC97 /* UIView+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Extensions.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2337,7 +2335,6 @@
1A0EDF8925E8E20A0076D1AD /* Popover */,
1A6EBB2325ADE35500EE325D /* MediaUpgrade */,
1A63B2F1257A3F2D00508478 /* Alert */,
C07666742ACAD76C00BB8375 /* LiveObservationConfirmationPresenter.swift */,
);
path = Common;
sourceTree = "<group>";
Expand Down Expand Up @@ -4347,7 +4344,6 @@
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 */,
Expand Down
40 changes: 40 additions & 0 deletions GliaWidgets/Sources/ViewController/Call/CallViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ final class CallViewController: EngagementViewController {
private let viewModel: CallViewModel
private let environment: Environment
private var proximityManager: ProximityManager?
private var hasViewAppeared = false

private var pendingLiveObservationConfirmation: LiveObservationConfirmation?

init(viewModel: CallViewModel, viewFactory: ViewFactory, environment: Environment) {
self.environment = environment
Expand Down Expand Up @@ -63,6 +66,15 @@ final class CallViewController: EngagementViewController {
view.checkBarsOrientation()
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
hasViewAppeared = true
if let alertConfig = pendingLiveObservationConfirmation {
showLiveObservationConfirmationAlert(with: alertConfig)
pendingLiveObservationConfirmation = nil
}
}

@objc
private func deviceDidRotate() {
guard let view = view as? CallView else { return }
Expand Down Expand Up @@ -125,6 +137,8 @@ final class CallViewController: EngagementViewController {
view.isVisitrOnHold = isOnHold
case .transferring:
view.setConnectState(.transferring, animated: true)
case let .showLiveObservationConfirmation(configuration):
self?.showLiveObservationConfirmation(with: configuration)
}
}
}
Expand All @@ -140,6 +154,26 @@ final class CallViewController: EngagementViewController {
style: props.style
)
}

private func showLiveObservationConfirmation(with config: LiveObservationConfirmation) {
switch hasViewAppeared {
case true: showLiveObservationConfirmationAlert(with: config)
case false: pendingLiveObservationConfirmation = config
}
}

private func showLiveObservationConfirmationAlert(with config: LiveObservationConfirmation) {
let alert = AlertViewController(
kind: .liveObservationConfirmation(
config.conf,
accepted: config.accepted,
declined: config.declined
),
viewFactory: self.viewFactory
)

replacePresentedOfferIfPossible(with: alert)
}
}

private extension CallViewModel.CallButton {
Expand Down Expand Up @@ -194,4 +228,10 @@ extension CallViewController {
var uiDevice: UIKitBased.UIDevice
var notificationCenter: FoundationBased.NotificationCenter
}

struct LiveObservationConfirmation {
let conf: ConfirmationAlertConfiguration
let accepted: () -> Void
let declined: () -> Void
}
}
34 changes: 34 additions & 0 deletions GliaWidgets/Sources/ViewController/Chat/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ final class ChatViewController: EngagementViewController, PopoverPresenter {
}
}
private var lastVisibleRowIndexPath: IndexPath?
private var hasViewAppeared = false
private var pendingLiveObservationConfirmation: CallViewController.LiveObservationConfirmation?

init(
viewModel: SecureConversations.ChatWithTranscriptModel,
Expand Down Expand Up @@ -36,6 +38,15 @@ final class ChatViewController: EngagementViewController, PopoverPresenter {
viewModel.event(.viewDidLoad)
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
hasViewAppeared = true
if let alertConfig = pendingLiveObservationConfirmation {
showLiveObservationConfirmationAlert(with: alertConfig)
pendingLiveObservationConfirmation = nil
}
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

Expand Down Expand Up @@ -168,12 +179,35 @@ final class ChatViewController: EngagementViewController, PopoverPresenter {
view?.messageEntryView.uploadListView.props = fileUploadListProps
case let .quickReplyPropsUpdated(props):
view?.renderQuickReply(props: props)
case let .showLiveObservationConfirmation(configuration):
self?.showLiveObservationConfirmation(with: configuration)
}
self?.renderProps()
}
}
// swiftlint:enable function_body_length

private func showLiveObservationConfirmation(
with config: CallViewController.LiveObservationConfirmation) {
switch hasViewAppeared {
case true: showLiveObservationConfirmationAlert(with: config)
case false: pendingLiveObservationConfirmation = config
}
}

private func showLiveObservationConfirmationAlert(with config: CallViewController.LiveObservationConfirmation) {
let alert = AlertViewController(
kind: .liveObservationConfirmation(
config.conf,
accepted: config.accepted,
declined: config.declined
),
viewFactory: self.viewFactory
)

replacePresentedOfferIfPossible(with: alert)
}

private func presentMediaPicker(
from sourceView: UIView,
itemSelected: @escaping (AttachmentSourceItemKind) -> Void
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit

class EngagementViewController: UIViewController, AlertPresenter, MediaUpgradePresenter, ScreenShareOfferPresenter, LiveObservationConfirmationPresenter {
class EngagementViewController: UIViewController, AlertPresenter, MediaUpgradePresenter, ScreenShareOfferPresenter {
let viewFactory: ViewFactory
private var viewModel: CommonEngagementModel

Expand Down Expand Up @@ -63,12 +63,6 @@ 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
)
}
}
}
Expand Down
24 changes: 22 additions & 2 deletions GliaWidgets/Sources/ViewModel/Call/CallViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class CallViewModel: EngagementViewModel, ViewModel {

switch startWith {
case .engagement(let mediaType):
enqueue(mediaType: mediaType)

interactor.state = .enqueueing
showLiveObservationConfirmation(in: mediaType)
case .call(offer: let offer, answer: let answer):
call.upgrade(to: offer)
showConnecting()
Expand Down Expand Up @@ -315,6 +315,25 @@ extension CallViewModel {
)
)
}

private func showLiveObservationConfirmation(in mediaType: CoreSdkClient.MediaType) {
let liveObservationAlertConfig = createLiveObservationAlertConfig(with: mediaType)
action?(.showLiveObservationConfirmation(liveObservationAlertConfig))
}

private func createLiveObservationAlertConfig(
with mediaType: CoreSdkClient.MediaType
) -> CallViewController.LiveObservationConfirmation {
.init(
conf: self.alertConfiguration.liveObservationConfirmation,
accepted: { [weak self] in
self?.enqueue(mediaType: mediaType)
},
declined: { [weak self] in
self?.endSession()
}
)
}
}

extension CallViewModel {
Expand Down Expand Up @@ -537,6 +556,7 @@ extension CallViewModel {
case setRemoteVideo(CoreSdkClient.StreamView?)
case setLocalVideo(CoreSdkClient.StreamView?)
case setVisitorOnHold(isOnHold: Bool)
case showLiveObservationConfirmation(CallViewController.LiveObservationConfirmation)
}

enum DelegateEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ extension ChatViewModel: ViewModel {
case setAttachmentButtonVisibility(MediaPickerButtonVisibility)
case fileUploadListPropsUpdated(SecureConversations.FileUploadListView.Props)
case quickReplyPropsUpdated(QuickReplyView.Props)
case showLiveObservationConfirmation(CallViewController.LiveObservationConfirmation)
}

enum DelegateEvent {
Expand Down
35 changes: 24 additions & 11 deletions GliaWidgets/Sources/ViewModel/Chat/ChatViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ class ChatViewModel: EngagementViewModel {
}
}

// swiftlint:disable function_body_length
override func update(for state: InteractorState) {
super.update(for: state)

Expand All @@ -199,15 +198,7 @@ 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()
}
))
showLiveObservationConfirmation(in: .text)
case .engaged(let engagedOperator):
let name = engagedOperator?.firstName
let pictureUrl = engagedOperator?.picture?.url
Expand Down Expand Up @@ -260,7 +251,6 @@ class ChatViewModel: EngagementViewModel {
break
}
}
// swiftlint:enable function_body_length

override func interactorEvent(_ event: InteractorEvent) {
super.interactorEvent(event)
Expand Down Expand Up @@ -941,6 +931,29 @@ extension ChatViewModel {
}
}

// MARK: Live Observation

extension ChatViewModel {
private func showLiveObservationConfirmation(in mediaType: CoreSdkClient.MediaType) {
let liveObservationAlertConfig = createLiveObservationAlertConfig(with: mediaType)
action?(.showLiveObservationConfirmation(liveObservationAlertConfig))
}

private func createLiveObservationAlertConfig(
with mediaType: CoreSdkClient.MediaType
) -> CallViewController.LiveObservationConfirmation {
.init(
conf: self.alertConfiguration.liveObservationConfirmation,
accepted: { [weak self] in
self?.enqueue(mediaType: mediaType)
},
declined: { [weak self] in
self?.endSession()
}
)
}
}

extension ChatViewModel {
static func shouldSkipEnqueueingState(for chatType: ChatType) -> Bool {
switch chatType {
Expand Down
19 changes: 0 additions & 19 deletions GliaWidgets/Sources/ViewModel/EngagementViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ class EngagementViewModel: CommonEngagementModel {
)
)
})

default:
break
}
Expand Down Expand Up @@ -191,19 +190,6 @@ 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)
}
Expand Down Expand Up @@ -373,11 +359,6 @@ extension EngagementViewModel {
accepted: () -> Void,
declined: () -> Void
)
case showLiveObservationConfirmation(
ConfirmationAlertConfiguration,
accepted: () -> Void,
declined: () -> Void
)
case showEndButton
case showEndScreenShareButton
}
Expand Down

0 comments on commit 84f13b5

Please sign in to comment.