Skip to content

Commit f992a3b

Browse files
committed
Migrate concurrency and errors
1 parent 433e4e2 commit f992a3b

File tree

21 files changed

+51
-583
lines changed

21 files changed

+51
-583
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//
2+
// Copyright © 2025 Stream.io Inc. All rights reserved.
3+
//

Sources/StreamChat/APIClient/RequestEncoder.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ protocol ConnectionDetailsProviderDelegate: AnyObject {
304304
}
305305

306306
public extension ClientError {
307-
final class InvalidURL: ClientError, @unchecked Sendable {}
308307
final class InvalidJSON: ClientError, @unchecked Sendable {}
309308
final class MissingConnectionId: ClientError, @unchecked Sendable {}
310309
}

Sources/StreamChat/Config/ChatClientConfig.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,3 @@ extension ChatClientConfig {
227227
public var latestMessagesLimit = 5
228228
}
229229
}
230-
231-
/// A struct representing an API key of the chat app.
232-
///
233-
/// An API key can be obtained by registering on [our website](https://getstream.io/chat/trial/\).
234-
///
235-
public struct APIKey: Equatable, Sendable {
236-
/// The string representation of the API key
237-
public let apiKeyString: String
238-
239-
/// Creates a new `APIKey` from the provided string. Fails, if the string is empty.
240-
///
241-
/// - Warning: The `apiKeyString` must be a non-empty value, otherwise an assertion failure is raised.
242-
///
243-
public init(_ apiKeyString: String) {
244-
log.assert(apiKeyString.isEmpty == false, "APIKey can't be initialize with an empty string.")
245-
self.apiKeyString = apiKeyString
246-
}
247-
}

Sources/StreamChat/Config/Token.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ public extension Token {
7272
}
7373
}
7474

75-
extension ClientError {
76-
public final class InvalidToken: ClientError, @unchecked Sendable {}
77-
}
78-
7975
private extension String {
8076
var jwtPayload: [String: Any]? {
8177
let parts = split(separator: ".")

Sources/StreamChat/Controllers/PollController/PollVoteListController.swift

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,14 @@ public class PollVoteListController: DataController, DelegateCallable, DataStore
170170
vote = event.vote
171171
}
172172
guard let vote else { return }
173-
if vote.isAnswer == true && self.query.pollId == vote.pollId && self.query.optionId == nil {
174-
self.pollsRepository.link(pollVote: vote, to: query)
173+
if vote.isAnswer == true
174+
&& query.pollId == vote.pollId
175+
&& query.optionId == nil {
176+
pollsRepository.link(pollVote: vote, to: query)
177+
} else if vote.isAnswer == false
178+
&& query.pollId == vote.pollId
179+
&& query.optionId == vote.optionId {
180+
pollsRepository.link(pollVote: vote, to: query)
175181
}
176182
}
177183
}
@@ -270,24 +276,3 @@ extension PollVoteListController {
270276
}
271277
}
272278
}
273-
274-
extension PollVoteListController: EventsControllerDelegate {
275-
public func eventsController(_ controller: EventsController, didReceiveEvent event: any Event) {
276-
var vote: PollVote?
277-
if let event = event as? PollVoteCastedEvent {
278-
vote = event.vote
279-
} else if let event = event as? PollVoteChangedEvent {
280-
vote = event.vote
281-
}
282-
guard let vote else { return }
283-
if vote.isAnswer == true
284-
&& query.pollId == vote.pollId
285-
&& query.optionId == nil {
286-
pollsRepository.link(pollVote: vote, to: query)
287-
} else if vote.isAnswer == false
288-
&& query.pollId == vote.pollId
289-
&& query.optionId == vote.optionId {
290-
pollsRepository.link(pollVote: vote, to: query)
291-
}
292-
}
293-
}

Sources/StreamChat/Errors/ClientError.swift

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,6 @@
44

55
import Foundation
66

7-
/// A Client error.
8-
public class ClientError: Error, CustomStringConvertible, @unchecked Sendable {
9-
public struct Location: Equatable {
10-
public let file: String
11-
public let line: Int
12-
}
13-
14-
/// The file and line number which emitted the error.
15-
public let location: Location?
16-
17-
public let message: String?
18-
19-
/// An underlying error.
20-
public let underlyingError: Error?
21-
22-
public var errorDescription: String? { underlyingError.map(String.init(describing:)) }
23-
24-
/// The error payload if the underlying error comes from a server error.
25-
public var errorPayload: ErrorPayload? { underlyingError as? ErrorPayload }
26-
27-
/// Retrieve the localized description for this error.
28-
public var localizedDescription: String { message ?? errorDescription ?? "" }
29-
30-
public private(set) lazy var description = "Error \(type(of: self)) in \(location?.file ?? ""):\(location?.line ?? 0)"
31-
+ (localizedDescription.isEmpty ? "" : " -> ")
32-
+ localizedDescription
33-
34-
/// A client error based on an external general error.
35-
/// - Parameters:
36-
/// - error: an external error.
37-
/// - file: a file name source of an error.
38-
/// - line: a line source of an error.
39-
public init(with error: Error? = nil, _ file: StaticString = #file, _ line: UInt = #line) {
40-
message = nil
41-
underlyingError = error
42-
location = .init(file: "\(file)", line: Int(line))
43-
}
44-
45-
/// An error based on a message.
46-
/// - Parameters:
47-
/// - message: an error message.
48-
/// - file: a file name source of an error.
49-
/// - line: a line source of an error.
50-
public init(_ message: String, _ file: StaticString = #file, _ line: UInt = #line) {
51-
self.message = message
52-
location = .init(file: "\(file)", line: Int(line))
53-
underlyingError = nil
54-
}
55-
}
56-
57-
extension ClientError {
58-
/// An unexpected error.
59-
public final class Unexpected: ClientError, @unchecked Sendable {}
60-
61-
/// An unknown error.
62-
public final class Unknown: ClientError, @unchecked Sendable {}
63-
}
64-
65-
// This should probably live only in the test target since it's not "true" equatable
66-
extension ClientError: Equatable {
67-
public static func == (lhs: ClientError, rhs: ClientError) -> Bool {
68-
type(of: lhs) == type(of: rhs)
69-
&& String(describing: lhs.underlyingError) == String(describing: rhs.underlyingError)
70-
&& String(describing: lhs.localizedDescription) == String(describing: rhs.localizedDescription)
71-
}
72-
}
73-
747
extension ClientError {
758
/// Returns `true` the stream code determines that the token is expired.
769
var isExpiredTokenError: Bool {
@@ -81,4 +14,7 @@ extension ClientError {
8114
var isInvalidTokenError: Bool {
8215
(underlyingError as? ErrorPayload)?.isInvalidTokenError == true
8316
}
17+
18+
/// The error payload if the underlying error comes from a server error.
19+
public var errorPayload: ErrorPayload? { underlyingError as? ErrorPayload }
8420
}

Sources/StreamChat/Utils/AllocatedUnfairLock.swift

Lines changed: 0 additions & 39 deletions
This file was deleted.

Sources/StreamChat/Utils/Atomic.swift

Lines changed: 0 additions & 59 deletions
This file was deleted.

Sources/StreamChat/Utils/StreamConcurrency.swift

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)