/* Copyright 2015, 2016 OpenMarket Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ 'use strict'; var q = require("q"); var React = require('react'); var classNames = require('classnames'); var MatrixClientPeg = require('matrix-react-sdk/lib/MatrixClientPeg'); var dis = require('matrix-react-sdk/lib/dispatcher'); module.exports = React.createClass({ displayName: 'NotificationStateContextMenu', propTypes: { room: React.PropTypes.object.isRequired, /* callback called when the menu is dismissed */ onFinished: React.PropTypes.func, }, getInitialState: function() { var areNotifsMuted = false; var cli = MatrixClientPeg.get(); if (!cli.isGuest()) { var roomPushRule = cli.getRoomPushRule("global", this.props.room.roomId); if (roomPushRule) { if (0 <= roomPushRule.actions.indexOf("dont_notify")) { areNotifsMuted = true; } } } return { areNotifsMuted: areNotifsMuted, }; }, _save: function( isMuted ) { var self = this; const roomId = this.props.room.roomId; var cli = MatrixClientPeg.get(); if (!cli.isGuest()) { cli.setRoomMutePushRule( "global", roomId, isMuted ).then(function() { self.setState({areNotifsMuted: isMuted}); // delay slightly so that the user can see their state change // before closing the menu q.delay(500).then(function() { // tell everyone that wants to know of the change in // notification state dis.dispatch({ action: 'notification_change', roomId: self.props.room.roomId, isMuted: isMuted, }); // Close the context menu if (self.props.onFinished) { self.props.onFinished(); }; }); }).fail(function(error) { // TODO: some form of error notification to the user // to inform them that their state change failed. }); } }, _onClickAlertMe: function() { // Placeholder }, _onClickAllNotifs: function() { this._save(false); }, _onClickMentions: function() { // Placeholder }, _onClickMute: function() { this._save(true); }, render: function() { var cli = MatrixClientPeg.get(); var alertMeClasses = classNames({ 'mx_NotificationStateContextMenu_field': true, 'mx_NotificationStateContextMenu_fieldDisabled': true, }); var allNotifsClasses = classNames({ 'mx_NotificationStateContextMenu_field': true, 'mx_NotificationStateContextMenu_fieldSet': !this.state.areNotifsMuted, }); var mentionsClasses = classNames({ 'mx_NotificationStateContextMenu_field': true, 'mx_NotificationStateContextMenu_fieldDisabled': true, }); var muteNotifsClasses = classNames({ 'mx_NotificationStateContextMenu_field': true, 'mx_NotificationStateContextMenu_fieldSet': this.state.areNotifsMuted, }); return (
Alert me
All notifications
Mentions only
Mute
); } });