Skip to content
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
2 changes: 1 addition & 1 deletion DemoApp/Screens/DemoReminderListVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ extension DemoReminderListVC: MessageReminderListControllerDelegate, EventsContr
updateRemindersData()
}

func eventsController(_ controller: EventsController, didReceiveEvent event: any StreamChat.Event) {
func eventsController(_ controller: EventsController, didReceiveEvent event: any Event) {
if event is MessageReminderDueEvent {
updateReminderListsWithNewNowDate()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class DemoLivestreamChatChannelVC: _ViewController,
messageListVC.scrollToBottomButton.content = .init(messages: skippedMessagesAmount, mentions: 0)
}

func eventsController(_ controller: EventsController, didReceiveEvent event: any StreamChat.Event) {
func eventsController(_ controller: EventsController, didReceiveEvent event: any Event) {
if event is NewMessagePendingEvent {
if livestreamChannelController.isPaused {
pauseBannerView.setState(.resuming)
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", exact: "1.0.0"),
.package(url: "https://github.com/GetStream/stream-core-swift.git", branch: "chat-concurrency-and-timers")
.package(url: "https://github.com/GetStream/stream-core-swift.git", exact: "0.5.0")
],
targets: [
.target(
Expand Down
6 changes: 3 additions & 3 deletions Sources/StreamChat/APIClient/RequestDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ struct DefaultRequestDecoder: RequestDecoder {
log.debug("URL request response: \(httpResponse), data:\n\(data.debugPrettyPrintedJSON))", subsystems: .httpRequests)

guard httpResponse.statusCode < 300 else {
let serverError: ErrorPayload
let serverError: APIError
do {
serverError = try JSONDecoder.default.decode(ErrorPayload.self, from: data)
serverError = try JSONDecoder.default.decode(APIError.self, from: data)
} catch {
log
.error(
Expand All @@ -58,7 +58,7 @@ struct DefaultRequestDecoder: RequestDecoder {
throw ClientError.Unknown("Unknown error. Server response: \(httpResponse).")
}

if serverError.isExpiredTokenError {
if serverError.isTokenExpiredError {
log.info("Request failed because of an expired token.", subsystems: .httpRequests)
throw ClientError.ExpiredToken()
}
Expand Down
1 change: 0 additions & 1 deletion Sources/StreamChat/APIClient/RequestEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ protocol ConnectionDetailsProviderDelegate: AnyObject {
}

public extension ClientError {
final class InvalidURL: ClientError, @unchecked Sendable {}
final class InvalidJSON: ClientError, @unchecked Sendable {}
final class MissingConnectionId: ClientError, @unchecked Sendable {}
}
33 changes: 18 additions & 15 deletions Sources/StreamChat/ChatClient+Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ extension ChatClient {

var webSocketClientBuilder: (@Sendable (
_ sessionConfiguration: URLSessionConfiguration,
_ requestEncoder: RequestEncoder,
_ eventDecoder: AnyEventDecoder,
_ notificationCenter: EventNotificationCenter
_ notificationCenter: PersistentEventNotificationCenter
) -> WebSocketClient)? = {
WebSocketClient(
let wsEnvironment = WebSocketClient.Environment(eventBatchingPeriod: 0.5)
return WebSocketClient(
sessionConfiguration: $0,
requestEncoder: $1,
eventDecoder: $2,
eventNotificationCenter: $3
eventDecoder: $1,
eventNotificationCenter: $2,
webSocketClientType: .coordinator,
environment: wsEnvironment,
connectRequest: nil,
healthCheckBeforeConnected: true
)
}

Expand All @@ -57,7 +60,7 @@ extension ChatClient {

var eventDecoderBuilder: @Sendable () -> EventDecoder = { EventDecoder() }

var notificationCenterBuilder: @Sendable (_ database: DatabaseContainer, _ manualEventHandler: ManualEventHandler?) -> EventNotificationCenter = { EventNotificationCenter(database: $0, manualEventHandler: $1) }
var notificationCenterBuilder: @Sendable (_ database: DatabaseContainer, _ manualEventHandler: ManualEventHandler?) -> PersistentEventNotificationCenter = { PersistentEventNotificationCenter(database: $0, manualEventHandler: $1) }

var internetConnection: @Sendable (_ center: NotificationCenter, _ monitor: InternetConnectionMonitor) -> InternetConnection = {
InternetConnection(notificationCenter: $0, monitor: $1)
Expand All @@ -76,16 +79,18 @@ extension ChatClient {
var connectionRepositoryBuilder: @Sendable (
_ isClientInActiveMode: Bool,
_ syncRepository: SyncRepository,
_ webSocketEncoder: RequestEncoder?,
_ webSocketClient: WebSocketClient?,
_ apiClient: APIClient,
_ timerType: TimerScheduling.Type
) -> ConnectionRepository = {
ConnectionRepository(
isClientInActiveMode: $0,
syncRepository: $1,
webSocketClient: $2,
apiClient: $3,
timerType: $4
webSocketEncoder: $2,
webSocketClient: $3,
apiClient: $4,
timerType: $5
)
}

Expand All @@ -110,20 +115,18 @@ extension ChatClient {
var connectionRecoveryHandlerBuilder: @Sendable (
_ webSocketClient: WebSocketClient,
_ eventNotificationCenter: EventNotificationCenter,
_ syncRepository: SyncRepository,
_ backgroundTaskScheduler: BackgroundTaskScheduler?,
_ internetConnection: InternetConnection,
_ keepConnectionAliveInBackground: Bool
) -> ConnectionRecoveryHandler = {
DefaultConnectionRecoveryHandler(
webSocketClient: $0,
eventNotificationCenter: $1,
syncRepository: $2,
backgroundTaskScheduler: $3,
internetConnection: $4,
backgroundTaskScheduler: $2,
internetConnection: $3,
reconnectionStrategy: DefaultRetryStrategy(),
reconnectionTimerType: DefaultTimer.self,
keepConnectionAliveInBackground: $5
keepConnectionAliveInBackground: $4
)
}

Expand Down
9 changes: 5 additions & 4 deletions Sources/StreamChat/ChatClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ChatClient: @unchecked Sendable {
private(set) var connectionRecoveryHandler: ConnectionRecoveryHandler?

/// The notification center used to send and receive notifications about incoming events.
private(set) var eventNotificationCenter: EventNotificationCenter
private(set) var eventNotificationCenter: PersistentEventNotificationCenter

/// The registry that contains all the attachment payloads associated with their attachment types.
/// For the meantime this is a static property to avoid breaking changes. On v5, this can be changed.
Expand Down Expand Up @@ -99,6 +99,7 @@ public class ChatClient: @unchecked Sendable {

/// The `WebSocketClient` instance `Client` uses to communicate with Stream WS servers.
let webSocketClient: WebSocketClient?
let webSocketEncoder: RequestEncoder?

/// The `DatabaseContainer` instance `Client` uses to store and cache data.
let databaseContainer: DatabaseContainer
Expand Down Expand Up @@ -184,13 +185,13 @@ public class ChatClient: @unchecked Sendable {
channelListUpdater
)
let webSocketClient = factory.makeWebSocketClient(
requestEncoder: webSocketEncoder,
urlSessionConfiguration: urlSessionConfiguration,
eventNotificationCenter: eventNotificationCenter
)
let connectionRepository = environment.connectionRepositoryBuilder(
config.isClientInActiveMode,
syncRepository,
webSocketEncoder,
webSocketClient,
apiClient,
environment.timerType
Expand All @@ -207,6 +208,7 @@ public class ChatClient: @unchecked Sendable {
self.databaseContainer = databaseContainer
self.apiClient = apiClient
self.webSocketClient = webSocketClient
self.webSocketEncoder = webSocketEncoder
self.eventNotificationCenter = eventNotificationCenter
self.offlineRequestsRepository = offlineRequestsRepository
self.connectionRepository = connectionRepository
Expand Down Expand Up @@ -268,7 +270,6 @@ public class ChatClient: @unchecked Sendable {
connectionRecoveryHandler = environment.connectionRecoveryHandlerBuilder(
webSocketClient,
eventNotificationCenter,
syncRepository,
environment.backgroundTaskSchedulerBuilder(),
environment.internetConnection(eventNotificationCenter, environment.internetMonitor),
config.staysConnectedInBackground
Expand Down Expand Up @@ -718,7 +719,7 @@ extension ChatClient: AuthenticationRepositoryDelegate {
}

extension ChatClient: ConnectionStateDelegate {
func webSocketClient(_ client: WebSocketClient, didUpdateConnectionState state: WebSocketConnectionState) {
public func webSocketClient(_ client: WebSocketClient, didUpdateConnectionState state: WebSocketConnectionState) {
connectionRepository.handleConnectionUpdate(
state: state,
onExpiredToken: { [weak self] in
Expand Down
6 changes: 2 additions & 4 deletions Sources/StreamChat/ChatClientFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@ class ChatClientFactory {
}

func makeWebSocketClient(
requestEncoder: RequestEncoder,
urlSessionConfiguration: URLSessionConfiguration,
eventNotificationCenter: EventNotificationCenter
eventNotificationCenter: PersistentEventNotificationCenter
) -> WebSocketClient? {
environment.webSocketClientBuilder?(
urlSessionConfiguration,
requestEncoder,
EventDecoder(),
eventNotificationCenter
)
Expand Down Expand Up @@ -114,7 +112,7 @@ class ChatClientFactory {
func makeEventNotificationCenter(
databaseContainer: DatabaseContainer,
currentUserId: @escaping () -> UserId?
) -> EventNotificationCenter {
) -> PersistentEventNotificationCenter {
let center = environment.notificationCenterBuilder(databaseContainer, nil)
let middlewares: [EventMiddleware] = [
EventDataProcessorMiddleware(),
Expand Down
18 changes: 0 additions & 18 deletions Sources/StreamChat/Config/ChatClientConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,3 @@ extension ChatClientConfig {
public var latestMessagesLimit = 5
}
}

/// A struct representing an API key of the chat app.
///
/// An API key can be obtained by registering on [our website](https://getstream.io/chat/trial/\).
///
public struct APIKey: Equatable, Sendable {
/// The string representation of the API key
public let apiKeyString: String

/// Creates a new `APIKey` from the provided string. Fails, if the string is empty.
///
/// - Warning: The `apiKeyString` must be a non-empty value, otherwise an assertion failure is raised.
///
public init(_ apiKeyString: String) {
log.assert(apiKeyString.isEmpty == false, "APIKey can't be initialize with an empty string.")
self.apiKeyString = apiKeyString
}
}
4 changes: 0 additions & 4 deletions Sources/StreamChat/Config/Token.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ public extension Token {
}
}

extension ClientError {
public final class InvalidToken: ClientError, @unchecked Sendable {}
}

private extension String {
var jwtPayload: [String: Any]? {
let parts = split(separator: ".")
Expand Down
84 changes: 0 additions & 84 deletions Sources/StreamChat/Errors/ClientError.swift

This file was deleted.

Loading
Loading