// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import $ from 'jquery'; import 'bootstrap'; import NavbarSearchBox from './search_bar.jsx'; import MessageWrapper from './message_wrapper.jsx'; import PopoverListMembers from './popover_list_members.jsx'; import EditChannelHeaderModal from './edit_channel_header_modal.jsx'; import EditChannelPurposeModal from './edit_channel_purpose_modal.jsx'; import ChannelInfoModal from './channel_info_modal.jsx'; import ChannelInviteModal from './channel_invite_modal.jsx'; import ChannelMembersModal from './channel_members_modal.jsx'; import ChannelNotificationsModal from './channel_notifications_modal.jsx'; import DeleteChannelModal from './delete_channel_modal.jsx'; import RenameChannelModal from './rename_channel_modal.jsx'; import ToggleModalButton from './toggle_modal_button.jsx'; import ChannelStore from 'stores/channel_store.jsx'; import UserStore from 'stores/user_store.jsx'; import TeamStore from 'stores/team_store.jsx'; import SearchStore from 'stores/search_store.jsx'; import PreferenceStore from 'stores/preference_store.jsx'; import WebrtcStore from 'stores/webrtc_store.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import * as WebrtcActions from 'actions/webrtc_actions.jsx'; import * as ChannelActions from 'actions/channel_actions.jsx'; import * as Utils from 'utils/utils.jsx'; import * as ChannelUtils from 'utils/channel_utils.jsx'; import {getSiteURL} from 'utils/url.jsx'; import * as TextFormatting from 'utils/text_formatting.jsx'; import {getFlaggedPosts, getPinnedPosts} from 'actions/post_actions.jsx'; import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; import {Constants, Preferences, UserStatuses, ActionTypes} from 'utils/constants.jsx'; import React from 'react'; import {FormattedMessage} from 'react-intl'; import {Tooltip, OverlayTrigger, Popover} from 'react-bootstrap'; const PreReleaseFeatures = Constants.PRE_RELEASE_FEATURES; export default class ChannelHeader extends React.Component { constructor(props) { super(props); this.onListenerChange = this.onListenerChange.bind(this); this.handleLeave = this.handleLeave.bind(this); this.searchMentions = this.searchMentions.bind(this); this.showRenameChannelModal = this.showRenameChannelModal.bind(this); this.hideRenameChannelModal = this.hideRenameChannelModal.bind(this); this.handleShortcut = this.handleShortcut.bind(this); this.getFlagged = this.getFlagged.bind(this); this.getPinnedPosts = this.getPinnedPosts.bind(this); this.initWebrtc = this.initWebrtc.bind(this); this.onBusy = this.onBusy.bind(this); this.openDirectMessageModal = this.openDirectMessageModal.bind(this); const state = this.getStateFromStores(); state.showEditChannelPurposeModal = false; state.showMembersModal = false; state.showRenameChannelModal = false; this.state = state; } getStateFromStores() { const channel = ChannelStore.get(this.props.channelId); const stats = ChannelStore.getStats(this.props.channelId); const users = UserStore.getProfileListInChannel(this.props.channelId); let otherUserId = null; if (channel && channel.type === 'D') { otherUserId = Utils.getUserIdFromChannelName(channel); } return { channel, memberChannel: ChannelStore.getMyMember(this.props.channelId), users, userCount: stats.member_count, currentUser: UserStore.getCurrentUser(), otherUserId, enableFormatting: PreferenceStore.getBool(Preferences.CATEGORY_ADVANCED_SETTINGS, 'formatting', true), isBusy: WebrtcStore.isBusy(), isFavorite: channel && ChannelUtils.isFavoriteChannel(channel) }; } validState() { if (!this.state.channel || !this.state.memberChannel || !this.state.users || !this.state.userCount || !this.state.currentUser) { return false; } return true; } componentDidMount() { ChannelStore.addChangeListener(this.onListenerChange); ChannelStore.addStatsChangeListener(this.onListenerChange); SearchStore.addSearchChangeListener(this.onListenerChange); PreferenceStore.addChangeListener(this.onListenerChange); UserStore.addChangeListener(this.onListenerChange); UserStore.addInChannelChangeListener(this.onListenerChange); UserStore.addStatusesChangeListener(this.onListenerChange); WebrtcStore.addChangedListener(this.onListenerChange); WebrtcStore.addBusyListener(this.onBusy); $('.sidebar--left .dropdown-menu').perfectScrollbar(); document.addEventListener('keydown', this.handleShortcut); } componentWillUnmount() { ChannelStore.removeChangeListener(this.onListenerChange); ChannelStore.removeStatsChangeListener(this.onListenerChange); SearchStore.removeSearchChangeListener(this.onListenerChange); PreferenceStore.removeChangeListener(this.onListenerChange); UserStore.removeChangeListener(this.onListenerChange); UserStore.removeInChannelChangeListener(this.onListenerChange); UserStore.removeStatusesChangeListener(this.onListenerChange); WebrtcStore.removeChangedListener(this.onListenerChange); WebrtcStore.removeBusyListener(this.onBusy); document.removeEventListener('keydown', this.handleShortcut); } shouldComponentUpdate(nextProps) { return Boolean(nextProps.channelId); } onListenerChange() { this.setState(this.getStateFromStores()); } handleLeave() { ChannelActions.leaveChannel(this.state.channel.id); } toggleFavorite = (e) => { e.preventDefault(); if (this.state.isFavorite) { ChannelActions.unmarkFavorite(this.state.channel.id); } else { ChannelActions.markFavorite(this.state.channel.id); } }; searchMentions(e) { e.preventDefault(); const user = this.state.currentUser; if (SearchStore.isMentionSearch) { // Close GlobalActions.toggleSideBarAction(false); } else { GlobalActions.emitSearchMentionsEvent(user); } } getPinnedPosts(e) { e.preventDefault(); if (SearchStore.isPinnedPosts) { GlobalActions.toggleSideBarAction(false); } else { getPinnedPosts(this.props.channelId); } } getFlagged(e) { e.preventDefault(); if (SearchStore.isFlaggedPosts) { GlobalActions.toggleSideBarAction(false); } else { getFlaggedPosts(); } } handleShortcut(e) { if (Utils.cmdOrCtrlPressed(e) && e.shiftKey) { if (e.keyCode === Constants.KeyCodes.M) { e.preventDefault(); this.searchMentions(e); } } } showRenameChannelModal(e) { e.preventDefault(); this.setState({ showRenameChannelModal: true }); } hideRenameChannelModal() { this.setState({ showRenameChannelModal: false }); } initWebrtc(contactId, isOnline) { if (isOnline && !this.state.isBusy) { GlobalActions.emitCloseRightHandSide(); WebrtcActions.initWebrtc(contactId, true); } } onBusy(isBusy) { this.setState({isBusy}); } openDirectMessageModal() { AppDispatcher.handleViewAction({ type: ActionTypes.TOGGLE_DM_MODAL, value: true, startingUsers: UserStore.getProfileListInChannel(this.props.channelId, true) }); } render() { const flagIcon = Constants.FLAG_ICON_SVG; const pinIcon = Constants.PIN_ICON; if (!this.validState()) { // Use an empty div to make sure the header's height stays constant return (
); } const channel = this.state.channel; const recentMentionsTooltip = (
{webrtc}
{toggleFavorite}
{channelTitle}
|
{popoverListMembers} |
|
---|