1- import { useLayoutEffect , useState , type FC } from 'react' ;
1+ import { useLayoutEffect , useState } from 'react' ;
22import { useSelector } from 'react-redux' ;
33
44import useKey from 'react-use/lib/useKey' ;
@@ -7,43 +7,23 @@ import {
77 getOldTopMessageId ,
88 getSortedMessagesTypesOfSelectedConversation ,
99 useFocusedMessageId ,
10- type MessagePropsType ,
1110} from '../../state/selectors/conversations' ;
1211import { useSelectedConversationKey } from '../../state/selectors/selectedConversation' ;
1312import { MessageDateBreak } from './message/message-item/DateBreak' ;
14- import { CommunityInvitation } from './message/message-item/CommunityInvitation' ;
15- import { GroupUpdateMessage } from './message/message-item/GroupUpdateMessage' ;
16- import { Message } from './message/message-item/Message' ;
17- import { MessageRequestResponse } from './message/message-item/MessageRequestResponse' ;
18- import { CallNotification } from './message/message-item/notification-bubble/CallNotification' ;
1913
2014import { IsDetailMessageViewContext } from '../../contexts/isDetailViewContext' ;
2115import { SessionLastSeenIndicator } from './SessionLastSeenIndicator' ;
22- import { TimerNotification } from './TimerNotification' ;
23- import { DataExtractionNotification } from './message/message-item/DataExtractionNotification' ;
24- import { InteractionNotification } from './message/message-item/InteractionNotification' ;
25- import type { WithMessageId } from '../../session/types/with' ;
2616import { useKeyboardShortcut } from '../../hooks/useKeyboardShortcut' ;
2717import { KbdShortcut } from '../../util/keyboardShortcuts' ;
28- import { useMessageInteractions } from '../../hooks/useMessageInteractions' ;
18+ import { GenericReadableMessage } from './message/message-item/GenericReadableMessage' ;
19+ import { useCopyText , useReply } from '../../hooks/useMessageInteractions' ;
2920
3021function isNotTextboxEvent ( e : KeyboardEvent ) {
3122 return ( e ?. target as any ) ?. type === undefined ;
3223}
3324
3425let previousRenderedConvo : string | undefined ;
3526
36- const componentForMessageType : Record < MessagePropsType , FC < WithMessageId > > = {
37- 'group-notification' : GroupUpdateMessage ,
38- 'group-invitation' : CommunityInvitation ,
39- 'message-request-response' : MessageRequestResponse ,
40- 'data-extraction' : DataExtractionNotification ,
41- 'timer-notification' : TimerNotification ,
42- 'call-notification' : CallNotification ,
43- 'interaction-notification' : InteractionNotification ,
44- 'regular-message' : Message ,
45- } ;
46-
4727export const SessionMessagesList = ( props : {
4828 scrollAfterLoadMore : (
4929 messageIdToScrollTo : string ,
@@ -60,8 +40,9 @@ export const SessionMessagesList = (props: {
6040 const [ didScroll , setDidScroll ] = useState ( false ) ;
6141 const oldTopMessageId = useSelector ( getOldTopMessageId ) ;
6242 const oldBottomMessageId = useSelector ( getOldBottomMessageId ) ;
63- const focusedMessageId = useFocusedMessageId ( ) ;
64- const { reply, copyText } = useMessageInteractions ( focusedMessageId ) ;
43+ const focusedMessageId = useFocusedMessageId ( ) ?? undefined ;
44+ const reply = useReply ( focusedMessageId ) ;
45+ const copyText = useCopyText ( focusedMessageId ) ;
6546
6647 useKeyboardShortcut ( { shortcut : KbdShortcut . messageToggleReply , handler : reply , scopeId : 'all' } ) ;
6748 useKeyboardShortcut ( { shortcut : KbdShortcut . messageCopyText , handler : copyText , scopeId : 'all' } ) ;
@@ -113,8 +94,6 @@ export const SessionMessagesList = (props: {
11394 . map ( messageProps => {
11495 const { messageId } = messageProps ;
11596
116- const ComponentToRender = componentForMessageType [ messageProps . message . messageType ] ;
117-
11897 const unreadIndicator = messageProps . showUnreadIndicator ? (
11998 < SessionLastSeenIndicator
12099 key = { 'unread-indicator' }
@@ -136,7 +115,7 @@ export const SessionMessagesList = (props: {
136115 return [
137116 dateBreak ,
138117 unreadIndicator ,
139- < ComponentToRender key = { messageId } messageId = { messageId } /> ,
118+ < GenericReadableMessage key = { messageId } messageId = { messageId } /> ,
140119 ] ;
141120 } )
142121 // TODO: check if we reverse this upstream, we might be reversing twice
0 commit comments