Skip to content

Commit

Permalink
Fix media upgrade dialog configuration
Browse files Browse the repository at this point in the history
After adding AlertManager class configuring alert dialogs was broken. As a result for Audio, 1-way Video, 2-way Video offers the SDK always showed 2-way Video media upgrade dialog. That was only UI configuration issue, accepting the offer resulted in establishing right media type. This commit fixes alert configuration issue.

MOB-3768
  • Loading branch information
Egor Egorov authored and EgorovEI committed Nov 8, 2024
1 parent 8a9e7ab commit 60eac36
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 16 deletions.
4 changes: 4 additions & 0 deletions GliaWidgets.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@
847956362AD96AD7004EF60C /* CoreSDKConfigurator.Interface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847956352AD96AD7004EF60C /* CoreSDKConfigurator.Interface.swift */; };
847956402ADED7A2004EF60C /* CallVisualizer.Action.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8479563F2ADED7A2004EF60C /* CallVisualizer.Action.swift */; };
847A7643285A1914004044D1 /* FileUploadListViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847A7642285A1914004044D1 /* FileUploadListViewModelTests.swift */; };
847D7FAE2CDE0F3A00EA5C2D /* AlertTypeComposerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847D7FAD2CDE0F3A00EA5C2D /* AlertTypeComposerTests.swift */; };
8485704F2BEE3A0800CEBCC5 /* ChatViewTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8485704E2BEE3A0800CEBCC5 /* ChatViewTest.swift */; };
848570512BEE3CCC00CEBCC5 /* ChatStyle.Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848570502BEE3CCC00CEBCC5 /* ChatStyle.Mock.swift */; };
848B8ADC2C0759C500E990E6 /* Theme.CustomCardContainerStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848B8ADB2C0759C500E990E6 /* Theme.CustomCardContainerStyle.swift */; };
Expand Down Expand Up @@ -1427,6 +1428,7 @@
847956352AD96AD7004EF60C /* CoreSDKConfigurator.Interface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreSDKConfigurator.Interface.swift; sourceTree = "<group>"; };
8479563F2ADED7A2004EF60C /* CallVisualizer.Action.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallVisualizer.Action.swift; sourceTree = "<group>"; };
847A7642285A1914004044D1 /* FileUploadListViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUploadListViewModelTests.swift; sourceTree = "<group>"; };
847D7FAD2CDE0F3A00EA5C2D /* AlertTypeComposerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertTypeComposerTests.swift; sourceTree = "<group>"; };
8485704E2BEE3A0800CEBCC5 /* ChatViewTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatViewTest.swift; sourceTree = "<group>"; };
848570502BEE3CCC00CEBCC5 /* ChatStyle.Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatStyle.Mock.swift; sourceTree = "<group>"; };
848B8ADB2C0759C500E990E6 /* Theme.CustomCardContainerStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.CustomCardContainerStyle.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4913,6 +4915,7 @@
isa = PBXGroup;
children = (
C0D6C9FF2C106A1F00D4709B /* AlertManager.Failing.swift */,
847D7FAD2CDE0F3A00EA5C2D /* AlertTypeComposerTests.swift */,
);
path = AlertManager;
sourceTree = "<group>";
Expand Down Expand Up @@ -6336,6 +6339,7 @@
9A1992E127D6313500161AAE /* ImageView.Cache.Failing.swift in Sources */,
3189DD9629E4331200D68E9F /* SecureConversations.WelcomeViewModel.Mock.swift in Sources */,
31D286AF2A00DE2B009192A6 /* SecureConversations.ConfirmationViewModel.Mock.swift in Sources */,
847D7FAE2CDE0F3A00EA5C2D /* AlertTypeComposerTests.swift in Sources */,
31B278012B55903C0021DEC1 /* SecureConversations.Coordinator.Environment.Mock.swift in Sources */,
C0D2F06429A4B1E900803B47 /* VideoCallTests.swift in Sources */,
31FF0DCF2B5A88F500834AFB /* CallCoordinatorTests.swift in Sources */,
Expand Down
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit

