MessageContext
MessageContext
is provided by Message
component. If you are not familiar with React Context API, please read about it on React docs.
#
Basic UsageMessageContext
can be consumed by any of the child component of Message
component as following:
import { useContext } from 'react';
import { MessageContext } from 'stream-chat-react-native';
const { isMyMessage, message, files } = useContext(MessageContext);
Alternatively, you can also use useMessageContext
hook provided by library to consume MessageContext.
import { useMessageContext } from 'stream-chat-react-native';
const { isMyMessage, message, files } = useMessageContext();
#
ValueactionsEnabled
#
This value gets set to true when following condition is true:
message.type === 'regular' && message.status === 'received';
Type |
---|
boolean |
#
alignmentSets if the message should be aligned to right or left side of list.
Type | Default |
---|---|
enum('right', 'left') | 'right' |
#
canModifyMessageTrue if one of the following condition is true:
- message is sent by the current user (connected to chat)
- current user has
admin
role - current user has
moderator
role
Type |
---|
boolean |
#
disabledTrue if channel is frozen and disableIfFrozenChannel is true.
Type |
---|
boolean |
#
filesArray of file
type attachments to be shown in the grouped UI component.
const files = message.attachments.filter(a => a.type === 'file');
Type |
---|
array |
groupStyles
#
Position of message in the group. A message group is a group of consecutive messages from the same user. groupStyles
can be used to style the message as per their position in message group.
for example user avatar (to which message belongs to) is only showed for last (bottom) message in group.
Type |
---|
array of enum('top', 'bottom', 'middle', 'single') |
handleAction
#
Function to send an attachment action on message. For example, in case of giphy
type attachments, there are 3 actions available - Shuffle, Cancel, Send.
Type |
---|
(name: string, value: string) => Promise |
#
handleDeleteMessageCallback function for "Delete Message" action.
Type |
---|
function |
#
handleEditMessageCallback function for "Edit Message" action.
Type |
---|
function |
#
handleQuotedReplyMessageCallback function for "Quoted Reply" action.
Type |
---|
function |
#
handleResendMessageCallback function for "Resend Message" (for failed message) action.
Type |
---|
function |
#
handleToggleBanUserCallback function for "Ban/Unban User" action.
Type |
---|
function |
#
handleToggleMuteUserCallback function for "Mute/Unmute User" action.
Type |
---|
function |
#
handleToggleReactionCallback function for toggling reaction from reaction selector.
Type |
---|
(reactionType: string) => void |
#
hasReactionsTrue if the message has at least 1 reaction.
Type |
---|
boolean |
#
imagesArray of image
type attachments on message.
const images = message.attachments.filter(a => a.type === 'image');
Type |
---|
array |
#
isMyMessageTrue if the message is sent by current user (connected to chat).
Type |
---|
boolean |
#
lastGroupMessageWhether or not this is the last message in a group of messages.
Type |
---|
boolean |
#
lastReceivedIdMost recent message id in the message list.
Type |
---|
string |
#
messageMessage object
Type |
---|
object |
#
messageContentOrderOrder of message content.
for example ['quoted_reply', 'attachments', 'file', 'gallery', 'text']
Type |
---|
array |
#
onLongPressDefault long press handler for message UI.
Type |
---|
function |
onlyEmojis
#
True if the message text only contains emojis and nothing else.
Type |
---|
boolean |
#
onOpenThreadHandler function for "Thread Reply" action.
Type |
---|
function |
onPress
#
Default press handler for message UI.
Type |
---|
function |
#
onPressInDefault pressIn
handler for message UI.
Type |
---|
function |
otherAttachments
#
All the attachments on the message except for types file
and image
.
Type |
---|
array |
#
reactionsList of reactions added to the message.
[
{
own: true,
type: 'love',
},
{
own: false,
type: 'haha',
},
];
Type |
---|
array |
#
readEventsEnabledEnable read receipts. The default value is supplied by the channel config.
Type |
---|
boolean |
#
showMessageOverlayFunction to open the message action overlay. This function gets called when user long presses a message.
Type |
---|
function |
#
showMessageStatusWhen false, message status (read receipt, pending state indicator) won't be rendered. By default, this value is true for messages sent by current user of chat.
Type |
---|
boolean |
threadList
#
True if current message is part of a message thread.
Type |
---|
boolean |