Skip to content

Commit ee43cde

Browse files
committed
perf: optimize channel ctx usage in message
1 parent 857fb68 commit ee43cde

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

package/src/components/Message/Message.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,12 @@ export type MessagePropsWithContext = Pick<
135135
> &
136136
Pick<KeyboardContextValue, 'dismissKeyboard'> &
137137
Partial<
138-
Omit<MessageContextValue, 'groupStyles' | 'handleReaction' | 'message' | 'isMessageAIGenerated'>
138+
Omit<
139+
MessageContextValue,
140+
'groupStyles' | 'handleReaction' | 'message' | 'isMessageAIGenerated' | 'readBy'
141+
>
139142
> &
140-
Pick<MessageContextValue, 'groupStyles' | 'message' | 'isMessageAIGenerated'> &
143+
Pick<MessageContextValue, 'groupStyles' | 'message' | 'isMessageAIGenerated' | 'readBy'> &
141144
Pick<
142145
MessagesContextValue,
143146
| 'sendReaction'
@@ -262,8 +265,8 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
262265
t,
263266
threadList = false,
264267
updateMessage,
268+
readBy,
265269
} = props;
266-
const { read } = useChannelContext();
267270
const isMessageAIGenerated = messagesContext.isMessageAIGenerated;
268271
const isAIGenerated = useMemo(
269272
() => isMessageAIGenerated(message),
@@ -278,7 +281,6 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
278281
screenPadding,
279282
},
280283
} = useTheme();
281-
const readBy = useMemo(() => getReadState(message, read), [message, read]);
282284

283285
const showMessageOverlay = async (showMessageReactions = false, selectedReaction?: string) => {
284286
await dismissKeyboard();
@@ -925,12 +927,14 @@ export type MessageProps = Partial<
925927
* @example ./Message.md
926928
*/
927929
export const Message = (props: MessageProps) => {
928-
const { channel, enforceUniqueReaction, members } = useChannelContext();
930+
const { message } = props;
931+
const { channel, enforceUniqueReaction, members, read } = useChannelContext();
929932
const chatContext = useChatContext();
930933
const { dismissKeyboard } = useKeyboardContext();
931934
const messagesContext = useMessagesContext();
932935
const { openThread } = useThreadContext();
933936
const { t } = useTranslationContext();
937+
const readBy = useMemo(() => getReadState(message, read), [message, read]);
934938

935939
return (
936940
<MemoizedMessage
@@ -943,6 +947,7 @@ export const Message = (props: MessageProps) => {
943947
members,
944948
messagesContext,
945949
openThread,
950+
readBy,
946951
t,
947952
}}
948953
{...props}

0 commit comments

Comments
 (0)