Skip to content

Commit

Permalink
Show snackbar when engagement request is timed out
Browse files Browse the repository at this point in the history
Snackbar needs to be showed after request has timed out. Also, if outcome is anything but nil or timed_out, we need to ignore it
  • Loading branch information
rasmustautsglia authored and Egor Egorov committed Sep 16, 2024
1 parent fe6ca65 commit 7b3ebb2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
1 change: 1 addition & 0 deletions GliaWidgets/Public/Glia/Glia+RestoreEngagement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extension Glia {

func showSnackBarMessage() {
environment.snackBar.showSnackBarMessage(
text: viewFactory.theme.snackBar.text,
style: viewFactory.theme.snackBar,
topMostViewController: GliaPresenter(
environment: .create(
Expand Down
6 changes: 3 additions & 3 deletions GliaWidgets/Sources/CallVisualizer/CallVisualizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ extension CallVisualizer {
coordinator.handleAcceptedUpgrade()
}

func handleEngagementRequestAccepted(request: CoreSdkClient.Request, answer: Command<Bool>) {
coordinator.handleEngagementRequestAccepted(request: request, answer: answer)
func handleEngagementRequest(request: CoreSdkClient.Request, answer: Command<Bool>) {
coordinator.handleEngagementRequest(request: request, answer: answer)
}

func addVideoStream(stream: CoreSdkClient.VideoStreamable) {
Expand Down Expand Up @@ -131,7 +131,7 @@ extension CallVisualizer {
else {
switch event {
case let .onEngagementRequest(request, answer):
self?.handleEngagementRequestAccepted(request: request, answer: answer)
self?.handleEngagementRequest(request: request, answer: answer)
default: return
}
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,33 @@ extension CallVisualizer {
showVideoCallViewController()
}

func handleEngagementRequestAccepted(request: CoreSdkClient.Request, answer: Command<Bool>) {
if request.outcome == .timedOut {
self.environment.alertManager.dismissCurrentAlert()
answer(false)
func handleEngagementRequest(
request: CoreSdkClient.Request,
answer: Command<Bool>
) {
guard request.outcome == .timedOut else {
handleEngagementRequestOutcomeNil(answer: answer)
return
}
handleEngagementRequestOutcomeTimeout(answer: answer)
}

func handleEngagementRequestOutcomeTimeout(answer: Command<Bool>) {
environment.alertManager.dismissCurrentAlert()
environment.gcd.mainQueue.asyncAfterDeadline(.now() + 0.5) {
// Will be swapped for localized string
self.showSnackBarMessage(text: "Request has timed out")
}
answer(false)
}

func handleEngagementRequestOutcomeNil(answer: Command<Bool>) {
fetchSiteConfigurations { [weak self] site in
let showSnackBarIfNeeded: () -> Void = {
guard site.mobileObservationEnabled == true else { return }
guard site.mobileObservationIndicationEnabled == true else { return }
self?.showSnackBarMessage()
guard let self else { return }
self.showSnackBarMessage(text: self.environment.viewFactory.theme.snackBar.text)
}
let completion: Command<Bool> = .init { isAccepted in
if isAccepted {
Expand Down Expand Up @@ -100,7 +116,8 @@ extension CallVisualizer {
fetchSiteConfigurations { [weak self] site in
guard site.mobileObservationEnabled == true else { return }
guard site.mobileObservationIndicationEnabled == true else { return }
self?.showSnackBarMessage()
guard let self else { return }
self.showSnackBarMessage(text: self.environment.viewFactory.theme.snackBar.text)
}
}

Expand Down Expand Up @@ -428,8 +445,9 @@ private extension CallVisualizer.Coordinator {
// MARK: - Live Observation

private extension CallVisualizer.Coordinator {
func showSnackBarMessage() {
func showSnackBarMessage(text: String) {
environment.snackBar.showSnackBarMessage(
text: text,
style: environment.viewFactory.theme.snackBar,
topMostViewController: topMostViewController,
timerProviding: environment.timerProviding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ struct SnackBar {
}

func showSnackBarMessage(
text: String,
style: Theme.SnackBarStyle,
topMostViewController: UIViewController,
timerProviding: FoundationBased.Timer.Providing,
gcd: GCD,
notificationCenter: FoundationBased.NotificationCenter
) {
self.present(
text: style.text,
text: text,
style: style,
for: topMostViewController,
bottomOffset: -60,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ final class CallVisualizerCoordinatorTests: XCTestCase {
}

let request = CoreSdkClient.Request(id: "123", outcome: .accepted, platform: nil)
coordinator.handleEngagementRequestAccepted(request: request, answer: answer)
coordinator.handleEngagementRequest(request: request, answer: answer)
XCTAssertEqual(answers, [true])
}

Expand Down Expand Up @@ -87,7 +87,7 @@ final class CallVisualizerCoordinatorTests: XCTestCase {

let answer = Command<Bool> { _ in }
let request = CoreSdkClient.Request(id: "123", outcome: .accepted, platform: nil)
coordinator.handleEngagementRequestAccepted(request: request, answer: answer)
coordinator.handleEngagementRequest(request: request, answer: answer)

XCTAssertTrue(coordinator.environment.presenter.getInstance()?.presentedViewController is AlertViewController)
}
Expand Down Expand Up @@ -121,7 +121,7 @@ final class CallVisualizerCoordinatorTests: XCTestCase {

let answer = Command<Bool> { _ in }
let request = CoreSdkClient.Request(id: "123", outcome: .timedOut, platform: nil)
coordinator.handleEngagementRequestAccepted(request: request, answer: answer)
coordinator.handleEngagementRequest(request: request, answer: answer)

XCTAssertFalse(coordinator.environment.presenter.getInstance()?.presentedViewController is AlertViewController)
}
Expand Down

0 comments on commit 7b3ebb2

Please sign in to comment.