summaryrefslogtreecommitdiffstats
path: root/webapp/components/post_view
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-05-01 23:08:54 +0900
committerHarrison Healey <harrisonmhealey@gmail.com>2017-05-01 10:08:54 -0400
commit83f819451a80a767170b927eb2f0d5ed63f03239 (patch)
treed1a5e0ff5078c12c7c292e6ad9123c0e5bc4fb4e /webapp/components/post_view
parent597641545d1be04a1ba6c0b2d35c75fc2cfc8737 (diff)
downloadchat-83f819451a80a767170b927eb2f0d5ed63f03239.tar.gz
chat-83f819451a80a767170b927eb2f0d5ed63f03239.tar.bz2
chat-83f819451a80a767170b927eb2f0d5ed63f03239.zip
[GH-5915] Clicking on @mention of a user in a post shows the profile popover (#6129)
* post message at-mention profile pop-over * remove hover effect to special mentions * make non-clickable the non-existing at-mention username * fix "video call" position * use usernameMap instead of initially defined liteUsernameMap * update per comments
Diffstat (limited to 'webapp/components/post_view')
-rw-r--r--webapp/components/post_view/components/post.jsx2
-rw-r--r--webapp/components/post_view/components/post_header.jsx2
-rw-r--r--webapp/components/post_view/components/post_message_view.jsx40
3 files changed, 41 insertions, 3 deletions
diff --git a/webapp/components/post_view/components/post.jsx b/webapp/components/post_view/components/post.jsx
index f5c96d2bc..cf25b28e4 100644
--- a/webapp/components/post_view/components/post.jsx
+++ b/webapp/components/post_view/components/post.jsx
@@ -3,7 +3,7 @@
import PostHeader from './post_header.jsx';
import PostBody from './post_body.jsx';
-import ProfilePicture from 'components/profile_picture.jsx';
+import ProfilePicture from 'components/profile_popover/picture_profile_popover.jsx';
import Constants from 'utils/constants.jsx';
const ActionTypes = Constants.ActionTypes;
diff --git a/webapp/components/post_view/components/post_header.jsx b/webapp/components/post_view/components/post_header.jsx
index 9de0b7e79..e19285963 100644
--- a/webapp/components/post_view/components/post_header.jsx
+++ b/webapp/components/post_view/components/post_header.jsx
@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
-import UserProfile from 'components/user_profile.jsx';
+import UserProfile from 'components/profile_popover/username_profile_popover.jsx';
import PostInfo from './post_info.jsx';
import {FormattedMessage} from 'react-intl';
diff --git a/webapp/components/post_view/components/post_message_view.jsx b/webapp/components/post_view/components/post_message_view.jsx
index 5b0790f36..db522c974 100644
--- a/webapp/components/post_view/components/post_message_view.jsx
+++ b/webapp/components/post_view/components/post_message_view.jsx
@@ -3,6 +3,9 @@
import React from 'react';
import {FormattedMessage} from 'react-intl';
+import {Parser, ProcessNodeDefinitions} from 'html-to-react';
+
+import AtMentionProfile from 'components/profile_popover/atmention_profile_popover.jsx';
import Constants from 'utils/constants.jsx';
import * as PostUtils from 'utils/post_utils.jsx';
@@ -88,6 +91,38 @@ export default class PostMessageView extends React.Component {
);
}
+ postMessageHtmlToComponent(html) {
+ const parser = new Parser();
+ const attrib = 'data-mention';
+ const processNodeDefinitions = new ProcessNodeDefinitions(React);
+
+ function isValidNode() {
+ return true;
+ }
+
+ const processingInstructions = [
+ {
+ replaceChildren: true,
+ shouldProcessNode: (node) => node.attribs && node.attribs[attrib] && this.props.usernameMap.hasOwnProperty(node.attribs[attrib]),
+ processNode: (node) => {
+ const username = node.attribs[attrib];
+ return (
+ <AtMentionProfile
+ user={this.props.usernameMap[username]}
+ username={username}
+ />
+ );
+ }
+ },
+ {
+ shouldProcessNode: () => true,
+ processNode: processNodeDefinitions.processDefaultNode
+ }
+ ];
+
+ return parser.parseWithInstructions(html, isValidNode, processingInstructions);
+ }
+
render() {
if (this.props.post.state === Constants.POST_DELETED) {
return this.renderDeletedPost();
@@ -111,14 +146,17 @@ export default class PostMessageView extends React.Component {
return <div>{renderedSystemMessage}</div>;
}
+ const htmlFormattedText = TextFormatting.formatText(this.props.post.message, options);
+ const postMessageComponent = this.postMessageHtmlToComponent(htmlFormattedText);
+
return (
<div>
<span
id={this.props.isLastPost ? 'lastPostMessageText' : null}
className='post-message__text'
onClick={Utils.handleFormattedTextClick}
- dangerouslySetInnerHTML={{__html: TextFormatting.formatText(this.props.post.message, options)}}
/>
+ {postMessageComponent}
{this.renderEditedIndicator()}
</div>
);