Skip to content

Commit

Permalink
[4889] Migration guide for MessagesScreen (#4890)
Browse files Browse the repository at this point in the history
Co-authored-by: kanat <>
  • Loading branch information
kanat authored Jul 24, 2023
1 parent 1afff98 commit 5c88408
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ That layer is represented by a class called `MessageListController`.

If you're using our `MessagesViewModelFactory`, you'll notice that the experience remains mostly the same along with a few changed parameters:

```kotlin {6,8,17-20}
```kotlin {7-9,11-12,19-22}
public class MessagesViewModelFactory(
private val context: Context,
private val channelId: String,
private val messageId: String? = null,
private val parentMessageId: String? = null,
private val chatClient: ChatClient = ChatClient.instance(),
private val clientState: ClientState = chatClient.clientState,
private val mediaRecorder: StreamMediaRecorder = DefaultStreamMediaRecorder(context.applicationContext),
private val fileToUriConverter: (File) -> String = { file -> file.toUri().toString() },
private val messageLimit: Int = MessageListController.DEFAULT_MESSAGES_LIMIT,
private val clipboardHandler: ClipboardHandler =
ClipboardHandlerImpl(context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# MessagesScreen

Previously, `MessagesScreen` component was internally creating `MessagesViewModelFactory` by utilizing the given component parameters.
In the new version, you are required to provide a `MessagesViewModelFactory` instance to `MessagesScreen`, which will be used for creating the required ViewModels.

## Component Parameters

Since the `MessagesViewModelFactory` is passed directly to the `MessagesScreen` component, the following parameters were removed from `MessagesScreen` component:
- `channelId: String` - The ID of the opened/active Channel.
- `messageLimit: Int` - The limit of messages per query.
- `enforceUniqueReactions: Boolean` - If we need to enforce unique reactions or not.
- `showDateSeparators: Boolean` - If we should show date separators or not.
- `showSystemMessages: Boolean` - If we should show system messages or not.
- `deletedMessageVisibility: DeletedMessageVisibility` - The behavior of deleted messages in the list and if they're visible or not.
- `messageFooterVisibility: MessageFooterVisibility` - The behavior of message footers in the list and their visibility.
- `messageId: String?` - The ID of the message which we wish to focus on, if such exists.
- `navigateToThreadViaNotification: Boolean` - If true, when a thread message arrives in a push notification, clicking it will automatically open the thread in which the message is located. If false, the SDK will always.

:::note
The parameter `navigateToThreadViaNotification: Boolean` has been removed from both `MessagesScreen` and `MessagesViewModelFactory` as navigating to thread messages via push notifications is the default behavior in `v6`.
:::

The `MessagesScreen` signature in **v5** looked like this:

```kotlin
@Composable
public fun MessagesScreen(
channelId: String,
messageLimit: Int = MessageListViewModel.DefaultMessageLimit,
showHeader: Boolean = true,
enforceUniqueReactions: Boolean = true,
showDateSeparators: Boolean = true,
showSystemMessages: Boolean = true,
deletedMessageVisibility: DeletedMessageVisibility = DeletedMessageVisibility.ALWAYS_VISIBLE,
messageFooterVisibility: MessageFooterVisibility = MessageFooterVisibility.WithTimeDifference(),
onBackPressed: () -> Unit = {},
onHeaderActionClick: (channel: Channel) -> Unit = {},
messageId: String? = null,
navigateToThreadViaNotification: Boolean = false,
skipPushNotification: Boolean = false,
skipEnrichUrl: Boolean = false,
threadMessagesStart: ThreadMessagesStart = ThreadMessagesStart.BOTTOM,
)
```

And the signature of `MessagesScreen` in **v6** looks like this:
```kotlin
@Composable
public fun MessagesScreen(
viewModelFactory: MessagesViewModelFactory,
showHeader: Boolean = true,
onBackPressed: () -> Unit = {},
onHeaderTitleClick: (channel: Channel) -> Unit = {},
onChannelAvatarClick: () -> Unit = {},
skipPushNotification: Boolean = false,
skipEnrichUrl: Boolean = false,
threadMessagesStart: ThreadMessagesStart = ThreadMessagesStart.BOTTOM,
statefulStreamMediaRecorder: StatefulStreamMediaRecorder? = null,
)
```

### MessagesViewModelFactory
Migration changes related to `MessagesViewModelFactory` can be found here [here](./01-message-list-viewmodel.mdx).

## More Information
You can find more docs about the `MessagesScreen` component and its' customization [here](../../05-compose/05-message-components/01-messages-screen.mdx).

0 comments on commit 5c88408

Please sign in to comment.