chore: cleanup message list component to render switch

pull/3281/head
Audric Ackermann 10 months ago
parent d4cae6e5b2
commit bc680a39f6
No known key found for this signature in database

@ -6,6 +6,7 @@ import {
getOldBottomMessageId, getOldBottomMessageId,
getOldTopMessageId, getOldTopMessageId,
getSortedMessagesTypesOfSelectedConversation, getSortedMessagesTypesOfSelectedConversation,
type MessagePropsType,
} from '../../state/selectors/conversations'; } from '../../state/selectors/conversations';
import { useSelectedConversationKey } from '../../state/selectors/selectedConversation'; import { useSelectedConversationKey } from '../../state/selectors/selectedConversation';
import { MessageDateBreak } from './message/message-item/DateBreak'; import { MessageDateBreak } from './message/message-item/DateBreak';
@ -20,7 +21,6 @@ import { SessionLastSeenIndicator } from './SessionLastSeenIndicator';
import { TimerNotification } from './TimerNotification'; import { TimerNotification } from './TimerNotification';
import { DataExtractionNotification } from './message/message-item/DataExtractionNotification'; import { DataExtractionNotification } from './message/message-item/DataExtractionNotification';
import { InteractionNotification } from './message/message-item/InteractionNotification'; import { InteractionNotification } from './message/message-item/InteractionNotification';
import { assertUnreachable } from '../../types/sqlSharedTypes';
import type { WithMessageId } from '../../session/types/with'; import type { WithMessageId } from '../../session/types/with';
function isNotTextboxEvent(e: KeyboardEvent) { function isNotTextboxEvent(e: KeyboardEvent) {
@ -29,6 +29,17 @@ function isNotTextboxEvent(e: KeyboardEvent) {
let previousRenderedConvo: string | undefined; let previousRenderedConvo: string | undefined;
const componentForMessageType: Record<MessagePropsType, React.FC<WithMessageId>> = {
'group-notification': GroupUpdateMessage,
'group-invitation': CommunityInvitation,
'message-request-response': MessageRequestResponse,
'data-extraction': DataExtractionNotification,
'timer-notification': TimerNotification,
'call-notification': CallNotification,
'interaction-notification': InteractionNotification,
'regular-message': Message,
};
export const SessionMessagesList = (props: { export const SessionMessagesList = (props: {
scrollAfterLoadMore: ( scrollAfterLoadMore: (
messageIdToScrollTo: string, messageIdToScrollTo: string,
@ -92,47 +103,7 @@ export const SessionMessagesList = (props: {
{messagesProps.map(messageProps => { {messagesProps.map(messageProps => {
const { messageId } = messageProps; const { messageId } = messageProps;
let ComponentToRender: React.FC<WithMessageId> | undefined; const ComponentToRender = componentForMessageType[messageProps.message.messageType];
switch (messageProps.message.messageType) {
case 'group-notification': {
ComponentToRender = GroupUpdateMessage;
break;
}
case 'group-invitation': {
ComponentToRender = CommunityInvitation;
break;
}
case 'message-request-response': {
ComponentToRender = MessageRequestResponse;
break;
}
case 'data-extraction': {
ComponentToRender = DataExtractionNotification;
break;
}
case 'timer-notification': {
ComponentToRender = TimerNotification;
break;
}
case 'call-notification': {
ComponentToRender = CallNotification;
break;
}
case 'interaction-notification': {
ComponentToRender = InteractionNotification;
break;
}
case 'regular-message': {
ComponentToRender = Message;
break;
}
default:
assertUnreachable(
messageProps.message.messageType,
`unhandled case with ${messageProps.message.messageType}`
);
}
const unreadIndicator = messageProps.showUnreadIndicator ? ( const unreadIndicator = messageProps.showUnreadIndicator ? (
<SessionLastSeenIndicator <SessionLastSeenIndicator

@ -112,7 +112,6 @@ export type MessagePropsType =
| 'message-request-response' | 'message-request-response'
| 'timer-notification' | 'timer-notification'
| 'regular-message' | 'regular-message'
| 'unread-indicator'
| 'call-notification' | 'call-notification'
| 'interaction-notification'; | 'interaction-notification';
@ -145,7 +144,7 @@ export const getSortedMessagesTypesOfSelectedConversation = createSelector(
messageId: msg.propsForMessage.id, messageId: msg.propsForMessage.id,
}; };
const messageType = msg.propsForDataExtractionNotification const messageType: MessagePropsType = msg.propsForDataExtractionNotification
? ('data-extraction' as const) ? ('data-extraction' as const)
: msg.propsForMessageRequestResponse : msg.propsForMessageRequestResponse
? ('message-request-response' as const) ? ('message-request-response' as const)

Loading…
Cancel
Save