diff --git a/ts/hooks/useParamSelector.ts b/ts/hooks/useParamSelector.ts index 903e95a5f..b71b9be71 100644 --- a/ts/hooks/useParamSelector.ts +++ b/ts/hooks/useParamSelector.ts @@ -1,4 +1,5 @@ -import { compact, isEmpty, isFinite, isNumber } from 'lodash'; +import { createSelector } from '@reduxjs/toolkit'; +import { compact, isEmpty, isFinite, isNumber, pick } from 'lodash'; import { useMemo } from 'react'; import { useSelector } from 'react-redux'; import { @@ -10,8 +11,12 @@ import { CONVERSATION } from '../session/constants'; import { TimerOptions, TimerOptionsArray } from '../session/disappearing_messages/timerOptions'; import { PubKey } from '../session/types'; import { UserUtils } from '../session/utils'; +import { PropsForExpiringMessage } from '../state/ducks/conversations'; import { StateType } from '../state/reducer'; -import { getMessageExpirationProps, getMessageReactsProps } from '../state/selectors/conversations'; +import { + getMessagePropsByMessageId, + getMessageReactsProps, +} from '../state/selectors/conversations'; import { isPrivateAndFriend } from '../state/selectors/selectedConversation'; export function useAvatarPath(convoId: string | undefined) { @@ -269,6 +274,29 @@ export function useIsTyping(conversationId?: string): boolean { return useConversationPropsById(conversationId)?.isTyping || false; } +const getMessageExpirationProps = createSelector(getMessagePropsByMessageId, (props): + | PropsForExpiringMessage + | undefined => { + if (!props || isEmpty(props)) { + return undefined; + } + + const msgProps: PropsForExpiringMessage = { + ...pick(props.propsForMessage, [ + 'convoId', + 'direction', + 'receivedAt', + 'isUnread', + 'expirationTimestamp', + 'expirationDurationMs', + 'isExpired', + ]), + messageId: props.propsForMessage.id, + }; + + return msgProps; +}); + export function useMessageExpirationPropsById(messageId?: string) { return useSelector((state: StateType) => { if (!messageId) { diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 598511cbc..dc5360075 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -10,7 +10,6 @@ import { MessageModelPropsWithConvoProps, MessageModelPropsWithoutConvoProps, MessagePropsDetails, - PropsForExpiringMessage, PropsForQuote, QuoteLookupType, ReduxConversationType, @@ -872,29 +871,6 @@ export const getMessageAttachmentProps = createSelector(getMessagePropsByMessage return msgProps; }); -export const getMessageExpirationProps = createSelector(getMessagePropsByMessageId, (props): - | PropsForExpiringMessage - | undefined => { - if (!props || isEmpty(props)) { - return undefined; - } - - const msgProps: PropsForExpiringMessage = { - ...pick(props.propsForMessage, [ - 'convoId', - 'direction', - 'receivedAt', - 'isUnread', - 'expirationTimestamp', - 'expirationDurationMs', - 'isExpired', - ]), - messageId: props.propsForMessage.id, - }; - - return msgProps; -}); - export const getIsMessageSelected = createSelector( getMessagePropsByMessageId, getSelectedMessageIds,