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 Demo App Refresh Tokens + Connection Banner #3313

Merged
merged 5 commits into from
Jul 18, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ struct DemoAppConfig {
var isLocationAttachmentsEnabled: Bool
/// Set this value to define if we should mimic token refresh scenarios.
var tokenRefreshDetails: TokenRefreshDetails?
/// A Boolean value that determines if a connection banner UI should be shown.
var shouldShowConnectionBanner: Bool

/// The details to generate expirable tokens in the demo app.
struct TokenRefreshDetails {
Expand Down Expand Up @@ -48,7 +50,8 @@ class AppConfig {
isMessageDebuggerEnabled: false,
isChannelPinningEnabled: false,
isLocationAttachmentsEnabled: false,
tokenRefreshDetails: nil
tokenRefreshDetails: nil,
shouldShowConnectionBanner: false
)

if StreamRuntimeCheck.isStreamInternalConfiguration {
Expand All @@ -57,6 +60,7 @@ class AppConfig {
demoAppConfig.isLocationAttachmentsEnabled = true
demoAppConfig.isLocationAttachmentsEnabled = true
demoAppConfig.isHardDeleteEnabled = true
demoAppConfig.shouldShowConnectionBanner = true
StreamRuntimeCheck.assertionsEnabled = true
}
}
Expand Down Expand Up @@ -165,6 +169,7 @@ class AppConfigViewController: UITableViewController {
case isChannelPinningEnabled
case isLocationAttachmentsEnabled
case tokenRefreshDetails
case shouldShowConnectionBanner
}

enum ComponentsConfigOption: String, CaseIterable {
Expand Down Expand Up @@ -315,6 +320,10 @@ class AppConfigViewController: UITableViewController {
cell.detailTextLabel?.text = "Disabled"
}
cell.accessoryType = .none
case .shouldShowConnectionBanner:
cell.accessoryView = makeSwitchButton(demoAppConfig.shouldShowConnectionBanner) { [weak self] newValue in
self?.demoAppConfig.shouldShowConnectionBanner = newValue
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions DemoApp/Shared/Token+Development.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension StreamChatWrapper {
{ completion in
// Simulate API call delay
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
var generatedToken: Token? = _generateUserToken(
let generatedToken: Token? = _generateUserToken(
secret: refreshDetails.appSecret,
userID: initialToken.userId,
expirationDate: Date().addingTimeInterval(refreshDetails.duration)
Expand All @@ -26,7 +26,7 @@ extension StreamChatWrapper {

let numberOfSuccessfulRefreshes = refreshDetails.numberOfSuccessfulRefreshesBeforeFailing
let shouldNotFail = numberOfSuccessfulRefreshes == 0
if shouldNotFail || self.numberOfRefreshTokens <= numberOfSuccessfulRefreshes {
if shouldNotFail || self.numberOfRefreshTokens >= numberOfSuccessfulRefreshes {
print("Demo App Token Refreshing: New token generated successfully.")
let newToken = generatedToken ?? initialToken
completion(.success(newToken))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ extension BannerShowingConnectionDelegate: ChatConnectionControllerDelegate {
bannerView.update(text: "Disconnected")
showBanner()
case .connected:
bannerView.update(text: "Connected")
hideBanner()
case .disconnecting:
bannerView.update(text: "Disconnecting...")
showBanner()
case .connecting:
bannerView.update(text: "Connecting...")
showBanner()
case .initialized:
break
}
Expand All @@ -45,7 +48,7 @@ extension BannerShowingConnectionDelegate: ChatConnectionControllerDelegate {
private extension BannerShowingConnectionDelegate {
func setupViews() {
attachToTopViewIfNeeded()
bannerView.alpha = 0
bannerView.alpha = 1
bannerView.update(text: "Connecting...")
}

Expand Down
4 changes: 3 additions & 1 deletion DemoApp/StreamChat/Components/DemoChatChannelListVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ final class DemoChatChannelListVC: ChatChannelListVC {

initialQuery = controller.query

connectionController.delegate = connectionDelegate
if AppConfig.shared.demoAppConfig.shouldShowConnectionBanner {
connectionController.delegate = connectionDelegate
}

navigationItem.rightBarButtonItems = [
UIBarButtonItem(customView: filterChannelsButton),
Expand Down
Loading