MessagesViewModelFactory

class MessagesViewModelFactory(context: Context, channelId: String, messageId: String? = null, parentMessageId: String? = null, autoTranslationEnabled: Boolean = false, chatClient: ChatClient = ChatClient.instance(), clientState: ClientState = chatClient.clientState, mediaRecorder: StreamMediaRecorder = DefaultStreamMediaRecorder(context.applicationContext), userLookupHandler: UserLookupHandler = DefaultUserLookupHandler(chatClient, channelId), fileToUriConverter: (File) -> String = { file -> file.toUri().toString() }, messageLimit: Int = MessageListController.DEFAULT_MESSAGES_LIMIT, clipboardHandler: ClipboardHandler = ClipboardHandlerImpl( clipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager, autoTranslationEnabled = autoTranslationEnabled, getCurrentUser = { chatClient.getCurrentUser() }, ), enforceUniqueReactions: Boolean = true, maxAttachmentCount: Int = AttachmentConstants.MAX_ATTACHMENTS_COUNT, showSystemMessages: Boolean = true, deletedMessageVisibility: DeletedMessageVisibility = DeletedMessageVisibility.ALWAYS_VISIBLE, messageFooterVisibility: MessageFooterVisibility = MessageFooterVisibility.WithTimeDifference(), dateSeparatorHandler: DateSeparatorHandler = DateSeparatorHandler.getDefaultDateSeparatorHandler(), threadDateSeparatorHandler: DateSeparatorHandler = DateSeparatorHandler.getDefaultThreadDateSeparatorHandler(), messagePositionHandler: MessagePositionHandler = MessagePositionHandler.defaultHandler(), showDateSeparatorInEmptyThread: Boolean = false, showThreadSeparatorInEmptyThread: Boolean = false, threadLoadOlderToNewer: Boolean = false, isComposerLinkPreviewEnabled: Boolean = false) : ViewModelProvider.Factory

Holds all the dependencies needed to build the ViewModels for the Messages Screen. Currently builds the MessageComposerViewModel, MessageListViewModel and AttachmentsPickerViewModel.

Parameters

context

Used to build the ClipboardManager.

channelId

The current channel ID, to load the messages from.

messageId

The message id to which we want to scroll to when opening the message list.

parentMessageId

The ID of the parent Message if the message we want to scroll to is in a thread. If the message we want to scroll to is not in a thread, you can pass in a null value.

chatClient

The client to use for API calls.

clientState

The current state of the SDK.

mediaRecorder

The media recorder for async voice messages.

messageLimit

The number of messages to load in a single page.

clipboardHandler

ClipboardHandler used to copy messages.

enforceUniqueReactions

Flag to enforce unique reactions or enable multiple from the same user.

maxAttachmentCount

The maximum number of attachments that can be sent in a single message.

showSystemMessages

If we should show system message items in the list.

deletedMessageVisibility

The behavior of deleted messages in the list and if they're visible or not.

messageFooterVisibility

The behavior of message footers in the list and their visibility.

dateSeparatorHandler

Handler that determines when the date separators should be visible.

threadDateSeparatorHandler

Handler that determines when the thread date separators should be visible.

messagePositionHandler

Determines the position of the message inside a group.

showDateSeparatorInEmptyThread

Configures if we show a date separator when threads are empty. Adds the separator item when the value is true.

showThreadSeparatorInEmptyThread

Configures if we show a thread separator when threads are empty. Adds the separator item when the value is true.

threadLoadOlderToNewer

Configures if the thread should load older messages to newer messages.

Constructors

Link copied to clipboard
constructor(context: Context, channelId: String, messageId: String? = null, parentMessageId: String? = null, autoTranslationEnabled: Boolean = false, chatClient: ChatClient = ChatClient.instance(), clientState: ClientState = chatClient.clientState, mediaRecorder: StreamMediaRecorder = DefaultStreamMediaRecorder(context.applicationContext), userLookupHandler: UserLookupHandler = DefaultUserLookupHandler(chatClient, channelId), fileToUriConverter: (File) -> String = { file -> file.toUri().toString() }, messageLimit: Int = MessageListController.DEFAULT_MESSAGES_LIMIT, clipboardHandler: ClipboardHandler = ClipboardHandlerImpl( clipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager, autoTranslationEnabled = autoTranslationEnabled, getCurrentUser = { chatClient.getCurrentUser() }, ), enforceUniqueReactions: Boolean = true, maxAttachmentCount: Int = AttachmentConstants.MAX_ATTACHMENTS_COUNT, showSystemMessages: Boolean = true, deletedMessageVisibility: DeletedMessageVisibility = DeletedMessageVisibility.ALWAYS_VISIBLE, messageFooterVisibility: MessageFooterVisibility = MessageFooterVisibility.WithTimeDifference(), dateSeparatorHandler: DateSeparatorHandler = DateSeparatorHandler.getDefaultDateSeparatorHandler(), threadDateSeparatorHandler: DateSeparatorHandler = DateSeparatorHandler.getDefaultThreadDateSeparatorHandler(), messagePositionHandler: MessagePositionHandler = MessagePositionHandler.defaultHandler(), showDateSeparatorInEmptyThread: Boolean = false, showThreadSeparatorInEmptyThread: Boolean = false, threadLoadOlderToNewer: Boolean = false, isComposerLinkPreviewEnabled: Boolean = false)

Functions

Link copied to clipboard
open override fun <T : ViewModel> create(modelClass: Class<T>): T

Creates the required ViewModel for our use case, based on the factories we provided.

Inherited functions

Link copied to clipboard
open fun <T : ViewModel> create(modelClass: Class<T>, extras: CreationExtras): T
open fun <T : ViewModel> create(modelClass: KClass<T>, extras: CreationExtras): T