Skip to content

Commit

Permalink
Show Entry Widget on SC top banner click
Browse files Browse the repository at this point in the history
  • Loading branch information
ykyivskyi-gl authored and github-review-helper committed Nov 28, 2024
1 parent 6f4c3c5 commit ebb4d9a
Show file tree
Hide file tree
Showing 39 changed files with 593 additions and 210 deletions.
24 changes: 20 additions & 4 deletions GliaWidgets.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@
215A25932CA44D900013023E /* EngagementLauncher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 215A25912CA44D900013023E /* EngagementLauncher.swift */; };
215A25982CABC7DF0013023E /* EngagementLauncherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 215A25972CABC7DF0013023E /* EngagementLauncherTests.swift */; };
215A259A2CAC19780013023E /* GliaTests+EngagementLauncher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 215A25992CAC19780013023E /* GliaTests+EngagementLauncher.swift */; };
216D31032CEF83A90019CA9E /* EntryWidget.Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 216D31022CEF83A90019CA9E /* EntryWidget.Builder.swift */; };
216D31052CF4D3590019CA9E /* ChatView.DefineLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 216D31042CF4D3590019CA9E /* ChatView.DefineLayout.swift */; };
216D31072CF5DA050019CA9E /* ChatView.Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 216D31062CF5DA050019CA9E /* ChatView.Constants.swift */; };
216D31092CF5DC080019CA9E /* OverlayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 216D31082CF5DC080019CA9E /* OverlayView.swift */; };
2188DED22CECC3D400FA3BEF /* SecureMessagingTopBannerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2188DED12CECC3D400FA3BEF /* SecureMessagingTopBannerView.swift */; };
2188DED42CECE15800FA3BEF /* SecureMessagingTopBannerViewStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2188DED32CECE15800FA3BEF /* SecureMessagingTopBannerViewStyle.swift */; };
2188DEDD2CEE2C3F00FA3BEF /* SecureMessagingBottomBannerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2188DED92CEE2C3F00FA3BEF /* SecureMessagingBottomBannerView.swift */; };
Expand Down Expand Up @@ -995,7 +999,7 @@
C0F3DE452C6E3D7C00DE6D7B /* EntryWidgetStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0F3DE442C6E3D7C00DE6D7B /* EntryWidgetStyle.swift */; };
C0F3DE482C6E468400DE6D7B /* PoweredByView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0F3DE472C6E468400DE6D7B /* PoweredByView.swift */; };
C0F7EA382CA1D6D40038019C /* CustomPresentationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0F7EA372CA1D6D40038019C /* CustomPresentationController.swift */; };
C0F7EA3A2CA1D7050038019C /* EntryWidget.SizeConstraints.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0F7EA392CA1D7050038019C /* EntryWidget.SizeConstraints.swift */; };
C0F7EA3A2CA1D7050038019C /* EntryWidget.Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0F7EA392CA1D7050038019C /* EntryWidget.Configuration.swift */; };
C0F7EA3C2CA581E70038019C /* Glia+EntryWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0F7EA3B2CA581E70038019C /* Glia+EntryWidget.swift */; };
C4119E06268F41D1004DFEFB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C4119E05268F41D1004DFEFB /* Main.storyboard */; };
C42463742673ABE10082C135 /* ScreenShareHandler.Interface.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42463732673ABE10082C135 /* ScreenShareHandler.Interface.swift */; };
Expand Down Expand Up @@ -1256,6 +1260,10 @@
215A25912CA44D900013023E /* EngagementLauncher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EngagementLauncher.swift; sourceTree = "<group>"; };
215A25972CABC7DF0013023E /* EngagementLauncherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EngagementLauncherTests.swift; sourceTree = "<group>"; };
215A25992CAC19780013023E /* GliaTests+EngagementLauncher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GliaTests+EngagementLauncher.swift"; sourceTree = "<group>"; };
216D31022CEF83A90019CA9E /* EntryWidget.Builder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntryWidget.Builder.swift; sourceTree = "<group>"; };
216D31042CF4D3590019CA9E /* ChatView.DefineLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatView.DefineLayout.swift; sourceTree = "<group>"; };
216D31062CF5DA050019CA9E /* ChatView.Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatView.Constants.swift; sourceTree = "<group>"; };
216D31082CF5DC080019CA9E /* OverlayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverlayView.swift; sourceTree = "<group>"; };
2188DED12CECC3D400FA3BEF /* SecureMessagingTopBannerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecureMessagingTopBannerView.swift; sourceTree = "<group>"; };
2188DED32CECE15800FA3BEF /* SecureMessagingTopBannerViewStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureMessagingTopBannerViewStyle.swift; sourceTree = "<group>"; };
2188DED92CEE2C3F00FA3BEF /* SecureMessagingBottomBannerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecureMessagingBottomBannerView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2072,7 +2080,7 @@
C0F3DE442C6E3D7C00DE6D7B /* EntryWidgetStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntryWidgetStyle.swift; sourceTree = "<group>"; };
C0F3DE472C6E468400DE6D7B /* PoweredByView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PoweredByView.swift; sourceTree = "<group>"; };
C0F7EA372CA1D6D40038019C /* CustomPresentationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomPresentationController.swift; sourceTree = "<group>"; };
C0F7EA392CA1D7050038019C /* EntryWidget.SizeConstraints.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntryWidget.SizeConstraints.swift; sourceTree = "<group>"; };
C0F7EA392CA1D7050038019C /* EntryWidget.Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntryWidget.Configuration.swift; sourceTree = "<group>"; };
C0F7EA3B2CA581E70038019C /* Glia+EntryWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Glia+EntryWidget.swift"; sourceTree = "<group>"; };
C4119E05268F41D1004DFEFB /* Main.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
C42463732673ABE10082C135 /* ScreenShareHandler.Interface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenShareHandler.Interface.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2915,6 +2923,8 @@
1A60AFE725669C5000E53F53 /* ChatStyle.swift */,
C09047332B7E1DA6003C437C /* ChatStyle.RemoteConfig.swift */,
1A60AFDC25669A4200E53F53 /* ChatView.swift */,
216D31062CF5DA050019CA9E /* ChatView.Constants.swift */,
216D31042CF4D3590019CA9E /* ChatView.DefineLayout.swift */,
C0175A1C2A5D4226001FACDE /* ChatView.TableView.swift */,
8491AF202A7D1F7900CC3E72 /* ChatView.GvaGallery.swift */,
C0175A182A5D3C56001FACDE /* ChatView.Accessibility.swift */,
Expand Down Expand Up @@ -3123,6 +3133,7 @@
children = (
84681AA52A681E8400DD7406 /* LeftAlignedCollectionViewFlowLayout */,
84681AA42A681E6900DD7406 /* SelfSizingCollectionView */,
216D31082CF5DC080019CA9E /* OverlayView.swift */,
);
path = Common;
sourceTree = "<group>";
Expand Down Expand Up @@ -5197,11 +5208,12 @@
isa = PBXGroup;
children = (
C0F7EA372CA1D6D40038019C /* CustomPresentationController.swift */,
216D31022CEF83A90019CA9E /* EntryWidget.Builder.swift */,
C0F3DE362C69F51D00DE6D7B /* EntryWidget.swift */,
2100B47B2CB66B6500AC7527 /* EntryWidget.Environment.swift */,
C0F3DE3E2C6E176A00DE6D7B /* EntryWidget.MediaTypeItem.swift */,
C0F3DE382C69FC2100DE6D7B /* EntryWidget.Presentation.swift */,
C0F7EA392CA1D7050038019C /* EntryWidget.SizeConstraints.swift */,
C0F7EA392CA1D7050038019C /* EntryWidget.Configuration.swift */,
C0F3DE442C6E3D7C00DE6D7B /* EntryWidgetStyle.swift */,
C034EEEC2CAAB525002650B8 /* EntryWidgetStyle.RemoteConfig.swift */,
C0F3DE3A2C6E0DD900DE6D7B /* EntryWidgetView.swift */,
Expand Down Expand Up @@ -6012,7 +6024,7 @@
C0D6CA632C19C59100D4709B /* Glia.OpaqueAuthentication.Environment.swift in Sources */,
7594095A298D386F008B173A /* NSLayoutConstraint+Extensions.swift in Sources */,
C07F62462ABC322B003EFC97 /* OrientationManager.Mock.swift in Sources */,
C0F7EA3A2CA1D7050038019C /* EntryWidget.SizeConstraints.swift in Sources */,
C0F7EA3A2CA1D7050038019C /* EntryWidget.Configuration.swift in Sources */,
C0D2F06829A4B71C00803B47 /* VideoCallViewModel.Mock.swift in Sources */,
AFEF5C6F29928DB0005C3D8D /* SecureConversations.FileUploadView.swift in Sources */,
C0D6CA092C18451800D4709B /* CallViewController.Environment.swift in Sources */,
Expand Down Expand Up @@ -6076,6 +6088,7 @@
C43C12F92694B14900C37E1B /* GliaPresenter.swift in Sources */,
AFF4412D2CD572AE0088B1C5 /* ChatMessageEntryView.StateStyle.swift in Sources */,
1A0452F025DBE268000DA0C1 /* MessageButtonStateStyle.swift in Sources */,
216D31052CF4D3590019CA9E /* ChatView.DefineLayout.swift in Sources */,
EB2CBB1227D89F7D004F178E /* OnHoldOverlayStyle.swift in Sources */,
C09047482B7E20B0003C437C /* FileUploadStateStyle.Mock.swift in Sources */,
75940983298D38C2008B173A /* VisitorCodeViewModel+Delegate.swift in Sources */,
Expand Down Expand Up @@ -6155,6 +6168,7 @@
3197F7B629F7C2E5008EE9F7 /* SecureConversations.SecureChatModel.swift in Sources */,
1A0C9A7125C16F4A00815406 /* Theme+Alert.swift in Sources */,
1A38A8AC258B65D00089DE7B /* ChatMessageStyle.swift in Sources */,
216D31072CF5DA050019CA9E /* ChatView.Constants.swift in Sources */,
C0175A282A67D470001FACDE /* GvaPersistentButtonStyle.swift in Sources */,
C49A29F22614A85E00819269 /* ChoiceCard.swift in Sources */,
1A0C9A6D25C16EED00815406 /* Theme+Call.swift in Sources */,
Expand All @@ -6163,6 +6177,7 @@
845E2F9B283FCA9000C04D56 /* Theme.Survey.Checkbox.swift in Sources */,
C0D2F07F29A4E59200803B47 /* CallButtonBarStyle.Mock.swift in Sources */,
755D187F29A6B1B90009F5E8 /* Glia+EngagementSetup.swift in Sources */,
216D31092CF5DC080019CA9E /* OverlayView.swift in Sources */,
C09046712B7CFE11003C437C /* ConfirmationStyle.TitleStyle.Accessibility.swift in Sources */,
C09047252B7E1BBA003C437C /* GvaGalleryCardStyle.ViewStyle.swift in Sources */,
1A60B0192567FC8A00E53F53 /* ButtonKind.swift in Sources */,
Expand All @@ -6171,6 +6186,7 @@
3100EEFD293F757E00D57F71 /* SecureConversations.WelcomeStyle.swift in Sources */,
C09046F02B7E0F78003C437C /* Theme.OperatorChatMessageStyle.RemoteConfig.swift in Sources */,
755D187729A6A6D70009F5E8 /* WelcomeStyle.MessageWarningStyle.swift in Sources */,
216D31032CEF83A90019CA9E /* EntryWidget.Builder.swift in Sources */,
C0D2F0412992585A00803B47 /* VideoCallView.ConnectView.swift in Sources */,
1A56D53D257E24A400141BC8 /* PoweredBy.swift in Sources */,
C0D6CA392C19A57200D4709B /* ChatMessageEntryView.Environment.swift in Sources */,
Expand Down
11 changes: 10 additions & 1 deletion GliaWidgets/Public/Glia/Glia+EngagementSetup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,16 @@ extension Glia {
maximumUploads: { self.maximumUploads },
viewFactory: viewFactory,
alertManager: alertManager,
queuesMonitor: queuesMonitor
queuesMonitor: queuesMonitor,
createEntryWidget: { [weak self] configuration in
guard let self else {
throw GliaError.internalError
}
return try self.getEntryWidget(
queueIds: interactor.queueIds ?? [],
configuration: configuration
)
}
)
)
rootCoordinator?.delegate = { [weak self] event in self?.handleCoordinatorEvent(event) }
Expand Down
5 changes: 5 additions & 0 deletions GliaWidgets/Public/Glia/Glia+EntryWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ extension Glia {
/// - Returns:
/// - `EntryWidget` instance.
public func getEntryWidget(queueIds: [String]) throws -> EntryWidget {
try getEntryWidget(queueIds: queueIds, configuration: .default)
}

func getEntryWidget(queueIds: [String], configuration: EntryWidget.Configuration) throws -> EntryWidget {
EntryWidget(
queueIds: queueIds,
configuration: configuration,
environment: .init(
observeSecureUnreadMessageCount: environment.coreSdk.subscribeForUnreadSCMessageCount,
unsubscribeFromUpdates: environment.coreSdk.unsubscribeFromUpdates,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import Combine

extension SecureConversations.ChatWithTranscriptModel {
typealias Action = Chat.Action
Expand Down Expand Up @@ -87,6 +88,16 @@ extension SecureConversations.ChatWithTranscriptModel {
}
}

// TODO: Unit test to be added in MOB-3840
var entryWidget: EntryWidget? {
switch self {
case .chat:
return nil
case let .transcript(model):
return model.entryWidget
}
}

func event(_ event: Event) {
switch self {
case let .chat(model):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ extension SecureConversations.TranscriptModel {
var maximumUploads: () -> Int
var shouldShowLeaveSecureConversationDialog: Bool
var leaveCurrentSecureConversation: Cmd
var createEntryWidget: EntryWidgetBuilder
var switchToEngagement: Command<EngagementKind>
}
}

Expand Down Expand Up @@ -73,7 +75,9 @@ extension SecureConversations.TranscriptModel.Environment {
log: environment.log,
maximumUploads: environment.maximumUploads,
shouldShowLeaveSecureConversationDialog: environment.shouldShowLeaveSecureConversationDialog,
leaveCurrentSecureConversation: environment.leaveCurrentSecureConversation
leaveCurrentSecureConversation: environment.leaveCurrentSecureConversation,
createEntryWidget: environment.createEntryWidget,
switchToEngagement: environment.switchToEngagement
)
}
}
Expand Down Expand Up @@ -111,7 +115,9 @@ extension SecureConversations.TranscriptModel.Environment {
log: CoreSdkClient.Logger = .mock,
maximumUploads: @escaping () -> Int = { .zero },
shouldShowLeaveSecureConversationDialog: Bool = false,
leaveCurrentSecureConversation: Cmd = .nop
leaveCurrentSecureConversation: Cmd = .nop,
createEntryWidget: @escaping EntryWidgetBuilder = { _ in .mock() },
switchToEngagement: Command<EngagementKind> = .nop
) -> Self {
Self(
fetchFile: fetchFile,
Expand Down Expand Up @@ -144,7 +150,9 @@ extension SecureConversations.TranscriptModel.Environment {
log: log,
maximumUploads: maximumUploads,
shouldShowLeaveSecureConversationDialog: shouldShowLeaveSecureConversationDialog,
leaveCurrentSecureConversation: leaveCurrentSecureConversation
leaveCurrentSecureConversation: leaveCurrentSecureConversation,
createEntryWidget: createEntryWidget,
switchToEngagement: switchToEngagement
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ extension SecureConversations {
var environment: Environment
var availability: Availability
var interactor: Interactor
var entryWidget: EntryWidget?

private(set) var isSecureConversationsAvailable: Bool = true {
didSet {
Expand Down Expand Up @@ -97,7 +98,6 @@ extension SecureConversations {
self.isCustomCardSupported = isCustomCardSupported
self.environment = environment
self.downloader = FileDownloader(environment: .create(with: environment))

self.availability = availability
self.deliveredStatusText = deliveredStatusText
self.failedToDeliverStatusText = failedToDeliverStatusText
Expand All @@ -117,6 +117,13 @@ extension SecureConversations {
)

self.transcriptMessageLoader = .init(environment: .create(with: environment))
do {
self.entryWidget = try environment.createEntryWidget(makeEntryWidgetConfiguration())
} catch {
// Creating an entry widget may fail if the SDK is not configured.
// This assumes that the SDK is configured by accessing Secure Conversations.
environment.log.warning("Could not create EntryWidget on Secure Conversation")
}

self.fileUploadListModel.delegate = { [weak self] event in
switch event {
Expand Down Expand Up @@ -735,6 +742,47 @@ extension SecureConversations.TranscriptModel {
}
}

// MARK: Entry Widget
extension SecureConversations.TranscriptModel {
// Set up the Entry Widget configuration inside TranscriptModel,
// since it requires passing view model logic to the configuration.
private func makeEntryWidgetConfiguration() -> EntryWidget.Configuration {
.init(
sizeConstraints: .init(
singleCellHeight: 56,
singleCellIconSize: 24,
poweredByContainerHeight: 40,
sheetHeaderHeight: 36,
sheetHeaderDraggerWidth: 32,
sheetHeaderDraggerHeight: 4,
dividerHeight: 1,
dividerHorizontalPadding: 0
),
showPoweredBy: false,
filterSecureConversation: true,
mediaTypeSelected: .init(closure: entryWidgetMediaTypeSelected)
)
}

private func entryWidgetMediaTypeSelected(_ item: EntryWidget.MediaTypeItem) {
action?(.switchToEngagement)
engagementAction?(.showAlert(.leaveCurrentConversation { [weak self] in
let kind: EngagementKind
switch item.type {
case .video:
kind = .videoCall
case .audio:
kind = .audioCall
case .chat:
kind = .chat
case .secureMessaging:
kind = .messaging(.welcome)
}
self?.environment.switchToEngagement(kind)
}))
}
}

#if DEBUG
extension SecureConversations.TranscriptModel {
/// Setter for `isSecureConversationsAvailable`. Used in unit tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ extension SecureConversations.Coordinator {
var flipCameraButtonStyle: FlipCameraButtonStyle
var alertManager: AlertManager
var queuesMonitor: QueuesMonitor
var createEntryWidget: EntryWidgetBuilder
var shouldShowLeaveSecureConversationDialog: Bool
var leaveCurrentSecureConversation: Cmd
var switchToEngagement: Command<EngagementKind>
}
}

Expand All @@ -67,7 +69,8 @@ extension SecureConversations.Coordinator.Environment {
isWindowVisible: ObservableValue<Bool>,
interactor: Interactor,
shouldShowLeaveSecureConversationDialog: Bool,
leaveCurrentSecureConversation: Cmd
leaveCurrentSecureConversation: Cmd,
switchToEngagement: Command<EngagementKind>
) -> Self {
.init(
queueIds: queueIds,
Expand Down Expand Up @@ -118,8 +121,10 @@ extension SecureConversations.Coordinator.Environment {
flipCameraButtonStyle: environment.flipCameraButtonStyle,
alertManager: environment.alertManager,
queuesMonitor: environment.queuesMonitor,
createEntryWidget: environment.createEntryWidget,
shouldShowLeaveSecureConversationDialog: shouldShowLeaveSecureConversationDialog,
leaveCurrentSecureConversation: leaveCurrentSecureConversation
leaveCurrentSecureConversation: leaveCurrentSecureConversation,
switchToEngagement: switchToEngagement
)
}
}
Loading

0 comments on commit ebb4d9a

Please sign in to comment.