Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix media upgrade dialog configuration #1108

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions GliaWidgets/Sources/AlertManager/AlertManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ extension AlertManager {
in placement: AlertPlacement,
as input: AlertInputType
) {
guard input != currentAlert else { return }
let alertType = composer.composeAlert(input: input)
guard input != currentAlert, let alertType = try? composer.composeAlert(input: input) else { return }

switch placement {
case .global:
Expand Down
16 changes: 11 additions & 5 deletions GliaWidgets/Sources/AlertManager/AlertTypeComposer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension AlertManager.AlertTypeComposer {
///
func composeAlert(
input: AlertInputType
) -> AlertType {
) throws -> AlertType {
switch input {
case let .mediaSourceNotAvailable(dismissed):
return mediaTypeNotAvailableAlertType(dismissed: dismissed)
Expand Down Expand Up @@ -65,7 +65,7 @@ extension AlertManager.AlertTypeComposer {
case let .endEngagement(confirmed):
return endEngagementAlertType(confirmed: confirmed)
case let .mediaUpgrade(operators, offer, accepted, declined, answer):
return mediaUpgradeOfferAlertType(
return try mediaUpgradeOfferAlertType(
operators: operators,
offer: offer,
accepted: accepted,
Expand Down Expand Up @@ -267,7 +267,7 @@ private extension AlertManager.AlertTypeComposer {
accepted: (() -> Void)? = nil,
declined: (() -> Void)? = nil,
answer: @escaping CoreSdkClient.AnswerWithSuccessBlock
) -> AlertType {
) throws -> AlertType {
let acceptedOffer: () -> Void = {
self.environment.log.prefixed(Self.self).info("Upgrade offer accepted by visitor")
accepted?()
Expand All @@ -280,22 +280,28 @@ private extension AlertManager.AlertTypeComposer {
answer(false, nil)
}

let configuration: SingleMediaUpgradeAlertConfiguration

switch offer.type {
case .audio:
environment.log.prefixed(Self.self).info("Audio upgrade requested")
environment.log.prefixed(Self.self).info("Show Upgrade Audio Dialog")
configuration = theme.alertConfiguration.audioUpgrade.withOperatorName(operators)
case .video where offer.direction == .oneWay:
environment.log.prefixed(Self.self).info("1 way video upgrade requested")
environment.log.prefixed(Self.self).info("Show Upgrade 1WayVideo Dialog")
configuration = theme.alertConfiguration.oneWayVideoUpgrade.withOperatorName(operators)
case .video where offer.direction == .twoWay:
environment.log.prefixed(Self.self).info("2 way video upgrade requested")
environment.log.prefixed(Self.self).info("Show Upgrade 2WayVideo Dialog")
configuration = theme.alertConfiguration.twoWayVideoUpgrade.withOperatorName(operators)
default:
break
environment.log.prefixed(Self.self).warning("Unsupported media upgrade offer type requested")
throw GliaError.internalError
}

return .singleMediaUpgrade(
theme.alertConfiguration.twoWayVideoUpgrade.withOperatorName(operators),
configuration,
accepted: acceptedOffer,
declined: declinedOffer
)
Expand Down
Loading