1- import React from 'react' ;
1+ import React , { useCallback } from 'react' ;
22
33import { View } from 'react-native' ;
44
@@ -14,6 +14,7 @@ import { ThemeProvider, useTheme } from '../../../contexts/themeContext/ThemeCon
1414
1515import { useStateStore } from '../../../hooks/useStateStore' ;
1616import { ChannelUnreadStateStoreType } from '../../../state-store/channel-unread-state' ;
17+ import { MessagePreviousAndNextMessageStoreType } from '../../../state-store/message-list-prev-next-state' ;
1718
1819const channelUnreadStateSelector = ( state : ChannelUnreadStateStoreType ) => ( {
1920 first_unread_message_id : state . channelUnreadState ?. first_unread_message_id ,
@@ -23,12 +24,11 @@ const channelUnreadStateSelector = (state: ChannelUnreadStateStoreType) => ({
2324} ) ;
2425
2526export type MessageWrapperProps = {
26- isNewestMessage ?: boolean ;
2727 message : LocalMessage ;
2828} ;
2929
3030export const MessageWrapper = ( props : MessageWrapperProps ) => {
31- const { isNewestMessage , message } = props ;
31+ const { message } = props ;
3232 const { client } = useChatContext ( ) ;
3333 const {
3434 channelUnreadStateStore,
@@ -61,6 +61,14 @@ export const MessageWrapper = (props: MessageWrapperProps) => {
6161 messageListPreviousAndNextMessageStore,
6262 } ) ;
6363
64+ const selector = useCallback (
65+ ( state : MessagePreviousAndNextMessageStoreType ) => ( {
66+ nextMessage : state . messageList [ message . id ] ?. nextMessage ,
67+ } ) ,
68+ [ message . id ] ,
69+ ) ;
70+ const { nextMessage } = useStateStore ( messageListPreviousAndNextMessageStore . state , selector ) ;
71+ const isNewestMessage = nextMessage === undefined ;
6472 const groupStyles = useMessageGroupStyles ( {
6573 dateSeparatorDate,
6674 getMessageGroupStyle,
0 commit comments