// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. var Modal = ReactBootstrap.Modal; import SettingItemMin from './setting_item_min.jsx'; import SettingItemMax from './setting_item_max.jsx'; import * as Client from '../utils/client.jsx'; import UserStore from '../stores/user_store.jsx'; import ChannelStore from '../stores/channel_store.jsx'; export default class ChannelNotificationsModal extends React.Component { constructor(props) { super(props); this.onListenerChange = this.onListenerChange.bind(this); this.updateSection = this.updateSection.bind(this); this.handleSubmitNotifyLevel = this.handleSubmitNotifyLevel.bind(this); this.handleUpdateNotifyLevel = this.handleUpdateNotifyLevel.bind(this); this.createNotifyLevelSection = this.createNotifyLevelSection.bind(this); this.handleSubmitMarkUnreadLevel = this.handleSubmitMarkUnreadLevel.bind(this); this.handleUpdateMarkUnreadLevel = this.handleUpdateMarkUnreadLevel.bind(this); this.createMarkUnreadLevelSection = this.createMarkUnreadLevelSection.bind(this); const member = ChannelStore.getMember(props.channel.id); this.state = { notifyLevel: member.notify_props.desktop, markUnreadLevel: member.notify_props.mark_unread, channelId: '', activeSection: '' }; } componentDidMount() { ChannelStore.addChangeListener(this.onListenerChange); } componentWillUnmount() { ChannelStore.removeChangeListener(this.onListenerChange); } onListenerChange() { if (!this.state.channelId) { return; } const member = ChannelStore.getMember(this.state.channelId); if (member.notify_props.desktop !== this.state.notifyLevel || member.notify_props.mark_unread !== this.state.mark_unread) { this.setState({ notifyLevel: member.notify_props.desktop, markUnreadLevel: member.notify_props.mark_unread }); } } updateSection(section) { this.setState({activeSection: section}); } handleSubmitNotifyLevel() { var channelId = this.state.channelId; var notifyLevel = this.state.notifyLevel; if (ChannelStore.getMember(channelId).notify_props.desktop === notifyLevel) { this.updateSection(''); return; } var data = {}; data.channel_id = channelId; data.user_id = UserStore.getCurrentId(); data.desktop = notifyLevel; Client.updateNotifyProps(data, () => { var member = ChannelStore.getMember(channelId); member.notify_props.desktop = notifyLevel; ChannelStore.setChannelMember(member); this.updateSection(''); }, (err) => { this.setState({serverError: err.message}); } ); } handleUpdateNotifyLevel(notifyLevel) { this.setState({notifyLevel}); } createNotifyLevelSection(serverError) { var handleUpdateSection; const user = UserStore.getCurrentUser(); const globalNotifyLevel = user.notify_props.desktop; let globalNotifyLevelName; if (globalNotifyLevel === 'all') { globalNotifyLevelName = 'For all activity'; } else if (globalNotifyLevel === 'mention') { globalNotifyLevelName = 'Only for mentions'; } else { globalNotifyLevelName = 'Never'; } if (this.state.activeSection === 'desktop') { var notifyActive = [false, false, false, false]; if (this.state.notifyLevel === 'default') { notifyActive[0] = true; } else if (this.state.notifyLevel === 'all') { notifyActive[1] = true; } else if (this.state.notifyLevel === 'mention') { notifyActive[2] = true; } else { notifyActive[3] = true; } var inputs = []; inputs.push(