Skip to content

Commit 43880f1

Browse files
Update method in line with Swift guidelines
See [1], in particular "Prefer method and function names that make use sites form grammatical English phrases". The "omit needless words" guideline is a bit harder to interpret and I wonder whether, under that guideline, things like `send(withParams params: SendMessageParams)` should be `with params: SendMessageParams` but honestly I don't know how understandable that is, especially when you use implicit `.init()` to create the argument. I think better to err on the side of caution and being a bit more verbose? Have renamed: - Messages: - history(options: QueryOptions) to history(withOptions options: QueryOptions) - send(params: SendMessageParams) to send(withParams params: SendMessageParams) - MessageSubscriptionAsyncSequence: - getPreviousMessages(params: QueryOptions) to getPreviousMessages(withParams params: QueryOptions) - MessageReactions: - send(messageSerial: String, params: SendMessageReactionParams) to send(forMessageWithSerial messageSerial: String, params: SendMessageReactionParams) - delete(messageSerial: String, params: SendMessageReactionParams) to delete(forMessageWithSerial messageSerial: String, params: SendMessageReactionParams) - Presence: - get(params: PresenceParams) to get(withParams params: PresenceParams) - isUserPresent(clientID: String) to isUserPresent(withClientID clientID: String) - enter(data: PresenceData) to enter(withData data: PresenceData); ditto for update, leave - RoomReactions: - send(params: SendReactionParams) to send(withParams params: SendReactionParams) - MessageSubscriptionResponse: - historyBeforeSubscribe(_ params: QueryOptions) to historyBeforeSubscribe(withParams params: QueryOptions) Have not touched Messages' `update` or `delete` methods yet because their signature seems completely inconsistent with that of JS; need to look into it further. [1] https://www.swift.org/documentation/api-design-guidelines/
1 parent 2039e87 commit 43880f1

17 files changed

+81
-81
lines changed

Example/AblyChatExample/ContentView.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ struct ContentView: View {
224224

225225
try await room.attach()
226226
try await showOccupancy(room: room)
227-
try await room.presence.enter(data: ["status": "📱 Online"])
227+
try await room.presence.enter(withData: ["status": "📱 Online"])
228228

229229
try await showMessages(room: room)
230230
} catch {
@@ -275,7 +275,7 @@ struct ContentView: View {
275275
}
276276
}
277277
}
278-
let previousMessages = try await subscription.historyBeforeSubscribe(.init())
278+
let previousMessages = try await subscription.historyBeforeSubscribe(withParams: .init())
279279

