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 anythign but nil or timed_out, we need to ignore it
  • Loading branch information
rasmustautsglia committed Sep 12, 2024
1 parent 365e705 commit d3ed70e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 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,35 @@ extension CallVisualizer {
showVideoCallViewController()
}

func handleEngagementRequestAccepted(request: CoreSdkClient.Request, answer: Command<Bool>) {
if let outcome = request.outcome, outcome == "timed_out" {
self.environment.alertManager.dismissCurrentAlert()
answer(false)
func handleEngagementRequest(
request: CoreSdkClient.Request,
answer: Command<Bool>
) {
guard let outcome = request.outcome else {
handleEngagementRequestOutcomeNil(answer: answer)
return
}
if outcome == "timed_out" {
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 All @@ -84,6 +102,7 @@ extension CallVisualizer {
}
}


Check warning on line 105 in GliaWidgets/Sources/CallVisualizer/Coordinator/CallVisualizer.Coordinator.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Vertical Whitespace Violation: Limit vertical whitespace to a single empty line; currently 2 (vertical_whitespace)
func end() {
removeBubbleView()
closeFlow()
Expand All @@ -100,7 +119,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 +448,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

0 comments on commit d3ed70e

Please sign in to comment.