// 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) => (
{!isReadOnly &&
{createMessage}
{memberMessage}
{purposeMessage}