/// Style of the media upgrade action in a multiple media type alert window.
public struct MediaUpgradeActionStyle {
public struct MediaUpgradeActionStyle: Equatable {
/// Title of the media upgrade action. Displayed to the left of the icon, at the top of the view.
public var title: String

Expand Down
2 changes: 1 addition & 1 deletion GliaWidgets/Sources/Theme/Alert/AlertConfiguration.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Configurations for alerts and confirmations.
public struct AlertConfiguration {
public struct AlertConfiguration: Equatable {
/// Configuration of the queue leaving confirmation alert.
public var leaveQueue: ConfirmationAlertConfiguration

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

/// Configuration of the confirmation alert.
public struct ConfirmationAlertConfiguration {
public struct ConfirmationAlertConfiguration: Equatable {
/// Title of the alert.
public var title: String?

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Configuration of a generic alert.
public struct MessageAlertConfiguration {
public struct MessageAlertConfiguration: Equatable {
/// Title of the alert.
public var title: String?

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

/// Configuration of the media upgrade confirmation alert.
public struct MultipleMediaUpgradeAlertConfiguration {
public struct MultipleMediaUpgradeAlertConfiguration: Equatable {
/// Title of the alert.
public var title: String

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit

/// Configuration of the screen sharing confirmation alert.
public struct ScreenShareOfferAlertConfiguration {
public struct ScreenShareOfferAlertConfiguration: Equatable {
/// Title of the alert.
public var title: String

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

/// Configuration of the alert that offers to go to the app's settings in the Settings app.
public struct SettingsAlertConfiguration {
public struct SettingsAlertConfiguration: Equatable {
/// Title of the alert.
public var title: String

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

/// Configuration of the operator ending the engagement alert.
public struct SingleActionAlertConfiguration {
public struct SingleActionAlertConfiguration: Equatable {
/// Title of the alert.
public var title: String?

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit

/// Configuration of the media upgrade confirmation alert.
public struct SingleMediaUpgradeAlertConfiguration {
public struct SingleMediaUpgradeAlertConfiguration: Equatable {
/// Title of the alert.
public var title: String

Expand Down
79 changes: 79 additions & 0 deletions GliaWidgetsTests/Sources/AlertManager/AlertTypeComposerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
@testable import GliaWidgets
import UIKit
import XCTest

final class AlertTypeComposerTests: XCTestCase {
var composer: AlertManager.AlertTypeComposer!

override func setUp() {
super.setUp()

composer = .init(
environment: .create(with: .mock()),
theme: .mock()
)
}

func testComposeAlertWithAudioMediaUpgradeInput() throws {
let operatorName = "Mock"
let offer = try CoreSdkClient.MediaUpgradeOffer(type: .audio, direction: .twoWay)
let input: AlertInputType = .mediaUpgrade(
operators: operatorName,
offer: offer,
accepted: nil,
declined: nil,
answer: { _, _ in }
)
let alertType = try composer.composeAlert(input: input)

switch alertType {
case let .singleMediaUpgrade(configuration, _, _):
let expected = Theme().alertConfiguration.audioUpgrade.withOperatorName(operatorName)
XCTAssertEqual(configuration, expected)
default:
XCTFail("alertType should be singleMediaUpgrade")
}
}

func testComposeAlertWithOneWayVideoMediaUpgradeInput() throws {
let operatorName = "Mock"
let offer = try CoreSdkClient.MediaUpgradeOffer(type: .video, direction: .oneWay)
let input: AlertInputType = .mediaUpgrade(
operators: operatorName,
offer: offer,
accepted: nil,
declined: nil,
answer: { _, _ in }
)
let alertType = try composer.composeAlert(input: input)

switch alertType {
case let .singleMediaUpgrade(configuration, _, _):
let expected = Theme().alertConfiguration.oneWayVideoUpgrade.withOperatorName(operatorName)
XCTAssertEqual(configuration, expected)
default:
XCTFail("alertType should be singleMediaUpgrade")
}
}

func testComposeAlertWithTwoWayVideoMediaUpgradeInput() throws {
let operatorName = "Mock"
let offer = try CoreSdkClient.MediaUpgradeOffer(type: .video, direction: .twoWay)
let input: AlertInputType = .mediaUpgrade(
operators: operatorName,
offer: offer,
accepted: nil,
declined: nil,
answer: { _, _ in }
)
let alertType = try composer.composeAlert(input: input)

switch alertType {
case let .singleMediaUpgrade(configuration, _, _):
let expected = Theme().alertConfiguration.twoWayVideoUpgrade.withOperatorName(operatorName)
XCTAssertEqual(configuration, expected)
default:
XCTFail("alertType should be singleMediaUpgrade")
}
}
}

0 comments on commit 60eac36

Please sign in to comment.