2015-07-03 13:12:54 +03:00
|
|
|
/*
|
2016-01-07 07:06:39 +03:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2015-07-03 13:12:54 +03:00
|
|
|
|
|
|
|
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';
|
2015-11-26 18:11:08 +03:00
|
|
|
var React = require("react");
|
2015-11-30 18:04:24 +03:00
|
|
|
var Notifier = require("../../../Notifier");
|
2015-11-26 18:11:08 +03:00
|
|
|
var sdk = require('../../../index');
|
|
|
|
var dis = require("../../../dispatcher");
|
2015-07-03 13:12:54 +03:00
|
|
|
|
2015-11-26 18:11:08 +03:00
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'EnableNotificationsButton',
|
2015-07-03 13:12:54 +03:00
|
|
|
|
2015-09-16 16:48:49 +03:00
|
|
|
componentDidMount: function() {
|
|
|
|
this.dispatcherRef = dis.register(this.onAction);
|
2015-07-03 13:12:54 +03:00
|
|
|
},
|
|
|
|
|
2015-09-16 16:48:49 +03:00
|
|
|
componentWillUnmount: function() {
|
|
|
|
dis.unregister(this.dispatcherRef);
|
2015-07-03 13:12:54 +03:00
|
|
|
},
|
|
|
|
|
2015-09-16 16:48:49 +03:00
|
|
|
onAction: function(payload) {
|
|
|
|
if (payload.action !== "notifier_enabled") {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-03 13:12:54 +03:00
|
|
|
this.forceUpdate();
|
|
|
|
},
|
|
|
|
|
2015-09-16 16:48:49 +03:00
|
|
|
enabled: function() {
|
|
|
|
return Notifier.isEnabled();
|
2015-07-03 13:12:54 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onClick: function() {
|
2015-09-16 16:48:49 +03:00
|
|
|
var self = this;
|
|
|
|
if (!Notifier.supportsDesktopNotifications()) {
|
2015-07-03 13:12:54 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-09-16 16:48:49 +03:00
|
|
|
if (!Notifier.isEnabled()) {
|
|
|
|
Notifier.setEnabled(true, function() {
|
|
|
|
self.forceUpdate();
|
|
|
|
});
|
2015-07-03 13:12:54 +03:00
|
|
|
} else {
|
2015-09-16 16:48:49 +03:00
|
|
|
Notifier.setEnabled(false);
|
2015-07-03 13:12:54 +03:00
|
|
|
}
|
2015-09-16 16:48:49 +03:00
|
|
|
this.forceUpdate();
|
2015-07-03 13:12:54 +03:00
|
|
|
},
|
2015-11-26 18:11:08 +03:00
|
|
|
|
|
|
|
render: function() {
|
|
|
|
if (this.enabled()) {
|
|
|
|
return (
|
|
|
|
<button className="mx_EnableNotificationsButton" onClick={this.onClick}>
|
|
|
|
Disable Notifications
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<button className="mx_EnableNotificationsButton" onClick={this.onClick}>
|
|
|
|
Enable Notifications
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|