1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import PostHeader from 'components/post_view/post_header';
import PostBody from 'components/post_view/post_body';
import ProfilePicture from 'components/profile_picture.jsx';
import Constants from 'utils/constants.jsx';
const ActionTypes = Constants.ActionTypes;
import {Posts} from 'mattermost-redux/constants';
import * as Utils from 'utils/utils.jsx';
import * as PostUtils from 'utils/post_utils.jsx';
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import React from 'react';
import PropTypes from 'prop-types';
export default class Post extends React.PureComponent {
static propTypes = {
/**
* The post to render
*/
post: PropTypes.object.isRequired,
/**
* The user who created the post
*/
user: PropTypes.object,
/**
* The status of the poster
*/
status: PropTypes.string,
/**
* The logged in user
*/
currentUser: PropTypes.object.isRequired,
/**
* Set to center the post
*/
center: PropTypes.bool,
/**
* Set to render post compactly
*/
compactDisplay: PropTypes.bool,
/**
* Set to render a preview of the parent post above this reply
*/
isFirstReply: PropTypes.bool,
/**
* Set to highlight the background of the post
*/
highlight: PropTypes.bool,
/**
* Set to render this post as if it was attached to the previous post
*/
consecutivePostByUser: PropTypes.bool,
/**
* Set if the previous post is a comment
*/
previousPostIsComment: PropTypes.bool,
/**
* Set to render this comment as a mention
*/
isCommentMention: PropTypes.bool,
/**
* The number of replies in the same thread as this post
*/
replyCount: PropTypes.number,
/**
* Set to mark the poster as in a webrtc call
*/
isBusy: PropTypes.bool,
/**
* The post count used for selenium tests
*/
lastPostCount: PropTypes.number,
/**
* Function to get the post list HTML element
*/
getPostList: PropTypes.func.isRequired
}
constructor(props) {
super(props);
this.state = {
dropdownOpened: false
};
}
handleCommentClick = (e) => {
e.preventDefault();
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_POST_SELECTED,
postId: Utils.getRootId(this.props.post)
});
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_SEARCH,
results: null
});
}
handleDropdownOpened = (opened) => {
this.setState({
dropdownOpened: opened
});
}
forceUpdateInfo = () => {
this.refs.info.forceUpdate();
this.refs.header.forceUpdate();
}
getClassName = (post, isSystemMessage, fromWebhook) => {
let className = 'post';
if (post.failed || post.state === Posts.POST_DELETED) {
className += ' post--hide-controls';
}
if (this.props.highlight) {
className += ' post--highlight';
}
let rootUser = '';
if (this.props.isFirstReply) {
rootUser = 'other--root';
} else if (!post.root_id && !this.props.previousPostIsComment && this.props.consecutivePostByUser) {
rootUser = 'same--root';
} else if (post.root_id) {
rootUser = 'same--root';
} else {
rootUser = 'other--root';
}
let currentUserCss = '';
if (this.props.currentUser.id === post.user_id && !fromWebhook && !isSystemMessage) {
currentUserCss = 'current--user';
}
let sameUserClass = '';
if (this.props.consecutivePostByUser) {
sameUserClass = 'same--user';
}
let postType = '';
if (post.root_id && post.root_id.length > 0) {
postType = 'post--comment';
} else if (this.props.replyCount > 0) {
postType = 'post--root';
sameUserClass = '';
rootUser = '';
}
if (isSystemMessage) {
className += ' post--system';
sameUserClass = '';
currentUserCss = '';
postType = '';
rootUser = '';
}
if (this.props.compactDisplay) {
className += ' post--compact';
}
if (this.state.dropdownOpened) {
className += ' post--hovered';
}
if (post.is_pinned) {
className += ' post--pinned';
}
return className + ' ' + sameUserClass + ' ' + rootUser + ' ' + postType + ' ' + currentUserCss;
}
render() {
const post = this.props.post;
const mattermostLogo = Constants.MATTERMOST_ICON_SVG;
const isSystemMessage = PostUtils.isSystemMessage(post);
const fromWebhook = post.props && post.props.from_webhook === 'true';
let timestamp = 0;
if (!this.props.user || this.props.user.last_picture_update == null) {
timestamp = this.props.currentUser.last_picture_update;
} else {
timestamp = this.props.user.last_picture_update;
}
let status = this.props.status;
if (fromWebhook) {
status = null;
}
let profilePic = (
<ProfilePicture
src={PostUtils.getProfilePicSrcForPost(post, timestamp)}
status={status}
user={this.props.user}
isBusy={this.props.isBusy}
/>
);
if (fromWebhook) {
profilePic = (
<ProfilePicture
src={PostUtils.getProfilePicSrcForPost(post, timestamp)}
/>
);
} else if (PostUtils.isSystemMessage(post)) {
profilePic = (
<span
className='icon'
dangerouslySetInnerHTML={{__html: mattermostLogo}}
/>
);
}
let centerClass = '';
if (this.props.center) {
centerClass = 'center';
}
if (this.props.compactDisplay) {
if (fromWebhook) {
profilePic = (
<ProfilePicture
src=''
status={status}
isBusy={this.props.isBusy}
user={this.props.user}
/>
);
} else {
profilePic = (
<ProfilePicture
src=''
status={status}
/>
);
}
}
const profilePicContainer = (<div className='post__img'>{profilePic}</div>);
return (
<div
ref={(div) => {
this.domNode = div;
}}
>
<div
id={'post_' + post.id}
className={this.getClassName(this.props.post, isSystemMessage, fromWebhook)}
>
<div className={'post__content ' + centerClass}>
{profilePicContainer}
<div>
<PostHeader
ref='header'
post={post}
handleCommentClick={this.handleCommentClick}
handleDropdownOpened={this.handleDropdownOpened}
user={this.props.user}
currentUser={this.props.currentUser}
compactDisplay={this.props.compactDisplay}
status={this.props.status}
isBusy={this.props.isBusy}
lastPostCount={this.props.lastPostCount}
replyCount={this.props.replyCount}
consecutivePostByUser={this.props.consecutivePostByUser}
getPostList={this.props.getPostList}
/>
<PostBody
post={post}
handleCommentClick={this.handleCommentClick}
compactDisplay={this.props.compactDisplay}
lastPostCount={this.props.lastPostCount}
isCommentMention={this.props.isCommentMention}
/>
</div>
</div>
</div>
</div>
);
}
}
|