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
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import * as Utils from './utils.jsx';
import ChannelInviteModal from 'components/channel_invite_modal';
import EditChannelHeaderModal from 'components/edit_channel_header_modal.jsx';
import ToggleModalButton from 'components/toggle_modal_button.jsx';
import UserProfile from 'components/user_profile.jsx';
import ChannelStore from 'stores/channel_store.jsx';
import UserStore from 'stores/user_store.jsx';
import TeamStore from 'stores/team_store.jsx';
import Constants from 'utils/constants.jsx';
import * as GlobalActions from 'actions/global_actions.jsx';
import ProfilePicture from 'components/profile_picture.jsx';
import {Client4} from 'mattermost-redux/client';
import {showManagementOptions} from './channel_utils.jsx';
import React from 'react';
import {FormattedMessage, FormattedHTMLMessage, FormattedDate} from 'react-intl';
export function createChannelIntroMessage(channel, fullWidthIntro) {
let centeredIntro = '';
if (!fullWidthIntro) {
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);
} else if (ChannelStore.isDefault(channel)) {
return createDefaultIntroMessage(channel, centeredIntro);
} else if (channel.name === Constants.OFFTOPIC_CHANNEL) {
return createOffTopicIntroMessage(channel, centeredIntro);
} else if (channel.type === 'O' || channel.type === 'P') {
return createStandardIntroMessage(channel, centeredIntro);
}
return null;
}
export function createGMIntroMessage(channel, centeredIntro) {
const profiles = UserStore.getProfileListInChannel(channel.id, true);
if (profiles.length > 0) {
const pictures = [];
let names = '';
for (let i = 0; i < profiles.length; i++) {
const profile = profiles[i];
pictures.push(
<ProfilePicture
key={'introprofilepicture' + profile.id}
src={Client4.getUsersRoute() + '/' + profile.id + '/image?time=' + profile.last_picture_update}
width='50'
height='50'
user={profile}
/>
);
if (i === profiles.length - 1) {
names += Utils.displayUsernameForUser(profile);
} else if (i === profiles.length - 2) {
names += Utils.displayUsernameForUser(profile) + ' and ';
} else {
names += Utils.displayUsernameForUser(profile) + ', ';
}
}
return (
<div className={'channel-intro ' + centeredIntro}>
<div className='post-profile-img__container channel-intro-img'>
{pictures}
</div>
<p className='channel-intro-text'>
<FormattedHTMLMessage
id='intro_messages.GM'
defaultMessage='This is the start of your group message history with {names}.<br />Messages and files shared here are not shown to people outside this area.'
values={{
names
}}
/>
</p>
{createSetHeaderButton(channel)}
</div>
);
}
return (
<div 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>
);
}
export function createDMIntroMessage(channel, centeredIntro) {
var teammate = Utils.getDirectTeammate(channel.id);
if (teammate) {
var teammateName = teammate.username;
if (teammate.nickname.length > 0) {
teammateName = teammate.nickname;
}
return (
<div className={'channel-intro ' + centeredIntro}>
<div className='post-profile-img__container channel-intro-img'>
<ProfilePicture
src={Client4.getUsersRoute() + '/' + teammate.id + '/image?time=' + teammate.last_picture_update}
width='50'
height='50'
user={teammate}
/>
</div>
<div className='channel-intro-profile'>
<strong>
<UserProfile
user={teammate}
disablePopover={false}
/>
</strong>
</div>
<p className='channel-intro-text'>
<FormattedHTMLMessage
id='intro_messages.DM'
defaultMessage='This is the start of your direct message history with {teammate}.<br />Direct messages and files shared here are not shown to people outside this area.'
values={{
teammate: teammateName
}}
/>
</p>
{createSetHeaderButton(channel)}
</div>
);
}
return (
<div 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>
);
}
export function createOffTopicIntroMessage(channel, centeredIntro) {
var uiType = (
<FormattedMessage
id='intro_messages.channel'
defaultMessage='channel'
/>
);
const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
const isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel();
let setHeaderButton = createSetHeaderButton(channel);
if (!showManagementOptions(channel, isAdmin, isSystemAdmin, isChannelAdmin)) {
setHeaderButton = null;
}
return (
<div className={'channel-intro ' + centeredIntro}>
<FormattedHTMLMessage
id='intro_messages.offTopic'
defaultMessage='<h4 class="channel-intro__title">Beginning of {display_name}</h4><p class="channel-intro__content">This is the start of {display_name}, a channel for non-work-related conversations.<br/></p>'
values={{
display_name: channel.display_name
}}
/>
{createInviteChannelMemberButton(channel, uiType)}
{setHeaderButton}
</div>
);
}
export function createDefaultIntroMessage(channel, centeredIntro) {
let inviteModalLink = (
<a
className='intro-links'
href='#'
onClick={GlobalActions.showGetTeamInviteLinkModal}
>
<i className='fa fa-user-plus'/>
<FormattedMessage
id='intro_messages.inviteOthers'
defaultMessage='Invite others to this team'
/>
</a>
);
const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
const isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel();
if (global.window.mm_license.IsLicensed === 'true') {
if (global.window.mm_config.RestrictTeamInvite === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
inviteModalLink = null;
} else if (global.window.mm_config.RestrictTeamInvite === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
inviteModalLink = null;
}
}
let setHeaderButton = createSetHeaderButton(channel);
if (!showManagementOptions(channel, isAdmin, isSystemAdmin, isChannelAdmin)) {
setHeaderButton = null;
}
return (
<div className={'channel-intro ' + centeredIntro}>
<FormattedHTMLMessage
id='intro_messages.default'
defaultMessage="<h4 class='channel-intro__title'>Beginning of {display_name}</h4><p class='channel-intro__content'><strong>Welcome to {display_name}!</strong><br/><br/>This is the first channel teammates see when they sign up - use it for posting updates everyone needs to know.</p>"
values={{
display_name: channel.display_name
}}
/>
{inviteModalLink}
{setHeaderButton}
<br/>
</div>
);
}
export function createStandardIntroMessage(channel, centeredIntro) {
var uiName = channel.display_name;
var creatorName = Utils.displayUsername(channel.creator_id);
var uiType;
var memberMessage;
if (channel.type === 'P') {
uiType = (
<FormattedMessage
id='intro_messages.group'
defaultMessage='private channel'
/>
);
memberMessage = (
<FormattedMessage
id='intro_messages.onlyInvited'
defaultMessage=' Only invited members can see this private channel.'
/>
);
} else {
uiType = (
<FormattedMessage
id='intro_messages.channel'
defaultMessage='channel'
/>
);
memberMessage = (
<FormattedMessage
id='intro_messages.anyMember'
defaultMessage=' Any member can join and read this channel.'
/>
);
}
const date = (
<FormattedDate
value={channel.create_at}
month='long'
day='2-digit'
year='numeric'
/>
);
var createMessage;
if (creatorName === '') {
createMessage = (
<FormattedMessage
id='intro_messages.noCreator'
defaultMessage='This is the start of the {name} {type}, created on {date}.'
values={{
name: (uiName),
type: (uiType),
date
}}
/>
);
} else {
createMessage = (
<span>
<FormattedMessage
id='intro_messages.creator'
defaultMessage='This is the start of the {name} {type}, created by {creator} on {date}.'
values={{
name: (uiName),
type: (uiType),
creator: (creatorName),
date
}}
/>
</span>
);
}
var purposeMessage = '';
if (channel.purpose && channel.purpose !== '') {
purposeMessage = (
<span>
<FormattedMessage
id='intro_messages.purpose'
defaultMessage=" This {type}'s purpose is: {purpose}"
values={{
purpose: channel.purpose,
type: (uiType)
}}
/>
</span>
);
}
const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
const isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel();
let setHeaderButton = createSetHeaderButton(channel);
if (!showManagementOptions(channel, isAdmin, isSystemAdmin, isChannelAdmin)) {
setHeaderButton = null;
}
return (
<div 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>
{createInviteChannelMemberButton(channel, uiType)}
{setHeaderButton}
</div>
);
}
function createInviteChannelMemberButton(channel, uiType) {
return (
<ToggleModalButton
className='intro-links'
dialogType={ChannelInviteModal}
dialogProps={{channel}}
>
<i className='fa fa-user-plus'/>
<FormattedMessage
id='intro_messages.invite'
defaultMessage='Invite others to this {type}'
values={{
type: (uiType)
}}
/>
</ToggleModalButton>
);
}
function createSetHeaderButton(channel) {
return (
<ToggleModalButton
className='intro-links'
dialogType={EditChannelHeaderModal}
dialogProps={{channel}}
>
<i className='fa fa-pencil'/>
<FormattedMessage
id='intro_messages.setHeader'
defaultMessage='Set a Header'
/>
</ToggleModalButton>
);
}
|