From 39ee5737b7aa84833a1dc5b03c492b46e22209bd Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Mon, 30 Jan 2017 11:49:00 -0500 Subject: PLT-2555/PLT-5009/PLT-5225 Changed system messages to be rendered by the client (#5209) * Moved rendering of (message deleted) into PostMessageView * Added additional post types to constants on client * Changed system messages to be rendered in the client's language * Updated new system messages to have relevant usernames highlighted and have markdown rendered in header change messages --- .../components/post_view/components/post_body.jsx | 18 +- .../post_view/components/post_message_view.jsx | 57 ++++-- .../components/system_message_helpers.jsx | 228 +++++++++++++++++++++ webapp/components/rhs_comment.jsx | 10 +- webapp/components/rhs_root_post.jsx | 3 +- 5 files changed, 276 insertions(+), 40 deletions(-) create mode 100644 webapp/components/post_view/components/system_message_helpers.jsx (limited to 'webapp/components') diff --git a/webapp/components/post_view/components/post_body.jsx b/webapp/components/post_view/components/post_body.jsx index e690b3702..8b650423f 100644 --- a/webapp/components/post_view/components/post_body.jsx +++ b/webapp/components/post_view/components/post_body.jsx @@ -156,22 +156,6 @@ export default class PostBody extends React.Component { ); } - let message; - if (this.props.post.state === Constants.POST_DELETED) { - message = ( -

- -

- ); - } else { - message = ( - - ); - } - const messageWrapper = (
{loading} - {message} +
); diff --git a/webapp/components/post_view/components/post_message_view.jsx b/webapp/components/post_view/components/post_message_view.jsx index eff791aec..371dd64eb 100644 --- a/webapp/components/post_view/components/post_message_view.jsx +++ b/webapp/components/post_view/components/post_message_view.jsx @@ -4,9 +4,12 @@ import React from 'react'; import {FormattedMessage} from 'react-intl'; +import Constants from 'utils/constants.jsx'; +import * as PostUtils from 'utils/post_utils.jsx'; import * as TextFormatting from 'utils/text_formatting.jsx'; import * as Utils from 'utils/utils.jsx'; -import * as PostUtils from 'utils/post_utils.jsx'; + +import {renderSystemMessage} from './system_message_helpers.jsx'; export default class PostMessageView extends React.Component { static propTypes = { @@ -29,6 +32,14 @@ export default class PostMessageView extends React.Component { return true; } + if (nextProps.post.state !== this.props.post.state) { + return true; + } + + if (nextProps.post.type !== this.props.post.type) { + return true; + } + // emojis are immutable if (nextProps.emojis !== this.props.emojis) { return true; @@ -49,26 +60,43 @@ export default class PostMessageView extends React.Component { return false; } - editedIndicator() { + renderDeletedPost() { return ( - PostUtils.isEdited(this.props.post) ? - - - : - '' +

+ +

+ ); + } + + renderEditedIndicator() { + if (!PostUtils.isEdited(this.props.post)) { + return null; + } + + return ( + + + ); } render() { + if (this.props.post.state === Constants.POST_DELETED) { + return this.renderDeletedPost(); + } + if (!this.props.enableFormatting) { return ( {this.props.post.message}   - {this.editedIndicator()} + {this.renderEditedIndicator()} ); } @@ -82,13 +110,18 @@ export default class PostMessageView extends React.Component { team: this.props.team }); + const renderedSystemMessage = renderSystemMessage(this.props.post, options); + if (renderedSystemMessage) { + return
{renderedSystemMessage}
; + } + return (
- {this.editedIndicator()} + {this.renderEditedIndicator()}
); } diff --git a/webapp/components/post_view/components/system_message_helpers.jsx b/webapp/components/post_view/components/system_message_helpers.jsx new file mode 100644 index 000000000..6f6454599 --- /dev/null +++ b/webapp/components/post_view/components/system_message_helpers.jsx @@ -0,0 +1,228 @@ +// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import React from 'react'; +import {FormattedMessage} from 'react-intl'; + +import {PostTypes} from 'utils/constants.jsx'; +import {formatText} from 'utils/text_formatting.jsx'; + +function renderFormattedText(value, options) { + return ; +} + +function renderJoinChannelMessage(post, options) { + const username = renderFormattedText(post.props.username, options); + + return ( + + ); +} + +function renderLeaveChannelMessage(post, options) { + const username = renderFormattedText(post.props.username, options); + + return ( + + ); +} + +function renderAddToChannelMessage(post, options) { + const username = renderFormattedText(post.props.username, options); + const addedUsername = renderFormattedText(post.props.addedUsername, options); + + return ( + + ); +} + +function renderRemoveFromChannelMessage(post, options) { + const removedUsername = renderFormattedText(post.props.removedUsername, options); + + return ( + + ); +} + +function renderHeaderChangeMessage(post, options) { + if (!post.props.username) { + return null; + } + + const headerOptions = { + ...options, + singleline: true + }; + + const username = renderFormattedText(post.props.username, options); + const oldHeader = post.props.old_header ? renderFormattedText(post.props.old_header, headerOptions) : null; + const newHeader = post.props.new_header ? renderFormattedText(post.props.new_header, headerOptions) : null; + + if (post.props.new_header) { + if (post.props.old_header) { + return ( + + ); + } + + return ( + + ); + } else if (post.props.old_header) { + return ( + + ); + } + + return null; +} + +function renderDisplayNameChangeMessage(post, options) { + if (!(post.props.username && post.props.old_displayname && post.props.new_displayname)) { + return null; + } + + const username = renderFormattedText(post.props.username, options); + const oldDisplayName = post.props.old_displayname; + const newDisplayName = post.props.new_displayname; + + return ( + + ); +} + +function renderPurposeChangeMessage(post, options) { + if (!post.props.username) { + return null; + } + + const username = renderFormattedText(post.props.username, options); + const oldPurpose = post.props.old_purpose; + const newPurpose = post.props.new_purpose; + + if (post.props.new_purpose) { + if (post.props.old_purpose) { + return ( + + ); + } + + return ( + + ); + } else if (post.props.old_purpose) { + return ( + + ); + } + + return null; +} + +function renderChannelDeletedMessage(post, options) { + if (!post.props.username) { + return null; + } + + const username = renderFormattedText(post.props.username, options); + + return ( + + ); +} + +const systemMessageRenderers = { + [PostTypes.JOIN_CHANNEL]: renderJoinChannelMessage, + [PostTypes.LEAVE_CHANNEL]: renderLeaveChannelMessage, + [PostTypes.ADD_TO_CHANNEL]: renderAddToChannelMessage, + [PostTypes.REMOVE_FROM_CHANNEL]: renderRemoveFromChannelMessage, + [PostTypes.HEADER_CHANGE]: renderHeaderChangeMessage, + [PostTypes.DISPLAYNAME_CHANGE]: renderDisplayNameChangeMessage, + [PostTypes.PURPOSE_CHANGE]: renderPurposeChangeMessage, + [PostTypes.CHANNEL_DELETED]: renderChannelDeletedMessage +}; + +export function renderSystemMessage(post, options) { + if (!systemMessageRenderers[post.type]) { + return null; + } + + return systemMessageRenderers[post.type](post, options); +} diff --git a/webapp/components/rhs_comment.jsx b/webapp/components/rhs_comment.jsx index 26659c7a1..0eb7717b3 100644 --- a/webapp/components/rhs_comment.jsx +++ b/webapp/components/rhs_comment.jsx @@ -294,7 +294,6 @@ export default class RhsComment extends React.Component { let loading; let postClass = ''; - let message = ; if (post.state === Constants.POST_FAILED) { postClass += ' post-fail'; @@ -307,13 +306,6 @@ export default class RhsComment extends React.Component { src={loadingGif} /> ); - } else if (this.props.post.state === Constants.POST_DELETED) { - message = ( - - ); } let systemMessageClass = ''; @@ -491,7 +483,7 @@ export default class RhsComment extends React.Component {
{loading} - {message} +
{fileAttachment} {profilePic}
); - const messageWrapper = ; let flag; let flagFunc; @@ -445,7 +444,7 @@ export default class RhsRootPost extends React.Component {
} previewCollapsed={this.props.previewCollapsed} /> {fileAttachment} -- cgit v1.2.3-1-g7c22