From 8a91235fb3cdc8d094dbc2eaa0d7baa447132b3c Mon Sep 17 00:00:00 2001 From: Debanshu Kundu Date: Mon, 31 Jul 2017 23:47:21 +0530 Subject: #4755 Combining consecutive user join/leave system messages to single message and few other changes. (#5945) fix 7 and 8 remove @ at "{username} joined the channel" refactor and update test --- .../post_message_view/system_message_helpers.jsx | 51 ++++++++++++++++++---- webapp/i18n/en.json | 8 ++-- 2 files changed, 46 insertions(+), 13 deletions(-) (limited to 'webapp') diff --git a/webapp/components/post_view/post_message_view/system_message_helpers.jsx b/webapp/components/post_view/post_message_view/system_message_helpers.jsx index c134e1a7a..c215ddb59 100644 --- a/webapp/components/post_view/post_message_view/system_message_helpers.jsx +++ b/webapp/components/post_view/post_message_view/system_message_helpers.jsx @@ -7,6 +7,13 @@ import {FormattedMessage} from 'react-intl'; import {PostTypes} from 'utils/constants.jsx'; import {formatText} from 'utils/text_formatting.jsx'; +const joinLeaveMessageGetters = { + [PostTypes.JOIN_CHANNEL]: getJoinChannelMessage, + [PostTypes.LEAVE_CHANNEL]: getLeaveChannelMessage, + [PostTypes.ADD_TO_CHANNEL]: getAddToChannelMessage, + [PostTypes.REMOVE_FROM_CHANNEL]: getRemoveFromChannelMessage +}; + function renderUsername(value, options) { return renderFormattedText(value, {...options, markdown: false}); } @@ -15,38 +22,60 @@ function renderFormattedText(value, options) { return ; } +function renderJoinLeaveMessage(post, options, messageFunction) { + if (post.props.messages) { + return ( +
+ {post.props.messages.map((message, key) => {joinLeaveMessageGetters[message.type](message, options)})} +
+ ); + } + return messageFunction(post.props, options); +} + function renderJoinChannelMessage(post, options) { - const username = renderUsername(post.props.username, options); + return renderJoinLeaveMessage(post, options, getJoinChannelMessage); +} + +function getJoinChannelMessage(messageProps, options) { + const username = renderUsername(messageProps.username, options); return ( ); } function renderLeaveChannelMessage(post, options) { - const username = renderUsername(post.props.username, options); + return renderJoinLeaveMessage(post, options, getLeaveChannelMessage); +} + +function getLeaveChannelMessage(messageProps, options) { + const username = renderUsername(messageProps.username, options); return ( ); } function renderAddToChannelMessage(post, options) { - const username = renderUsername(post.props.username, options); - const addedUsername = renderUsername(post.props.addedUsername, options); + return renderJoinLeaveMessage(post, options, getAddToChannelMessage); +} +function getAddToChannelMessage(messageProps, options) { + const username = renderUsername(messageProps.username, options); + const addedUsername = renderUsername(messageProps.addedUsername, options); return (