Skip to content

Commit

Permalink
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 2, 2023
1 parent 1e7c941 commit 19d15d8
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 6 deletions.
4 changes: 4 additions & 0 deletions GliaWidgets.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -1340,6 +1341,7 @@
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 @@ -2335,6 +2337,7 @@
1A0EDF8925E8E20A0076D1AD /* Popover */,
1A6EBB2325ADE35500EE325D /* MediaUpgrade */,
1A63B2F1257A3F2D00508478 /* Alert */,
C07666742ACAD76C00BB8375 /* LiveObservationConfirmationPresenter.swift */,
);
path = Common;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
2 changes: 0 additions & 2 deletions GliaWidgets/Sources/Interactor/Interactor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit

class EngagementViewController: UIViewController, AlertPresenter, MediaUpgradePresenter, ScreenShareOfferPresenter {
class EngagementViewController: UIViewController, AlertPresenter, MediaUpgradePresenter, ScreenShareOfferPresenter, LiveObservationConfirmationPresenter {

Check warning on line 3 in GliaWidgets/Sources/ViewController/EngagementViewController.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Line Length Violation: Line should be 150 characters or less; currently it has 154 characters (line_length)
let viewFactory: ViewFactory
private var viewModel: CommonEngagementModel

Expand Down Expand Up @@ -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
)
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions GliaWidgets/Sources/ViewModel/Chat/ChatViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -247,11 +256,11 @@ class ChatViewModel: EngagementViewModel {
}
}
}

default:
break
}
}
// swiftlint:enable function_body_length

override func interactorEvent(_ event: InteractorEvent) {
super.interactorEvent(event)
Expand Down
18 changes: 18 additions & 0 deletions GliaWidgets/Sources/ViewModel/EngagementViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -360,6 +373,11 @@ extension EngagementViewModel {
accepted: () -> Void,
declined: () -> Void
)
case showLiveObservationConfirmation(
ConfirmationAlertConfiguration,
accepted: () -> Void,
declined: () -> Void
)
case showEndButton
case showEndScreenShareButton
}
Expand Down

0 comments on commit 19d15d8

Please sign in to comment.