From 2768cd201038afbb6dd649f12ec64129cb0c68ea Mon Sep 17 00:00:00 2001 From: wmwragg Date: Fri, 22 Jul 2016 17:30:09 +0100 Subject: [PATCH] Initial unstyled mentions state notifier context menu --- src/component-index.js | 2 +- src/components/views/elements/Label.js | 45 -------- .../rooms/NotificationStateContextMenu.js | 107 ++++++++++++++++++ 3 files changed, 108 insertions(+), 46 deletions(-) delete mode 100644 src/components/views/elements/Label.js create mode 100644 src/components/views/rooms/NotificationStateContextMenu.js diff --git a/src/component-index.js b/src/component-index.js index fc4a72c7f..029a0a818 100644 --- a/src/component-index.js +++ b/src/component-index.js @@ -35,7 +35,6 @@ module.exports.components['structures.RoomSubList'] = require('./components/stru module.exports.components['structures.SearchBox'] = require('./components/structures/SearchBox'); module.exports.components['structures.ViewSource'] = require('./components/structures/ViewSource'); module.exports.components['views.elements.ImageView'] = require('./components/views/elements/ImageView'); -module.exports.components['views.elements.Label'] = require('./components/views/elements/Label'); module.exports.components['views.elements.Spinner'] = require('./components/views/elements/Spinner'); module.exports.components['views.globals.GuestWarningBar'] = require('./components/views/globals/GuestWarningBar'); module.exports.components['views.globals.MatrixToolbar'] = require('./components/views/globals/MatrixToolbar'); @@ -48,6 +47,7 @@ module.exports.components['views.messages.MessageTimestamp'] = require('./compon module.exports.components['views.messages.SenderProfile'] = require('./components/views/messages/SenderProfile'); module.exports.components['views.rooms.BottomLeftMenuTile'] = require('./components/views/rooms/BottomLeftMenuTile'); module.exports.components['views.rooms.MessageContextMenu'] = require('./components/views/rooms/MessageContextMenu'); +module.exports.components['views.rooms.NotificationStateContextMenu'] = require('./components/views/rooms/NotificationStateContextMenu'); module.exports.components['views.rooms.RoomDNDView'] = require('./components/views/rooms/RoomDNDView'); module.exports.components['views.rooms.RoomDropTarget'] = require('./components/views/rooms/RoomDropTarget'); module.exports.components['views.rooms.RoomTooltip'] = require('./components/views/rooms/RoomTooltip'); diff --git a/src/components/views/elements/Label.js b/src/components/views/elements/Label.js deleted file mode 100644 index 2608dd453..000000000 --- a/src/components/views/elements/Label.js +++ /dev/null @@ -1,45 +0,0 @@ -/* -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 React = require('react'); - -module.exports = React.createClass({ - displayName: 'Label', - - propTypes: { - label: React.PropTypes.string, - }, - - getInitialState: function() { - return({ label : "LABEL" }); - }, - - onLabelClick: function() { - if (this.props.onFinished) this.props.onFinished(); - }, - - render: function() { - return ( -
-
- LABEL -
-
- ); - } -}); diff --git a/src/components/views/rooms/NotificationStateContextMenu.js b/src/components/views/rooms/NotificationStateContextMenu.js new file mode 100644 index 000000000..d485422d9 --- /dev/null +++ b/src/components/views/rooms/NotificationStateContextMenu.js @@ -0,0 +1,107 @@ +/* +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 MatrixClientPeg = require('matrix-react-sdk/lib/MatrixClientPeg'); + +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, + }; + }, + + onAllClick: function() { + if (this.props.onFinished) { + this.setState({areNotifsMuted: false}); + this._save(false); + this.props.onFinished(); + } + }, + + onMuteClick: function() { + if (this.props.onFinished) { + this.setState({areNotifsMuted: true}); + this._save(true); + this.props.onFinished(); + } + }, + + _save: function( isMuted ) { + const roomId = this.props.room.roomId; + /* + if (this.state.areNotifsMuted !== originalState.areNotifsMuted) { + promises.push(MatrixClientPeg.get().setRoomMutePushRule( + "global", roomId, this.state.areNotifsMuted + )); + } + */ + MatrixClientPeg.get().setRoomMutePushRule( + "global", roomId, isMuted + ); + }, + + _onToggle: function(keyName, checkedValue, uncheckedValue, ev) { + console.log("Checkbox toggle: %s %s", keyName, ev.target.checked); + var state = {}; + state[keyName] = ev.target.checked ? checkedValue : uncheckedValue; + this.setState(state); + }, + + render: function() { + var cli = MatrixClientPeg.get(); + return ( +
+ {/* +
+ + Mute notifications for this room +
+ */} +
+ All notifications - { this.state.areNotifsMuted ? "OFF" : "ON" } +
+
+ Mute - { this.state.areNotifsMuted ? "ON" : "OFF" } +
+
+ ); + } +});