280280
for message in previousMessages.items {
281281
switch message.action {
@@ -387,7 +387,7 @@ struct ContentView: View {
387387
guard !newMessage.isEmpty else {
388388
return
389389
}
390-
_ = try await room().messages.send(params: .init(text: newMessage))
390+
_ = try await room().messages.send(withParams: .init(text: newMessage))
391391
newMessage = ""
392392
}
393393

@@ -417,19 +417,19 @@ struct ContentView: View {
417417

418418
func sendRoomReaction(_ reaction: String) {
419419
Task {
420-
try await room().reactions.send(params: .init(name: reaction))
420+
try await room().reactions.send(withParams: .init(name: reaction))
421421
}
422422
}
423423

424424
func addMessageReaction(_ reaction: String, messageSerial: String) {
425425
Task {
426-
try await room().messages.reactions.send(messageSerial: messageSerial, params: .init(name: reaction, type: .distinct))
426+
try await room().messages.reactions.send(forMessageWithSerial: messageSerial, params: .init(name: reaction, type: .distinct))
427427
}
428428
}
429429

430430
func deleteMessageReaction(_ reaction: String, messageSerial: String) {
431431
Task {
432-
try await room().messages.reactions.delete(messageSerial: messageSerial, params: .init(name: reaction, type: .distinct))
432+
try await room().messages.reactions.delete(forMessageWithSerial: messageSerial, params: .init(name: reaction, type: .distinct))
433433
}
434434
}
435435

Example/AblyChatExample/Mocks/MockClients.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class MockMessageReactions: MessageReactions {
246246
self.roomName = roomName
247247
}
248248

249-
func send(messageSerial: String, params: SendMessageReactionParams) async throws(ARTErrorInfo) {
249+
func send(forMessageWithSerial messageSerial: String, params: SendMessageReactionParams) async throws(ARTErrorInfo) {
250250
reactions.append(
251251
MessageReaction(
252252
type: .distinct,
@@ -265,7 +265,7 @@ class MockMessageReactions: MessageReactions {
265265
)
266266
}
267267

268-
func delete(messageSerial: String, params: DeleteMessageReactionParams) async throws(ARTErrorInfo) {
268+
func delete(forMessageWithSerial messageSerial: String, params: DeleteMessageReactionParams) async throws(ARTErrorInfo) {
269269
reactions.removeAll { reaction in
270270
reaction.messageSerial == messageSerial && reaction.name == params.name && reaction.clientID == clientID
271271
}

Sources/AblyChat/DefaultMessageReactions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal final class DefaultMessageReactions: MessageReactions {
1919
}
2020

2121
// (CHA-MR4) Users should be able to send a reaction to a message via the `send` method of the `MessagesReactions` object
22-
internal func send(messageSerial: String, params: SendMessageReactionParams) async throws(ARTErrorInfo) {
22+
internal func send(forMessageWithSerial messageSerial: String, params: SendMessageReactionParams) async throws(ARTErrorInfo) {
2323
do {
2424
var count = params.count
2525
if params.type == .multiple, params.count == nil {
@@ -40,7 +40,7 @@ internal final class DefaultMessageReactions: MessageReactions {
4040
}
4141

4242
// (CHA-MR11) Users should be able to delete a reaction from a message via the `delete` method of the `MessagesReactions` object
43-
internal func delete(messageSerial: String, params: DeleteMessageReactionParams) async throws(ARTErrorInfo) {
43+
internal func delete(forMessageWithSerial messageSerial: String, params: DeleteMessageReactionParams) async throws(ARTErrorInfo) {
4444
let reactionType = params.type ?? options.defaultMessageReactionType
4545
if reactionType != .unique, params.name == nil {
4646
throw ARTErrorInfo(chatError: .unableDeleteReactionWithoutName(reactionType: reactionType.rawValue))

Sources/AblyChat/DefaultMessages.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ internal final class DefaultMessages: Messages {
115115
}
116116

117117
// (CHA-M6a) A method must be exposed that accepts the standard Ably REST API query parameters. It shall call the "REST API"#rest-fetching-messages and return a PaginatedResult containing messages, which can then be paginated through.
118-
internal func history(options: QueryOptions) async throws(ARTErrorInfo) -> some PaginatedResult<Message> {
118+
internal func history(withOptions options: QueryOptions) async throws(ARTErrorInfo) -> some PaginatedResult<Message> {
119119
do {
120120
return try await chatAPI.getMessages(roomName: roomName, params: options)
121121
} catch {
122122
throw error.toARTErrorInfo()
123123
}
124124
}
125125

126-
internal func send(params: SendMessageParams) async throws(ARTErrorInfo) -> Message {
126+
internal func send(withParams params: SendMessageParams) async throws(ARTErrorInfo) -> Message {
127127
do {
128128
return try await chatAPI.sendMessage(roomName: roomName, params: params)
129129
} catch {

Sources/AblyChat/DefaultPresence.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ internal final class DefaultPresence: Presence {
4242
}
4343
}
4444

45-
internal func get(params: PresenceParams) async throws(ARTErrorInfo) -> [PresenceMember] {
45+
internal func get(withParams params: PresenceParams) async throws(ARTErrorInfo) -> [PresenceMember] {
4646
do throws(InternalError) {
4747
logger.log(message: "Getting presence with params: \(params)", level: .debug)
4848

@@ -68,7 +68,7 @@ internal final class DefaultPresence: Presence {
6868
}
6969

7070
// (CHA-PR5) It must be possible to query if a given clientId is in the presence set.
71-
internal func isUserPresent(clientID: String) async throws(ARTErrorInfo) -> Bool {
71+
internal func isUserPresent(withClientID clientID: String) async throws(ARTErrorInfo) -> Bool {
7272
do throws(InternalError) {
7373
logger.log(message: "Checking if user is present with clientID: \(clientID)", level: .debug)
7474

@@ -94,7 +94,7 @@ internal final class DefaultPresence: Presence {
9494
}
9595
}
9696

97-
internal func enter(data: PresenceData) async throws(ARTErrorInfo) {
97+
internal func enter(withData data: PresenceData) async throws(ARTErrorInfo) {
9898
try await enter(optionalData: data)
9999
}
100100

@@ -126,7 +126,7 @@ internal final class DefaultPresence: Presence {
126126
}
127127
}
128128

129-
internal func update(data: PresenceData) async throws(ARTErrorInfo) {
129+
internal func update(withData data: PresenceData) async throws(ARTErrorInfo) {
130130
try await update(optionalData: data)
131131
}
132132

@@ -158,7 +158,7 @@ internal final class DefaultPresence: Presence {
158158
}
159159
}
160160

161-
internal func leave(data: PresenceData) async throws(ARTErrorInfo) {
161+
internal func leave(withData data: PresenceData) async throws(ARTErrorInfo) {
162162
try await leave(optionalData: data)
163163
}
164164

Sources/AblyChat/DefaultRoomReactions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal final class DefaultRoomReactions: RoomReactions {
1515

1616
// (CHA-ER3) Ephemeral room reactions are sent to Ably via the Realtime connection via a send method.
1717
// (CHA-ER3d) Reactions are sent on the channel using a message in a particular format - see spec for format.
18-
internal func send(params: SendReactionParams) async throws(ARTErrorInfo) {
18+
internal func send(withParams params: SendReactionParams) async throws(ARTErrorInfo) {
1919
do {
2020
logger.log(message: "Sending reaction with params: \(params)", level: .debug)
2121

Sources/AblyChat/MessageReactions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public protocol MessageReactions: AnyObject, Sendable {
1919
*
2020
* - Note: It is possible to receive your own reaction via the reactions subscription before this method returns.
2121
*/
22-
func send(messageSerial: String, params: SendMessageReactionParams) async throws(ARTErrorInfo)
22+
func send(forMessageWithSerial messageSerial: String, params: SendMessageReactionParams) async throws(ARTErrorInfo)
2323

2424
/**
2525
* Delete a message reaction.
@@ -28,7 +28,7 @@ public protocol MessageReactions: AnyObject, Sendable {
2828
* - messageSerial: A serial of the message to remove the reaction from.
2929
* - params: The type of reaction annotation and the specific reaction to remove. The reaction to remove is required for all types except ``MessageReactionType/unique``.
3030
*/
31-
func delete(messageSerial: String, params: DeleteMessageReactionParams) async throws(ARTErrorInfo)
31+
func delete(forMessageWithSerial messageSerial: String, params: DeleteMessageReactionParams) async throws(ARTErrorInfo)
3232

3333
/**
3434
* Subscribe to message reaction summaries. Use this to keep message reaction counts up to date efficiently in the UI.

Sources/AblyChat/Messages.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public protocol Messages: AnyObject, Sendable {
3333
*
3434
* - Returns: A paginated result object that can be used to fetch more messages if available.
3535
*/
36-
func history(options: QueryOptions) async throws(ARTErrorInfo) -> HistoryResult
36+
func history(withOptions options: QueryOptions) async throws(ARTErrorInfo) -> HistoryResult
3737

3838
/**
3939
* Send a message in the chat room.
@@ -47,7 +47,7 @@ public protocol Messages: AnyObject, Sendable {
4747
*
4848
* - Note: It is possible to receive your own message via the messages subscription before this method returns.
4949
*/
50-
func send(params: SendMessageParams) async throws(ARTErrorInfo) -> Message
50+
func send(withParams params: SendMessageParams) async throws(ARTErrorInfo) -> Message
5151

5252
/**
5353
* Updates a message in the chat room.
@@ -391,7 +391,7 @@ public final class MessageSubscriptionAsyncSequence<HistoryResult: PaginatedResu
391391
}
392392

393393
// swiftlint:disable:next missing_docs
394-
public func getPreviousMessages(params: QueryOptions) async throws(ARTErrorInfo) -> HistoryResult {
394+
public func getPreviousMessages(withParams params: QueryOptions) async throws(ARTErrorInfo) -> HistoryResult {
395395
try await getPreviousMessages(params)
396396
}
397397

Sources/AblyChat/Presence.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public protocol Presence: AnyObject, Sendable {
2929
*
3030
* - Throws: An `ARTErrorInfo`.
3131
*/
32-
func get(params: PresenceParams) async throws(ARTErrorInfo) -> [PresenceMember]
32+
func get(withParams params: PresenceParams) async throws(ARTErrorInfo) -> [PresenceMember]
3333

3434
/**
3535
* Method to check if user with supplied clientId is online.
@@ -41,7 +41,7 @@ public protocol Presence: AnyObject, Sendable {
4141
*
4242
* - Throws: An `ARTErrorInfo`.
4343
*/
44-
func isUserPresent(clientID: String) async throws(ARTErrorInfo) -> Bool
44+
func isUserPresent(withClientID clientID: String) async throws(ARTErrorInfo) -> Bool
4545

4646
/**
4747
* Method to join room presence, will emit an enter event to all subscribers. Repeat calls will trigger more enter events.
@@ -51,7 +51,7 @@ public protocol Presence: AnyObject, Sendable {
5151
*
5252
* - Throws: An `ARTErrorInfo`.
5353
*/
54-
func enter(data: PresenceData) async throws(ARTErrorInfo)
54+
func enter(withData data: PresenceData) async throws(ARTErrorInfo)
5555

5656
/**
5757
* Method to update room presence, will emit an update event to all subscribers. If the user is not present, it will be treated as a join event.
@@ -61,7 +61,7 @@ public protocol Presence: AnyObject, Sendable {
6161
*
6262
* - Throws: An `ARTErrorInfo`.
6363
*/
64-
func update(data: PresenceData) async throws(ARTErrorInfo)
64+
func update(withData data: PresenceData) async throws(ARTErrorInfo)
6565

6666
/**
6767
* Method to leave room presence, will emit a leave event to all subscribers. If the user is not present, it will be treated as a no-op.
@@ -71,7 +71,7 @@ public protocol Presence: AnyObject, Sendable {
7171
*
7272
* - Throws: An `ARTErrorInfo`.
7373
*/
74-
func leave(data: PresenceData) async throws(ARTErrorInfo)
74+
func leave(withData data: PresenceData) async throws(ARTErrorInfo)
7575

7676
/**
7777
* Subscribes a given listener to a particular presence event in the chat room.

Sources/AblyChat/RoomReactions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public protocol RoomReactions: AnyObject, Sendable {
1818
*
1919
* - Note: It is possible to receive your own reaction via the reactions subscription before this method returns.
2020
*/
21-
func send(params: SendReactionParams) async throws(ARTErrorInfo)
21+
func send(withParams params: SendReactionParams) async throws(ARTErrorInfo)
2222

2323
/**
2424
* Subscribes a given listener to the room reactions.

0 commit comments

Comments
 (0)