41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
|
import { isASubmittedFormMessage } from 'shared/helpers/MessageTypeHelper';
|
||
|
|
||
|
const getSenderName = message => (message.sender ? message.sender.name : '');
|
||
|
|
||
|
const shouldShowAvatar = (message, nextMessage) => {
|
||
|
const currentSender = getSenderName(message);
|
||
|
const nextSender = getSenderName(nextMessage);
|
||
|
|
||
|
return (
|
||
|
currentSender !== nextSender ||
|
||
|
message.message_type !== nextMessage.message_type ||
|
||
|
isASubmittedFormMessage(nextMessage)
|
||
|
);
|
||
|
};
|
||
|
|
||
|
export const groupConversationBySender = conversationsForADate =>
|
||
|
conversationsForADate.map((message, index) => {
|
||
|
let showAvatar = false;
|
||
|
const isLastMessage = index === conversationsForADate.length - 1;
|
||
|
if (isASubmittedFormMessage(message)) {
|
||
|
showAvatar = false;
|
||
|
} else if (isLastMessage) {
|
||
|
showAvatar = true;
|
||
|
} else {
|
||
|
const nextMessage = conversationsForADate[index + 1];
|
||
|
showAvatar = shouldShowAvatar(message, nextMessage);
|
||
|
}
|
||
|
return { showAvatar, ...message };
|
||
|
});
|
||
|
|
||
|
export const findUndeliveredMessage = (messageInbox, { content }) =>
|
||
|
Object.values(messageInbox).filter(
|
||
|
message => message.content === content && message.status === 'in_progress'
|
||
|
);
|
||
|
|
||
|
export const getNonDeletedMessages = ({ messages }) => {
|
||
|
return messages.filter(
|
||
|
item => !(item.content_attributes && item.content_attributes.deleted)
|
||
|
);
|
||
|
};
|