Skip to content

Commit 0f0d8fb

Browse files
authored
[ECO-5342] Refactor roomID to name and roomName across SDK (#308)
* Refactor `roomID` to `name` and `roomName` across `Rooms` interface and related components for consistency. * Removed "roomID" field from Message * Update comments and arguments to use "name" instead of "ID" [ECO-5342]
1 parent 55234c9 commit 0f0d8fb

30 files changed

Lines changed: 299 additions & 325 deletions

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ If you haven't worked with typed throws before, be aware of a few sharp edges:
5656
- It is possible to crash the compiler when using Swift Testing's `#expect(throws: …)` in combination with an `expression` that throws a typed error. See https://github.com/ably/ably-chat-swift/issues/233. A workaround that seems to work, which we're using at the moment (will be able to remove once Xcode 16.3 is released) is to move the code with a typed throw into a separate, non-typed-throw function; for example:
5757
```swift
5858
let doIt = {
59-
try await rooms.get(roomID: roomID, options: differentOptions)
59+
try await rooms.get(name: name, options: differentOptions)
6060
}
6161
await #expect {
6262
try await doIt()

Example/AblyChatExample/ContentView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ struct ContentView: View {
4040
let screenHeight = UIScreen.main.bounds.height
4141
#endif
4242

43-
// Can be replaced with your own room ID
44-
private let roomID = "DemoRoom"
43+
// Can be replaced with your own room name
44+
private let roomName = "DemoRoom"
4545

4646
@State private var chatClient = Environment.current.createChatClient()
4747

@@ -78,7 +78,7 @@ struct ContentView: View {
7878
}
7979

8080
private func room() async throws -> Room {
81-
try await chatClient.rooms.get(roomID: roomID, options: .init(occupancy: .init(enableEvents: true)))
81+
try await chatClient.rooms.get(name: roomName, options: .init(occupancy: .init(enableEvents: true)))
8282
}
8383

8484
private var sendTitle: String {
@@ -101,7 +101,7 @@ struct ContentView: View {
101101
var body: some View {
102102
ZStack {
103103
VStack {
104-
Text("In \(roomID) as \(currentClientID)")
104+
Text("In \(roomName) as \(currentClientID)")
105105
.font(.headline)
106106
.padding(5)
107107
HStack {

Example/AblyChatExample/Mocks/Misc.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ final class MockMessagesPaginatedResult: PaginatedResult {
55
typealias Item = Message
66

77
let clientID: String
8-
let roomID: String
8+
let roomName: String
99
let numberOfMockMessages: Int
1010

1111
var items: [Item] {
@@ -14,7 +14,6 @@ final class MockMessagesPaginatedResult: PaginatedResult {
1414
serial: "\(Date().timeIntervalSince1970)",
1515
action: .create,
1616
clientID: self.clientID,
17-
roomID: self.roomID,
1817
text: MockStrings.randomPhrase(),
1918
createdAt: Date(),
2019
metadata: [:],
@@ -36,9 +35,9 @@ final class MockMessagesPaginatedResult: PaginatedResult {
3635

3736
var current: any PaginatedResult<Item> { fatalError("Not implemented") }
3837

39-
init(clientID: String, roomID: String, numberOfMockMessages: Int = 3) {
38+
init(clientID: String, roomName: String, numberOfMockMessages: Int = 3) {
4039
self.clientID = clientID
41-
self.roomID = roomID
40+
self.roomName = roomName
4241
self.numberOfMockMessages = numberOfMockMessages
4342
}
4443

Example/AblyChatExample/Mocks/MockClients.swift

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ class MockRooms: Rooms {
2323
let clientOptions: ChatClientOptions
2424
private var rooms = [String: MockRoom]()
2525

26-
func get(roomID: String, options: RoomOptions) async throws(ARTErrorInfo) -> any Room {
27-
if let room = rooms[roomID] {
26+
func get(name: String, options: RoomOptions) async throws(ARTErrorInfo) -> any Room {
27+
if let room = rooms[name] {
2828
return room
2929
}
30-
let room = MockRoom(roomID: roomID, options: options)
31-
rooms[roomID] = room
30+
let room = MockRoom(name: name, options: options)
31+
rooms[name] = room
3232
return room
3333
}
3434

35-
func release(roomID _: String) async {
35+
func release(name _: String) async {
3636
fatalError("Not yet implemented")
3737
}
3838

@@ -44,7 +44,7 @@ class MockRooms: Rooms {
4444
class MockRoom: Room {
4545
private let clientID = "AblyTest"
4646

47-
nonisolated let roomID: String
47+
nonisolated let name: String
4848
nonisolated let options: RoomOptions
4949
nonisolated let messages: any Messages
5050
nonisolated let presence: any Presence
@@ -54,14 +54,14 @@ class MockRoom: Room {
5454

5555
let channel: any RealtimeChannelProtocol = MockRealtime.Channel()
5656

57-
init(roomID: String, options: RoomOptions) {
58-
self.roomID = roomID
57+
init(name: String, options: RoomOptions) {
58+
self.name = name
5959
self.options = options
60-
messages = MockMessages(clientID: clientID, roomID: roomID)
61-
presence = MockPresence(clientID: clientID, roomID: roomID)
62-
reactions = MockRoomReactions(clientID: clientID, roomID: roomID)
63-
typing = MockTyping(clientID: clientID, roomID: roomID)
64-
occupancy = MockOccupancy(clientID: clientID, roomID: roomID)
60+
messages = MockMessages(clientID: clientID, roomName: name)
61+
presence = MockPresence(clientID: clientID, roomName: name)
62+
reactions = MockRoomReactions(clientID: clientID, roomName: name)
63+
typing = MockTyping(clientID: clientID, roomName: name)
64+
occupancy = MockOccupancy(clientID: clientID, roomName: name)
6565
}
6666

6767
var status: RoomStatus = .initialized
@@ -73,7 +73,7 @@ class MockRoom: Room {
7373
}
7474

7575
func attach() async throws(ARTErrorInfo) {
76-
print("Mock client attached to room with roomID: \(roomID)")
76+
print("Mock client attached to room with roomName: \(name)")
7777
}
7878

7979
func detach() async throws(ARTErrorInfo) {
@@ -105,7 +105,7 @@ class MockRoom: Room {
105105

106106
class MockMessages: Messages {
107107
let clientID: String
108-
let roomID: String
108+
let roomName: String
109109

110110
var reactions: any MessageReactions
111111

@@ -116,10 +116,10 @@ class MockMessages: Messages {
116116

117117
private let mockSubscriptions = MockMessageSubscriptionStorage<Message>()
118118

119-
init(clientID: String, roomID: String) {
119+
init(clientID: String, roomName: String) {
120120
self.clientID = clientID
121-
self.roomID = roomID
122-
reactions = MockMessageReactions(clientID: clientID, roomID: roomID)
121+
self.roomName = roomName
122+
reactions = MockMessageReactions(clientID: clientID, roomName: roomName)
123123
}
124124

125125
func subscribe(_ callback: @escaping @MainActor (Message) -> Void) async throws(ARTErrorInfo) -> MessageSubscriptionResponseProtocol {
@@ -129,7 +129,6 @@ class MockMessages: Messages {
129129
serial: "\(Date().timeIntervalSince1970)",
130130
action: .create,
131131
clientID: MockStrings.names.randomElement()!,
132-
roomID: self.roomID,
133132
text: MockStrings.randomPhrase(),
134133
createdAt: Date(),
135134
metadata: [:],
@@ -145,23 +144,22 @@ class MockMessages: Messages {
145144
return message
146145
},
147146
previousMessages: { _ in
148-
MockMessagesPaginatedResult(clientID: self.clientID, roomID: self.roomID)
147+
MockMessagesPaginatedResult(clientID: self.clientID, roomName: self.roomName)
149148
},
150149
interval: 3.0,
151150
callback: callback
152151
)
153152
}
154153

155154
func get(options _: QueryOptions) async throws(ARTErrorInfo) -> any PaginatedResult<Message> {
156-
MockMessagesPaginatedResult(clientID: clientID, roomID: roomID)
155+
MockMessagesPaginatedResult(clientID: clientID, roomName: roomName)
157156
}
158157

159158
func send(params: SendMessageParams) async throws(ARTErrorInfo) -> Message {
160159
let message = Message(
161160
serial: "\(Date().timeIntervalSince1970)",
162161
action: .create,
163162
clientID: clientID,
164-
roomID: roomID,
165163
text: params.text,
166164
createdAt: Date(),
167165
metadata: params.metadata ?? [:],
@@ -179,7 +177,6 @@ class MockMessages: Messages {
179177
serial: newMessage.serial,
180178
action: .update,
181179
clientID: clientID,
182-
roomID: roomID,
183180
text: newMessage.text,
184181
createdAt: Date(),
185182
metadata: newMessage.metadata,
@@ -197,7 +194,6 @@ class MockMessages: Messages {
197194
serial: message.serial,
198195
action: .delete,
199196
clientID: clientID,
200-
roomID: roomID,
201197
text: message.text,
202198
createdAt: Date(),
203199
metadata: message.metadata,
@@ -213,7 +209,7 @@ class MockMessages: Messages {
213209

214210
class MockMessageReactions: MessageReactions {
215211
let clientID: String
216-
let roomID: String
212+
let roomName: String
217213

218214
var clientIDs: Set<String> = []
219215
var messageSerials: [String] = []
@@ -241,9 +237,9 @@ class MockMessageReactions: MessageReactions {
241237
)
242238
}
243239

244-
init(clientID: String, roomID: String) {
240+
init(clientID: String, roomName: String) {
245241
self.clientID = clientID
246-
self.roomID = roomID
242+
self.roomName = roomName
247243
}
248244

249245
func send(to messageSerial: String, params: SendMessageReactionParams) async throws(ARTErrorInfo) {
@@ -310,13 +306,13 @@ class MockMessageReactions: MessageReactions {
310306

311307
class MockRoomReactions: RoomReactions {
312308
let clientID: String
313-
let roomID: String
309+
let roomName: String
314310

315311
private let mockSubscriptions = MockSubscriptionStorage<Reaction>()
316312

317-
init(clientID: String, roomID: String) {
313+
init(clientID: String, roomName: String) {
318314
self.clientID = clientID
319-
self.roomID = roomID
315+
self.roomName = roomName
320316
}
321317

322318
func send(params: SendReactionParams) async throws(ARTErrorInfo) {
@@ -352,13 +348,13 @@ class MockRoomReactions: RoomReactions {
352348

353349
class MockTyping: Typing {
354350
let clientID: String
355-
let roomID: String
351+
let roomName: String
356352

357353
private let mockSubscriptions = MockSubscriptionStorage<TypingSetEvent>()
358354

359-
init(clientID: String, roomID: String) {
355+
init(clientID: String, roomName: String) {
360356
self.clientID = clientID
361-
self.roomID = roomID
357+
self.roomName = roomName
362358
}
363359

364360
@discardableResult
@@ -406,13 +402,13 @@ class MockTyping: Typing {
406402

407403
class MockPresence: Presence {
408404
let clientID: String
409-
let roomID: String
405+
let roomName: String
410406

411407
private let mockSubscriptions = MockSubscriptionStorage<PresenceEvent>()
412408

413-
init(clientID: String, roomID: String) {
409+
init(clientID: String, roomName: String) {
414410
self.clientID = clientID
415-
self.roomID = roomID
411+
self.roomName = roomName
416412
}
417413

418414
private func createSubscription(callback: @escaping @MainActor (PresenceEvent) -> Void) -> SubscriptionProtocol {
@@ -526,13 +522,13 @@ class MockPresence: Presence {
526522

527523
class MockOccupancy: Occupancy {
528524
let clientID: String
529-
let roomID: String
525+
let roomName: String
530526

531527
private let mockSubscriptions = MockSubscriptionStorage<OccupancyEvent>()
532528

533-
init(clientID: String, roomID: String) {
529+
init(clientID: String, roomName: String) {
534530
self.clientID = clientID
535-
self.roomID = roomID
531+
self.roomName = roomName
536532
}
537533

538534
@discardableResult

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Task {
111111

112112
// Get a chat room for the tutorial
113113
let room = try await chatClient.rooms.get(
114-
roomID: "readme-getting-started")
114+
name: "readme-getting-started")
115115

116116
// Add a listener to observe changes to the chat rooms status
117117
let statusSubscription = room.onStatusChange()
@@ -140,7 +140,7 @@ _ = try await room.messages.send(
140140
// Wait 5 seconds before closing the connection so we have plenty of time to receive the message we just sent
141141
// This disconnects the client from Ably servers
142142
try await Task.sleep(nanoseconds: 5 * NSEC_PER_SEC)
143-
await chatClient.rooms.release(roomID: "readme-getting-started")
143+
await chatClient.rooms.release(name: "readme-getting-started")
144144
realtime.close()
145145
print("Connection closed")
146146
```

0 commit comments

Comments
 (0)