From abf6bc780f7d506c716293a7c10d9a7fec1bd3cc Mon Sep 17 00:00:00 2001 From: Muhsin Date: Sun, 27 Dec 2020 10:21:33 +0530 Subject: [PATCH] Code beautification --- .../widget/store/modules/conversation.js | 45 +++---------------- 1 file changed, 5 insertions(+), 40 deletions(-) diff --git a/app/javascript/widget/store/modules/conversation.js b/app/javascript/widget/store/modules/conversation.js index 7d37dcdb1..9a3a5f3eb 100755 --- a/app/javascript/widget/store/modules/conversation.js +++ b/app/javascript/widget/store/modules/conversation.js @@ -9,11 +9,8 @@ import { } from 'widget/api/conversation'; import { MESSAGE_TYPE } from 'widget/helpers/constants'; import { playNotificationAudio } from 'shared/helpers/AudioNotificationHelper'; -import { formatUnixDate } from 'shared/helpers/DateHelper'; -import { isASubmittedFormMessage } from 'shared/helpers/MessageTypeHelper'; - +import { getGroupedConversation } from '../../../dashboard/helper/commons'; import getUuid from '../../helpers/uuid'; -const groupBy = require('lodash.groupby'); export const createTemporaryMessage = ({ attachments, content }) => { 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 }) => Object.values(messageInbox).filter( message => message.content === content && message.status === 'in_progress' @@ -96,14 +65,10 @@ export const getters = { return {}; }, getGroupedConversation: _state => { - const conversationGroupedByDate = groupBy( - Object.values(_state.conversations), - message => formatUnixDate(message.created_at) - ); - return Object.keys(conversationGroupedByDate).map(date => ({ - date, - messages: groupConversationBySender(conversationGroupedByDate[date]), - })); + const groupedConversationList = getGroupedConversation({ + conversations: _state.conversations, + }); + return groupedConversationList; }, getIsFetchingList: _state => _state.uiFlags.isFetchingList, getUnreadMessageCount: _state => {