ChatScreen
Properties
screen (ChatiumJsonChatScreen): Chat data, including URLs for fetching messages, changes, marking as read, and socket operation data.
States
- store
(ChatScreenStore)
:
The main state of the component where chat data is stored, such as messages, the last change ID, the last read time, and the socket. - text
(string)
:
The current text value of the message being typed by the user. - files
(File[])
:
An array of files that the user has attached to the message. - replyMessage
(Message | null)
:
The message that the user is replying to. - footerFocusTrigger
(boolean)
:
A trigger used to set focus on the input field in the chat footer.
Events
- submitHandler:
Message submission handler. When a message is sent, it is added to the list of messages, and if it is successfully sent, its status is changed to "sent." - pasteHandler
(ClipboardEvent)
:
Handler for pasting files from the clipboard. If files are pasted, they are added to the current array of files. - uploaderCancelHandler:
Handler for canceling file uploads. Removes attached files and resets the state. - fileInputHandler
(newFiles: File[])
:
Handler for adding files through input. Adds new files to the current array of attached files. - replyMessageHandler
(message: Message)
:
Sets the message that the user is replying to as a reply. - removeReplyMessageHandler:
Removes the reply message, resetting the current reply message. - fetchMessages:
Function to load messages from the server via API using the URL specified inscreen.chat.messages_get_url
. - fetchChanges:
Function to get message changes (e.g., new messages or changes to existing ones) via API at the URLmessages_changes_url
. - fetchLastRead:
Function to get the last read time of messages. - markAsRead
(messageId: string)
:
Sends a request to mark a message as read. - messagesSocketHandler:
WebSocket handler that is triggered when messages change (e.g., a new message or modification). - lastReadSocketHandler:
WebSocket handler that is triggered when the read status of messages changes.
WebSockets
The component connects to WebSockets to receive message changes and read status updates. These sockets are managed through the subscribeToSocket
function, which is called for each socket passed through props.screen
.