Skip to content

Commit

Permalink
Implement EngagementLauncher enqueuing logic
Browse files Browse the repository at this point in the history
- Show already in contact snackbar for chat/SC enqueueing if audio/video already enqueued
- Maximize bubble for chat/SC enqueueing if chat/SC already enqueued
- Show already in contact snackbar for audio/video enqueueing if chat/SC already enqueued
- Maximize bubble for audio/video enqueueing if audio/video already enqueued
  • Loading branch information
ykyivskyi-gl committed Jan 31, 2025
1 parent a718cac commit bc70d0c
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 446 deletions.
38 changes: 35 additions & 3 deletions GliaWidgets/Public/Glia/Glia+EngagementSetup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ extension Glia {
/// If during enqueued state the visitor initiates another engagement, we avoid cancelling the queue
/// ticket and adding a new one, by monitoring the new engagement kind. If the engagement kind matches
/// the current enqueued engagement kind, then we resume the old, and do not start a new one
if case let .enqueued(_, enqueudEngagementKind) = interactor.state, enqueudEngagementKind == engagementKind, let rootCoordinator {
rootCoordinator.maximize()
if let enqueueingEngagementKind = interactor.state.enqueueingEngagementKind {
handleEnqueueingEngagement(
from: engagementKind,
enqueueingEngagementKind: enqueueingEngagementKind,
snackBarStyle: viewFactory.theme.snackBar
)
return
}

Expand Down Expand Up @@ -271,6 +275,35 @@ extension Glia {
}
}

private func handleEnqueueingEngagement(
from engagementKind: EngagementKind,
enqueueingEngagementKind: EngagementKind,
snackBarStyle: Theme.SnackBarStyle
) {
switch engagementKind {
case .chat, .messaging:
if enqueueingEngagementKind == .chat || enqueueingEngagementKind.isMessaging {
rootCoordinator?.maximize()
} else {
showSnackBar(
with: Localization.EntryWidget.CallVisualizer.description,
style: snackBarStyle
)
}
case .audioCall, .videoCall:
if enqueueingEngagementKind == .audioCall || enqueueingEngagementKind == .videoCall {
rootCoordinator?.maximize()
} else {
showSnackBar(
with: Localization.EntryWidget.CallVisualizer.description,
style: snackBarStyle
)
}
case .none:
break
}
}

/// The `EngagementParameters` encapsulates all parameters required to initiate or restore the coordinator
struct EngagementParameters {
let viewFactory: ViewFactory
Expand All @@ -281,7 +314,6 @@ extension Glia {
}
}


extension GliaCoreSDK.Engagement.Media {
var containsMediaDirection: Bool {
audio != nil || video != nil
Expand Down
13 changes: 1 addition & 12 deletions GliaWidgets/Sources/EntryWidget/EntryWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ private extension EntryWidget {
}

func resolveViewState(for interactorState: InteractorState) -> EntryWidget.ViewState? {
guard let engagementKind = interactorState.enqueiengEngagementKind else {
guard let engagementKind = interactorState.enqueueingEngagementKind else {
return nil
}

Expand Down Expand Up @@ -423,17 +423,6 @@ extension EntryWidget {
}
}

private extension InteractorState {
var enqueiengEngagementKind: EngagementKind? {
switch self {
case .enqueued(_, let engagementKind), .enqueueing(let engagementKind):
return engagementKind
case .none, .engaged, .ended:
return nil
}
}
}

// MARK: - UIViewControllerTransitioningDelegate
extension EntryWidget: UIViewControllerTransitioningDelegate {
public func presentationController(
Expand Down
9 changes: 9 additions & 0 deletions GliaWidgets/Sources/Interactor/Interactor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ enum InteractorState {
guard case .ended = self else { return false }
return true
}

var enqueueingEngagementKind: EngagementKind? {
switch self {
case .enqueued(_, let engagementKind), .enqueueing(let engagementKind):
return engagementKind
case .none, .engaged, .ended:
return nil
}
}
}

enum EndEngagementReason {
Expand Down
Loading

0 comments on commit bc70d0c

Please sign in to comment.