// 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) => ( )); return (
{pictures}

{createSetHeaderButton(channel)}
); } return (

); } 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 (

{teammate.is_bot ? null : createSetHeaderButton(channel)}
); } return (

); } function createOffTopicIntroMessage(channel, centeredIntro) { const isPrivate = channel.type === Constants.PRIVATE_CHANNEL; const children = createSetHeaderButton(channel); let setHeaderButton = null; if (children) { setHeaderButton = ( {children} ); } const channelInviteButton = createInviteChannelButton(channel); return (

{channelInviteButton} {setHeaderButton}
); } export function createDefaultIntroMessage(channel, centeredIntro, enableUserCreation, isReadOnly, teamIsGroupConstrained) { let teamInviteLink = null; if (!isReadOnly && enableUserCreation) { teamInviteLink = ( {!teamIsGroupConstrained && {(message) => ( {(title) => ( )} {message} )} } {teamIsGroupConstrained && {(title) => ( )} } ); } const isPrivate = channel.type === Constants.PRIVATE_CHANNEL; let setHeaderButton = null; if (!isReadOnly) { const children = createSetHeaderButton(channel); if (children) { setHeaderButton = ( {children} ); } } return (

{!isReadOnly && } {isReadOnly && }

{teamInviteLink} {setHeaderButton}
); } 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 = ( ); } else { memberMessage = ( ); } const date = ( ); var createMessage; if (creatorName === '') { if (channel.type === Constants.PRIVATE_CHANNEL) { createMessage = ( ); } else if (channel.type === Constants.OPEN_CHANNEL) { createMessage = ( ); } } else if (channel.type === Constants.PRIVATE_CHANNEL) { createMessage = ( ); } else if (channel.type === Constants.OPEN_CHANNEL) { createMessage = ( ); } var purposeMessage = ''; if (channel.purpose && channel.purpose !== '') { if (channel.type === Constants.PRIVATE_CHANNEL) { purposeMessage = ( ); } else if (channel.type === Constants.OPEN_CHANNEL) { purposeMessage = ( ); } } const isPrivate = channel.type === Constants.PRIVATE_CHANNEL; let setHeaderButton = null; const children = createSetHeaderButton(channel); if (children) { setHeaderButton = ( {children} ); } const channelInviteButton = createInviteChannelButton(channel); return (

{createMessage} {memberMessage} {purposeMessage}

{channelInviteButton} {setHeaderButton}
); } 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 ( {(title) => ( )} {isPrivate && channel.group_constrained && } {isPrivate && !channel.group_constrained && } {!isPrivate && } ); } function createSetHeaderButton(channel) { const channelIsArchived = channel.delete_at !== 0; if (channelIsArchived) { return null; } return ( {(message) => ( {message} )} ); }