Code beautification
This commit is contained in:
parent
0c68403cf0
commit
abf6bc780f
1 changed files with 5 additions and 40 deletions
|
@ -9,11 +9,8 @@ import {
|
||||||
} from 'widget/api/conversation';
|
} from 'widget/api/conversation';
|
||||||
import { MESSAGE_TYPE } from 'widget/helpers/constants';
|
import { MESSAGE_TYPE } from 'widget/helpers/constants';
|
||||||
import { playNotificationAudio } from 'shared/helpers/AudioNotificationHelper';
|
import { playNotificationAudio } from 'shared/helpers/AudioNotificationHelper';
|
||||||
import { formatUnixDate } from 'shared/helpers/DateHelper';
|
import { getGroupedConversation } from '../../../dashboard/helper/commons';
|
||||||
import { isASubmittedFormMessage } from 'shared/helpers/MessageTypeHelper';
|
|
||||||
|
|
||||||
import getUuid from '../../helpers/uuid';
|
import getUuid from '../../helpers/uuid';
|
||||||
const groupBy = require('lodash.groupby');
|
|
||||||
|
|
||||||
export const createTemporaryMessage = ({ attachments, content }) => {
|
export const createTemporaryMessage = ({ attachments, content }) => {
|
||||||
const timestamp = new Date().getTime() / 1000;
|
const timestamp = new Date().getTime() / 1000;
|
||||||
|
@ -27,34 +24,6 @@ export const createTemporaryMessage = ({ attachments, content }) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
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)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
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 }) =>
|
export const findUndeliveredMessage = (messageInbox, { content }) =>
|
||||||
Object.values(messageInbox).filter(
|
Object.values(messageInbox).filter(
|
||||||
message => message.content === content && message.status === 'in_progress'
|
message => message.content === content && message.status === 'in_progress'
|
||||||
|
@ -96,14 +65,10 @@ export const getters = {
|
||||||
return {};
|
return {};
|
||||||
},
|
},
|
||||||
getGroupedConversation: _state => {
|
getGroupedConversation: _state => {
|
||||||
const conversationGroupedByDate = groupBy(
|
const groupedConversationList = getGroupedConversation({
|
||||||
Object.values(_state.conversations),
|
conversations: _state.conversations,
|
||||||
message => formatUnixDate(message.created_at)
|
});
|
||||||
);
|
return groupedConversationList;
|
||||||
return Object.keys(conversationGroupedByDate).map(date => ({
|
|
||||||
date,
|
|
||||||
messages: groupConversationBySender(conversationGroupedByDate[date]),
|
|
||||||
}));
|
|
||||||
},
|
},
|
||||||
getIsFetchingList: _state => _state.uiFlags.isFetchingList,
|
getIsFetchingList: _state => _state.uiFlags.isFetchingList,
|
||||||
getUnreadMessageCount: _state => {
|
getUnreadMessageCount: _state => {
|
||||||
|
|
Loading…
Reference in a new issue