refactor: moved getMessageExpirationProps

into useParamSelector since it is only called there
pull/2971/head
William Grant 2 years ago
parent 058ab3ea7e
commit 9fb67f20c2

@ -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 { useMemo } from 'react';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { import {
@ -10,8 +11,12 @@ import { CONVERSATION } from '../session/constants';
import { TimerOptions, TimerOptionsArray } from '../session/disappearing_messages/timerOptions'; import { TimerOptions, TimerOptionsArray } from '../session/disappearing_messages/timerOptions';
import { PubKey } from '../session/types'; import { PubKey } from '../session/types';
import { UserUtils } from '../session/utils'; import { UserUtils } from '../session/utils';
import { PropsForExpiringMessage } from '../state/ducks/conversations';
import { StateType } from '../state/reducer'; 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'; import { isPrivateAndFriend } from '../state/selectors/selectedConversation';
export function useAvatarPath(convoId: string | undefined) { export function useAvatarPath(convoId: string | undefined) {
@ -269,6 +274,29 @@ export function useIsTyping(conversationId?: string): boolean {
return useConversationPropsById(conversationId)?.isTyping || false; 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) { export function useMessageExpirationPropsById(messageId?: string) {
return useSelector((state: StateType) => { return useSelector((state: StateType) => {
if (!messageId) { if (!messageId) {

@ -10,7 +10,6 @@ import {
MessageModelPropsWithConvoProps, MessageModelPropsWithConvoProps,
MessageModelPropsWithoutConvoProps, MessageModelPropsWithoutConvoProps,
MessagePropsDetails, MessagePropsDetails,
PropsForExpiringMessage,
PropsForQuote, PropsForQuote,
QuoteLookupType, QuoteLookupType,
ReduxConversationType, ReduxConversationType,
@ -872,29 +871,6 @@ export const getMessageAttachmentProps = createSelector(getMessagePropsByMessage
return msgProps; 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( export const getIsMessageSelected = createSelector(
getMessagePropsByMessageId, getMessagePropsByMessageId,
getSelectedMessageIds, getSelectedMessageIds,

Loading…
Cancel
Save