-
Notifications
You must be signed in to change notification settings - Fork 45
chat: add Jetpack Compose support to documentation #2991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ttypic
wants to merge
2
commits into
main
Choose a base branch
from
chat-jetpack-compose
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,11 @@ The history feature enables users to retrieve messages that have been previously | |
| ## Retrieve previously sent messages <a id="history"/> | ||
|
|
||
| <If lang="javascript,swift,kotlin"> | ||
| Use the <If lang="javascript">[`messages.history()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#history)</If><If lang="swift">[`messages.history()`](https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/messages/history(withparams:))</If><If lang="kotlin">[`messages.history()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat/com.ably.chat/-messages/history.html)</If> method to retrieve messages that have been previously sent to a room. This returns a paginated response, which can be queried further to retrieve the next set of messages. | ||
| Use the <If lang="javascript">[`messages.history()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#history)</If><If lang="swift">[`messages.history()`](https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/messages/history(withparams:))</If><If lang="kotlin">[`messages.history()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat/com.ably.chat/-messages/history.html)</If><If lang="jetpack">[`collectAsPagingMessagesState()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/jetpack/chat-extensions-compose/com.ably.chat.extensions.compose/collect-as-paging-messages-state.html)</If> method to retrieve messages that have been previously sent to a room. This returns a paginated response, which can be queried further to retrieve the next set of messages. | ||
| </If> | ||
|
|
||
| <If lang="jetpack"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The above |
||
| Use the [`collectAsPagingMessagesState()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/jetpack/chat-extensions-compose/com.ably.chat.extensions.compose/collect-as-paging-messages-state.html) method to retrieve messages that have been previously sent to a room. This returns a paginated response, which can be queried further to retrieve the next set of messages. | ||
| </If> | ||
|
|
||
| <If lang="react"> | ||
|
|
@@ -71,6 +75,28 @@ while (historicalMessages.hasNext()) { | |
|
|
||
| println("End of messages") | ||
| ``` | ||
|
|
||
| ```jetpack | ||
| import androidx.compose.foundation.lazy.LazyColumn | ||
| import androidx.compose.material.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.getValue | ||
| import com.ably.chat.extensions.compose.collectAsPagingMessagesState | ||
|
|
||
| @Composable | ||
| fun HistoryComponent(room: Room) { | ||
| val pagingMessagesState by room.messages.collectAsPagingMessagesState( | ||
| orderBy = OrderBy.NewestFirst | ||
| ) | ||
|
|
||
| LazyColumn { | ||
| items(pagingMessagesState.messages.size) { index -> | ||
| val message = pagingMessagesState.messages[index] | ||
| Text("Message: ${message.text}") | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
| </Code> | ||
|
|
||
| The following optional parameters can be passed when retrieving previously sent messages: | ||
|
|
@@ -90,6 +116,10 @@ Users can also retrieve historical messages that were sent to a room before the | |
| Use the <If lang="javascript">[`historyBeforeSubscribe()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.MessageSubscriptionResponse.html#historyBeforeSubscribe)</If><If lang="swift">[`historyBeforeSubscribe(withParams:)`](https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/messagesubscriptionresponse/historybeforesubscribe%28withparams%3A%29))</If><If lang="kotlin">[`getPreviousMessages()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat/com.ably.chat/-messages-subscription/get-previous-messages.html)</If> function returned as part of a [message subscription](/docs/chat/rooms/messages#subscribe) response to only retrieve messages that were received before the listener was subscribed to the room. This returns a paginated response, which can be queried further to retrieve the next set of messages. | ||
| </If> | ||
|
|
||
| <If lang="jetpack"> | ||
| Use the [`getPreviousMessages()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat/com.ably.chat/-messages-subscription/get-previous-messages.html) function returned as part of a [message subscription](/docs/chat/rooms/messages#subscribe) response to only retrieve messages that were received before the listener was subscribed to the room. This returns a paginated response, which can be queried further to retrieve the next set of messages. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
| </If> | ||
|
|
||
| <If lang="react"> | ||
| Use the [`historyBeforeSubscribe()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseMessagesResponse.html#historyBeforeSubscribe) method available from the response of the `useMessages` hook to only retrieve messages that were received before the listener subscribed to the room. As long as a defined value is provided for the listener, and there are no message discontinuities, `historyBeforeSubscribe()` will return messages from the same point across component renders. If the listener becomes undefined, the subscription to messages will be removed. If you subsequently redefine the listener then `historyBeforeSubscribe()` will return messages from the new point of subscription. This returns a paginated response, which can be queried further to retrieve the next set of messages. | ||
| </If> | ||
|
|
@@ -157,7 +187,7 @@ val subscription = room.messages.subscribe { | |
| println("New message received") | ||
| } | ||
|
|
||
| var historicalMessages = subscription.historyBeforeSubscribe(limit = 50) | ||
| var historicalMessages = subscription.getPreviousMessages(limit = 50) | ||
| println(historicalMessages.items.toString()) | ||
|
|
||
| while (historicalMessages.hasNext()) { | ||
|
|
@@ -167,6 +197,34 @@ while (historicalMessages.hasNext()) { | |
|
|
||
| println("End of messages") | ||
| ``` | ||
|
|
||
| ```jetpack | ||
| import androidx.compose.runtime.* | ||
| import com.ably.chat.extensions.compose.collectAsPagingMessagesState | ||
|
|
||
| @Composable | ||
| fun HistoryBeforeSubscribeComponent(room: Room) { | ||
| DisposableEffect(room) { | ||
| val subscription = room.messages.subscribe { | ||
| println("New message received") | ||
| } | ||
|
|
||
| var historicalMessages = subscription.getPreviousMessages(limit = 50) | ||
| println(historicalMessages.items.toString()) | ||
|
|
||
| while (historicalMessages.hasNext()) { | ||
| historicalMessages = historicalMessages.next() | ||
| println(historicalMessages.items.toString()) | ||
| } | ||
|
|
||
| println("End of messages") | ||
|
|
||
| onDispose { | ||
| subscription.unsubscribe() | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
| </Code> | ||
|
|
||
| The following parameters can be passed when retrieving previously sent messages: | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added these as a fixup so that it shows up in docs - could you source an icon for Jetpack so it shows in the language selector?