From 3ca59a6fadfe8b537e8acbbc974ac017460a7f3d Mon Sep 17 00:00:00 2001 From: Marat Al Date: Thu, 5 Dec 2024 15:59:33 +0100 Subject: [PATCH] Updated to the recent swift API changes to fit JS. --- content/chat/connect.textile | 20 ++++++++++---------- content/chat/rooms/history.textile | 2 +- content/chat/rooms/index.textile | 4 ++-- content/chat/rooms/messages.textile | 4 ++-- content/chat/rooms/occupancy.textile | 2 +- content/chat/rooms/reactions.textile | 4 ++-- content/chat/rooms/typing.textile | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/content/chat/connect.textile b/content/chat/connect.textile index c5594ef81b..c76e2551ee 100644 --- a/content/chat/connect.textile +++ b/content/chat/connect.textile @@ -72,7 +72,7 @@ blang[react]. blang[javascript,swift]. blang[javascript,swift]. - Use the "@connection.status.onChange()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.ConnectionStatus.html#onChange"@connection.onStatusChange(bufferingPolicy: .unbounded)@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Connection.html#onStatusChange method to register a listener for status change updates: + Use the "@connection.status.onChange()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.ConnectionStatus.html#onChange"@connection.onStatusChange()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Connection.html#onStatusChange method to register a listener for status change updates: blang[react]. Listeners can also be registered to monitor the changes in connection status. Any hooks that take an optional listener to monitor their events, such as typing indicator events in the @useTyping@ hook, can also register a status change listener. Changing the value provided for a listener will cause the previously registered listener instance to stop receiving events. All messages will be received by exactly one listener. @@ -95,7 +95,7 @@ const MyComponent = () => { ``` ```[swift] -let subscription = chatClient.connection.onStatusChange(bufferingPolicy: .unbounded) +let subscription = chatClient.connection.onStatusChange() for await statusChange in subscription { print("Connection status changed to: \(statusChange.current)") } @@ -130,7 +130,7 @@ If a client briefly loses connection to Ably, for example when driving through a During periods of discontinuity greater than 2 minutes then you will need to take steps to recover any missed messages, such as by calling "history":/chat/rooms/history. blang[javascript,swift]. - Each feature of the Chat SDK provides an @onDiscontinuity()@@subscribeToDiscontinuities()@ handler to assist with this. These methods enable you to register a listener that will be notified when discontinuity occurs in that feature so that you can handle it, as needed. + Each feature of the Chat SDK provides an @onDiscontinuity()@ handler to assist with this. These methods enable you to register a listener that will be notified when discontinuity occurs in that feature so that you can handle it, as needed. blang[react]. Any hooks that take an optional listener to monitor their events, such as typing indicator events in the @useTyping@ hook, can also register a listener to be notified of, and handle, periods of discontinuity. @@ -159,7 +159,7 @@ const MyComponent = () => { ``` ```[swift] -let subscription = room.messages.subscribeToDiscontinuities() +let subscription = room.messages.onDiscontinuity() for await error in subscription { print("Recovering from the error: \(error)") } @@ -168,7 +168,7 @@ for await error in subscription { blang[react]. blang[javascript,swift]. - Use the @off()@@unsubscribe()@ function returned in the @onDiscontinuity()@@subscribeToDiscontinuities()@ response to remove a listener: + Use the @off()@@unsubscribe()@ function returned in the @onDiscontinuity()@ response to remove a listener: ```[javascript] off(); @@ -191,8 +191,8 @@ blang[javascript]. * "Room reactions":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomReactions.html#onDiscontinuity blang[swift]. - * "Messages":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Messages.html#subscribeToDiscontinuities - * "Presence":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Presence.html#subscribeToDiscontinuities - * "Occupancy":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Occupancy.html#subscribeToDiscontinuities - * "Typing indicators":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Typing.html#subscribeToDiscontinuities - * "Room reactions":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.RoomReactions.html#subscribeToDiscontinuities + * "Messages":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Messages.html#onDiscontinuity + * "Presence":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Presence.html#onDiscontinuity + * "Occupancy":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Occupancy.html#onDiscontinuity + * "Typing indicators":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Typing.html#onDiscontinuity + * "Room reactions":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.RoomReactions.html#onDiscontinuity diff --git a/content/chat/rooms/history.textile b/content/chat/rooms/history.textile index f39627dd52..0ddadb503a 100644 --- a/content/chat/rooms/history.textile +++ b/content/chat/rooms/history.textile @@ -134,7 +134,7 @@ const MyComponent = () => { ``` ```[swift] -let messagesSubscription = try await room.messages.subscribe(bufferingPolicy: .unbounded) +let messagesSubscription = try await room.messages.subscribe() let paginatedResult = try await messagesSubscription.getPreviousMessages(params: .init(limit: 50)) // `orderBy` here is ignored and always `newestFirst` print(paginatedResult.items) if let next = try await paginatedResult.next { diff --git a/content/chat/rooms/index.textile b/content/chat/rooms/index.textile index e512379e6e..777f4ab0e5 100644 --- a/content/chat/rooms/index.textile +++ b/content/chat/rooms/index.textile @@ -243,7 +243,7 @@ let status = try await room.status blang[javascript,swift]. You can also subscribe to room status updates by registering a listener. An event will be emitted whenever the status of the room changes. - Use the "@room.status.onChange()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomStatus.html#onChange"@room.onStatusChange(bufferingPolicy: .unbounded)@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Room.html#onStatusChange method in a room to register a listener for status change updates: + Use the "@room.status.onChange()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomStatus.html#onChange"@room.onStatusChange()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Room.html#onStatusChange method in a room to register a listener for status change updates: ```[javascript] const { off } = room.onStatusChange((change) => @@ -251,7 +251,7 @@ blang[javascript,swift]. ``` ```[swift] - let statusSubscription = try await room.onStatusChange(bufferingPolicy: .unbounded) + let statusSubscription = try await room.onStatusChange() for await status in statusSubscription { print("Room status: \(status)") } diff --git a/content/chat/rooms/messages.textile b/content/chat/rooms/messages.textile index 1b6f10b448..e7b5b72099 100644 --- a/content/chat/rooms/messages.textile +++ b/content/chat/rooms/messages.textile @@ -13,7 +13,7 @@ You can send and receive messages in a chat room with any number of participants h2(#subscribe). Subscribe to messages blang[javascript,swift]. - Subscribe to receive messages in a room by registering a listener. Use the "@messages.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#subscribe"@messages.subscribe(bufferingPolicy: .unbounded)@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Messages.html#subscribe method in a room to receive all messages that are sent to it: + Subscribe to receive messages in a room by registering a listener. Use the "@messages.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#subscribe"@messages.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Messages.html#subscribe method in a room to receive all messages that are sent to it: blang[react]. Subscribe to messages with the "@useMessages@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.useMessages.html hook. Supply a listener and the hook will automatically subscribe to messages sent to the room. As long as a defined value is provided, the subscription will persist across renders. If the listener value is undefined, the subscription will be removed until it becomes defined again. @@ -42,7 +42,7 @@ const MyComponent = () => { ``` ```[swift] -let messagesSubscription = try await room.messages.subscribe(bufferingPolicy: .unbounded) +let messagesSubscription = try await room.messages.subscribe() for await message in messagesSubscription { print("Message received: \(message)") } diff --git a/content/chat/rooms/occupancy.textile b/content/chat/rooms/occupancy.textile index 7ddcd5eade..73664b1ba3 100644 --- a/content/chat/rooms/occupancy.textile +++ b/content/chat/rooms/occupancy.textile @@ -29,7 +29,7 @@ const {unsubscribe} = room.occupancy.subscribe((event) => { ``` ```[swift] -let occupancySubscription = try await room.occupancy.subscribe(bufferingPolicy: .unbounded) +let occupancySubscription = try await room.occupancy.subscribe() for await event in occupancySubscription { occupancyInfo = "Connections: \(event.presenceMembers) (\(event.connections))" } diff --git a/content/chat/rooms/reactions.textile b/content/chat/rooms/reactions.textile index eab178e4f4..f284daae47 100644 --- a/content/chat/rooms/reactions.textile +++ b/content/chat/rooms/reactions.textile @@ -21,7 +21,7 @@ h2(#subscribe). Subscribe to room reactions Room reactions events are emitted whenever a user sends a reaction, such as by hitting a 'like' button or clicking a heart emoji. blang[javascript,swift]. - Subscribe to room reactions by registering a listener. Use the "@reactions.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomReactions.html#subscribe"@reactions.subscribe(bufferingPolicy: .unbounded)@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.RoomReactions.html#subscribe method in a room to receive reactions: + Subscribe to room reactions by registering a listener. Use the "@reactions.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomReactions.html#subscribe"@reactions.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.RoomReactions.html#subscribe method in a room to receive reactions: blang[react]. Subscribe to room reactions with the "@useRoomReactions@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat_react.useRoomReactions.html hook. Supply an optional listener to receive the room reactions. @@ -46,7 +46,7 @@ const MyComponent = () => { ``` ```[swift] -let reactionSubscription = try await room.reactions.subscribe(bufferingPolicy: .unbounded) +let reactionSubscription = try await room.reactions.subscribe() for await reaction in reactionSubscription { print("Received a reaction of type \(reaction.type), and metadata \(reaction.metadata)") } diff --git a/content/chat/rooms/typing.textile b/content/chat/rooms/typing.textile index 801dbf7c58..8fe2b04cea 100644 --- a/content/chat/rooms/typing.textile +++ b/content/chat/rooms/typing.textile @@ -17,7 +17,7 @@ Typing indicators enable you to display which users are currently writing a mess h2(#subscribe). Subscribe to typing events blang[javascript,swift]. - Subscribe to typing events by registering a listener. Typing events can be emitted when a user starts typing, and when they stop typing. Use the "@typing.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#subscribe"@typing.subscribe(bufferingPolicy: .unbounded)@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Typing.html#subscribe method in a room to receive these updates: + Subscribe to typing events by registering a listener. Typing events can be emitted when a user starts typing, and when they stop typing. Use the "@typing.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#subscribe"@typing.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Typing.html#subscribe method in a room to receive these updates: blang[react]. Subscribe to typing events with the "@useTyping@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.useTyping.html hook. Supply an optional listener to receive the typing events, or use the "@currentlyTyping@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseTypingResponse.html#currentlyTyping property returned by the hook to access the list of those users that are currently typing. @@ -48,7 +48,7 @@ const MyComponent = () => { ``` ```[swift] -let typingSubscription = try await room.typing.subscribe(bufferingPolicy: .unbounded) +let typingSubscription = try await room.typing.subscribe() for await typing in typingSubscription { typingInfo = typing.currentlyTyping.isEmpty ? "" : "Typing: \(typing.currentlyTyping.joined(separator: ", "))..."