// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import SettingItemMin from 'components/setting_item_min.jsx';
import SettingItemMax from 'components/setting_item_max.jsx';
import ChannelStore from 'stores/channel_store.jsx';
import $ from 'jquery';
import React from 'react';
import {Modal} from 'react-bootstrap';
import {FormattedMessage} from 'react-intl';
import {updateChannelNotifyProps} from 'actions/channel_actions.jsx';
export default class ChannelNotificationsModal extends React.Component {
constructor(props) {
super(props);
this.updateSection = this.updateSection.bind(this);
this.onHide = this.onHide.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);
this.state = {
activeSection: '',
show: true,
notifyLevel: props.channelMember.notify_props.desktop,
unreadLevel: props.channelMember.notify_props.mark_unread
};
}
updateSection(section) {
if ($('.section-max').length) {
$('.settings-modal .modal-body').scrollTop(0).perfectScrollbar('update');
}
this.setState({activeSection: section});
}
onHide() {
this.setState({show: false});
}
handleSubmitNotifyLevel() {
const channelId = this.props.channel.id;
const notifyLevel = this.state.notifyLevel;
const currentUserId = this.props.currentUser.id;
if (this.props.channelMember.notify_props.desktop === notifyLevel) {
this.updateSection('');
return;
}
const data = {
channel_id: channelId,
user_id: currentUserId,
desktop: notifyLevel
};
updateChannelNotifyProps(data,
() => {
// YUCK
var member = ChannelStore.getMyMember(channelId);
member.notify_props.desktop = notifyLevel;
ChannelStore.storeMyChannelMember(member);
this.updateSection('');
},
(err) => {
this.setState({serverError: err.message});
}
);
}
handleUpdateNotifyLevel(notifyLevel) {
this.setState({notifyLevel});
}
createNotifyLevelSection(serverError) {
// Get glabal user setting for notifications
const globalNotifyLevel = this.props.currentUser.notify_props ? this.props.currentUser.notify_props.desktop : 'all';
let globalNotifyLevelName;
if (globalNotifyLevel === 'all') {
globalNotifyLevelName = (