forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel_intro_message.jsx
585 lines (550 loc) · 21.5 KB
/
channel_intro_message.jsx
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {FormattedDate, FormattedMessage} from 'react-intl';
import PropTypes from 'prop-types';
import {Permissions} from 'mattermost-redux/constants';
import {Constants, ModalIdentifiers} from 'utils/constants';
import ChannelInviteModal from 'components/channel_invite_modal';
import EditChannelHeaderModal from 'components/edit_channel_header_modal';
import ProfilePicture from 'components/profile_picture';
import ToggleModalButtonRedux from 'components/toggle_modal_button_redux';
import ToggleModalButton from 'components/toggle_modal_button.jsx';
import UserProfile from 'components/user_profile';
import ChannelPermissionGate from 'components/permissions_gates/channel_permission_gate';
import TeamPermissionGate from 'components/permissions_gates/team_permission_gate';
import FormattedMarkdownMessage from 'components/formatted_markdown_message';
import EditIcon from 'components/widgets/icons/fa_edit_icon';
import InvitationModal from 'components/invitation_modal';
import AddGroupsToChannelModal from 'components/add_groups_to_channel_modal';
import AddGroupsToTeamModal from 'components/add_groups_to_team_modal';
import {getMonthLong} from 'utils/i18n.jsx';
import * as Utils from 'utils/utils.jsx';
export default class ChannelIntroMessage extends React.PureComponent {
static propTypes = {
currentUserId: PropTypes.string.isRequired,
channel: PropTypes.object.isRequired,
fullWidth: PropTypes.bool.isRequired,
locale: PropTypes.string.isRequired,
channelProfiles: PropTypes.array.isRequired,
enableUserCreation: PropTypes.bool,
isReadOnly: PropTypes.bool,
teamIsGroupConstrained: PropTypes.bool,
};
render() {
const {
currentUserId,
channel,
fullWidth,
locale,
enableUserCreation,
isReadOnly,
channelProfiles,
teamIsGroupConstrained,
} = this.props;
let centeredIntro = '';
if (!fullWidth) {
centeredIntro = 'channel-intro--centered';
}
if (channel.type === Constants.DM_CHANNEL) {
return createDMIntroMessage(channel, centeredIntro);
} else if (channel.type === Constants.GM_CHANNEL) {
return createGMIntroMessage(channel, centeredIntro, channelProfiles, currentUserId);
} else if (channel.name === Constants.DEFAULT_CHANNEL) {
return createDefaultIntroMessage(channel, centeredIntro, enableUserCreation, isReadOnly, teamIsGroupConstrained);
} else if (channel.name === Constants.OFFTOPIC_CHANNEL) {
return createOffTopicIntroMessage(channel, centeredIntro);
} else if (channel.type === Constants.OPEN_CHANNEL || channel.type === Constants.PRIVATE_CHANNEL) {
return createStandardIntroMessage(channel, centeredIntro, locale);
}
return null;
}
}
function createGMIntroMessage(channel, centeredIntro, profiles, currentUserId) {
const channelIntroId = 'channelIntro';
if (profiles.length > 0) {
const pictures = profiles.
filter((profile) => profile.id !== currentUserId).
map((profile) => (
<ProfilePicture
key={'introprofilepicture' + profile.id}
src={Utils.imageURLForUser(profile)}
size='xl'
userId={profile.id}
username={profile.username}
/>
));
return (
<div
id={channelIntroId}
className={'channel-intro ' + centeredIntro}
>
<div className='post-profile-img__container channel-intro-img'>
{pictures}
</div>
<p className='channel-intro-text'>
<FormattedMarkdownMessage
id='intro_messages.GM'
defaultMessage='This is the start of your group message history with {names}.\nMessages and files shared here are not shown to people outside this area.'
values={{
names: channel.display_name,
}}
/>
</p>
{createSetHeaderButton(channel)}
</div>
);
}
return (
<div
id={channelIntroId}
className={'channel-intro ' + centeredIntro}
>
<p className='channel-intro-text'>
<FormattedMessage
id='intro_messages.group_message'
defaultMessage='This is the start of your group message history with these teammates. Messages and files shared here are not shown to people outside this area.'
/>
</p>
</div>
);
}
function createDMIntroMessage(channel, centeredIntro) {
var teammate = Utils.getDirectTeammate(channel.id);
const channelIntroId = 'channelIntro';
if (teammate) {
var teammateName = teammate.username;
if (teammate.nickname.length > 0) {
teammateName = teammate.nickname;
}
return (
<div
id={channelIntroId}
className={'channel-intro ' + centeredIntro}
>
<div className='post-profile-img__container channel-intro-img'>
<ProfilePicture
src={Utils.imageURLForUser(teammate)}
size='xl'
userId={teammate.id}
username={teammate.username}
hasMention={true}
/>
</div>
<div className='channel-intro-profile d-flex'>
<UserProfile
userId={teammate.id}
disablePopover={false}
hasMention={true}
/>
</div>
<p className='channel-intro-text'>
<FormattedMarkdownMessage
id='intro_messages.DM'
defaultMessage='This is the start of your direct message history with {teammate}.\nDirect messages and files shared here are not shown to people outside this area.'
values={{
teammate: teammateName,
}}
/>
</p>
{teammate.is_bot ? null : createSetHeaderButton(channel)}
</div>
);
}
return (
<div
id={channelIntroId}
className={'channel-intro ' + centeredIntro}
>
<p className='channel-intro-text'>
<FormattedMessage
id='intro_messages.teammate'
defaultMessage='This is the start of your direct message history with this teammate. Direct messages and files shared here are not shown to people outside this area.'
/>
</p>
</div>
);
}
function createOffTopicIntroMessage(channel, centeredIntro) {
const isPrivate = channel.type === Constants.PRIVATE_CHANNEL;
const children = createSetHeaderButton(channel);
let setHeaderButton = null;
if (children) {
setHeaderButton = (
<ChannelPermissionGate
teamId={channel.team_id}
channelId={channel.id}
permissions={[isPrivate ? Permissions.MANAGE_PRIVATE_CHANNEL_PROPERTIES : Permissions.MANAGE_PUBLIC_CHANNEL_PROPERTIES]}
>
{children}
</ChannelPermissionGate>
);
}
const channelInviteButton = createInviteChannelButton(channel);
return (
<div
id='channelIntro'
className={'channel-intro ' + centeredIntro}
>
<h4 className='channel-intro__title'>
<FormattedMessage
id='intro_messages.beginning'
defaultMessage='Beginning of {name}'
values={{
name: channel.display_name,
}}
/>
</h4>
<p className='channel-intro__content'>
<FormattedMessage
id='intro_messages.offTopic'
defaultMessage='This is the start of {display_name}, a channel for non-work-related conversations.'
values={{
display_name: channel.display_name,
}}
/>
</p>
{channelInviteButton}
{setHeaderButton}
</div>
);
}
export function createDefaultIntroMessage(channel, centeredIntro, enableUserCreation, isReadOnly, teamIsGroupConstrained) {
let teamInviteLink = null;
if (!isReadOnly && enableUserCreation) {
teamInviteLink = (
<TeamPermissionGate
teamId={channel.team_id}
permissions={[Permissions.INVITE_USER]}
>
<TeamPermissionGate
teamId={channel.team_id}
permissions={[Permissions.ADD_USER_TO_TEAM]}
>
{!teamIsGroupConstrained &&
<FormattedMessage
id='intro_messages.inviteOthers'
defaultMessage='Invite others to this team'
>
{(message) => (
<ToggleModalButtonRedux
accessibilityLabel={message}
id='introTextInvite'
className='intro-links color--link cursor--pointer'
modalId={ModalIdentifiers.INVITATION}
dialogType={InvitationModal}
>
<FormattedMessage
id='generic_icons.add'
defaultMessage='Add Icon'
>
{(title) => (
<i
className='fa fa-user-plus'
title={title}
/>
)}
</FormattedMessage>
{message}
</ToggleModalButtonRedux>
)}
</FormattedMessage>
}
{teamIsGroupConstrained &&
<ToggleModalButton
className='intro-links color--link'
dialogType={AddGroupsToTeamModal}
dialogProps={{channel}}
>
<FormattedMessage
id='generic_icons.add'
defaultMessage='Add Icon'
>
{(title) => (
<i
className='fa fa-user-plus'
title={title}
/>
)}
</FormattedMessage>
<FormattedMessage
id='intro_messages.addGroupsToTeam'
defaultMessage='Add other groups to this team'
/>
</ToggleModalButton>
}
</TeamPermissionGate>
</TeamPermissionGate>
);
}
const isPrivate = channel.type === Constants.PRIVATE_CHANNEL;
let setHeaderButton = null;
if (!isReadOnly) {
const children = createSetHeaderButton(channel);
if (children) {
setHeaderButton = (
<ChannelPermissionGate
teamId={channel.team_id}
channelId={channel.id}
permissions={[isPrivate ? Permissions.MANAGE_PRIVATE_CHANNEL_PROPERTIES : Permissions.MANAGE_PUBLIC_CHANNEL_PROPERTIES]}
>
{children}
</ChannelPermissionGate>
);
}
}
return (
<div
id='channelIntro'
className={'channel-intro ' + centeredIntro}
>
<h4 className='channel-intro__title'>
<FormattedMessage
id='intro_messages.beginning'
defaultMessage='Beginning of {name}'
values={{
name: channel.display_name,
}}
/>
</h4>
<p className='channel-intro__content'>
{!isReadOnly &&
<FormattedMarkdownMessage
id='intro_messages.default'
defaultMessage='**Welcome to {display_name}!**\n \nPost messages here that you want everyone to see. Everyone automatically becomes a permanent member of this channel when they join the team.'
values={{
display_name: channel.display_name,
}}
/>
}
{isReadOnly &&
<FormattedMarkdownMessage
id='intro_messages.readonly.default'
defaultMessage='**Welcome to {display_name}!**\n \nMessages can only be posted by system admins. Everyone automatically becomes a permanent member of this channel when they join the team.'
values={{
display_name: channel.display_name,
}}
/>
}
</p>
{teamInviteLink}
{setHeaderButton}
<br/>
</div>
);
}
function createStandardIntroMessage(channel, centeredIntro, locale) {
var uiName = channel.display_name;
var creatorName = Utils.getDisplayNameByUserId(channel.creator_id);
var memberMessage;
const channelIsArchived = channel.delete_at !== 0;
if (channelIsArchived) {
memberMessage = '';
} else if (channel.type === Constants.PRIVATE_CHANNEL) {
memberMessage = (
<FormattedMessage
id='intro_messages.onlyInvited'
defaultMessage=' Only invited members can see this private channel.'
/>
);
} else {
memberMessage = (
<FormattedMessage
id='intro_messages.anyMember'
defaultMessage=' Any member can join and read this channel.'
/>
);
}
const date = (
<FormattedDate
value={channel.create_at}
month={getMonthLong(locale)}
day='2-digit'
year='numeric'
/>
);
var createMessage;
if (creatorName === '') {
if (channel.type === Constants.PRIVATE_CHANNEL) {
createMessage = (
<FormattedMessage
id='intro_messages.noCreatorPrivate'
defaultMessage='This is the start of the {name} private channel, created on {date}.'
values={{name: (uiName), date}}
/>
);
} else if (channel.type === Constants.OPEN_CHANNEL) {
createMessage = (
<FormattedMessage
id='intro_messages.noCreator'
defaultMessage='This is the start of the {name} channel, created on {date}.'
values={{name: (uiName), date}}
/>
);
}
} else if (channel.type === Constants.PRIVATE_CHANNEL) {
createMessage = (
<span>
<FormattedMessage
id='intro_messages.creatorPrivate'
defaultMessage='This is the start of the {name} private channel, created by {creator} on {date}.'
values={{
name: (uiName),
creator: (creatorName),
date,
}}
/>
</span>
);
} else if (channel.type === Constants.OPEN_CHANNEL) {
createMessage = (
<span>
<FormattedMessage
id='intro_messages.creator'
defaultMessage='This is the start of the {name} channel, created by {creator} on {date}.'
values={{
name: (uiName),
creator: (creatorName),
date,
}}
/>
</span>
);
}
var purposeMessage = '';
if (channel.purpose && channel.purpose !== '') {
if (channel.type === Constants.PRIVATE_CHANNEL) {
purposeMessage = (
<span>
<FormattedMessage
id='intro_messages.purposePrivate'
defaultMessage=" This private channel's purpose is: {purpose}"
values={{purpose: channel.purpose}}
/>
</span>
);
} else if (channel.type === Constants.OPEN_CHANNEL) {
purposeMessage = (
<span>
<FormattedMessage
id='intro_messages.purpose'
defaultMessage=" This channel's purpose is: {purpose}"
values={{purpose: channel.purpose}}
/>
</span>
);
}
}
const isPrivate = channel.type === Constants.PRIVATE_CHANNEL;
let setHeaderButton = null;
const children = createSetHeaderButton(channel);
if (children) {
setHeaderButton = (
<ChannelPermissionGate
teamId={channel.team_id}
channelId={channel.id}
permissions={[isPrivate ? Permissions.MANAGE_PRIVATE_CHANNEL_PROPERTIES : Permissions.MANAGE_PUBLIC_CHANNEL_PROPERTIES]}
>
{children}
</ChannelPermissionGate>
);
}
const channelInviteButton = createInviteChannelButton(channel);
return (
<div
id='channelIntro'
className={'channel-intro ' + centeredIntro}
>
<h4 className='channel-intro__title'>
<FormattedMessage
id='intro_messages.beginning'
defaultMessage='Beginning of {name}'
values={{
name: (uiName),
}}
/>
</h4>
<p className='channel-intro__content'>
{createMessage}
{memberMessage}
{purposeMessage}
<br/>
</p>
{channelInviteButton}
{setHeaderButton}
</div>
);
}
function createInviteChannelButton(channel) {
const modal = channel.group_constrained ? AddGroupsToChannelModal : ChannelInviteModal;
const channelIsArchived = channel.delete_at !== 0;
if (channelIsArchived) {
return null;
}
const isPrivate = channel.type === Constants.PRIVATE_CHANNEL;
return (
<ChannelPermissionGate
channelId={channel.id}
teamId={channel.team_id}
permissions={[isPrivate ? Permissions.MANAGE_PRIVATE_CHANNEL_MEMBERS : Permissions.MANAGE_PUBLIC_CHANNEL_MEMBERS]}
>
<ToggleModalButton
className='intro-links color--link'
dialogType={modal}
dialogProps={{channel}}
>
<FormattedMessage
id='generic_icons.add'
defaultMessage='Add Icon'
>
{(title) => (
<i
className='fa fa-user-plus'
title={title}
/>
)}
</FormattedMessage>
{isPrivate && channel.group_constrained &&
<FormattedMessage
id='intro_messages.addGroups'
defaultMessage='Add groups to this private channel'
/>}
{isPrivate && !channel.group_constrained &&
<FormattedMessage
id='intro_messages.invitePrivate'
defaultMessage='Invite others to this private channel'
/>}
{!isPrivate &&
<FormattedMessage
id='intro_messages.invite'
defaultMessage='Invite others to this channel'
/>}
</ToggleModalButton>
</ChannelPermissionGate>
);
}
function createSetHeaderButton(channel) {
const channelIsArchived = channel.delete_at !== 0;
if (channelIsArchived) {
return null;
}
return (
<FormattedMessage
id='intro_messages.setHeader'
defaultMessage='Set a Header'
>
{(message) => (
<ToggleModalButtonRedux
modalId='editChannelHeaderModal'
accessibilityLabel={message}
className={'intro-links color--link'}
dialogType={EditChannelHeaderModal}
dialogProps={{channel}}
>
<EditIcon/>
{message}
</ToggleModalButtonRedux>
)}
</FormattedMessage>
);
}