Skip to content

Commit d96e5a5

Browse files
committed
Merge branch 'develop' of github.com:vector-im/vector-web into develop
2 parents 4f64f70 + 9cd8f7c commit d96e5a5

1 file changed

Lines changed: 71 additions & 14 deletions

File tree

‎src/components/views/settings/Notifications.js‎

Lines changed: 71 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ module.exports = React.createClass({
6969
ERROR: "ERROR" // There was an error
7070
},
7171

72+
propTypes: {
73+
// The array of threepids from the JS SDK (required for email notifications)
74+
threepids: React.PropTypes.array.isRequired,
75+
},
76+
7277
getInitialState: function() {
7378
return {
7479
phase: this.phases.LOADING,
@@ -102,6 +107,26 @@ module.exports = React.createClass({
102107
UserSettingsStore.setEnableNotifications(event.target.checked);
103108
},
104109

110+
onEnableEmailNotificationsChange: function(address, event) {
111+
var emailPusherPromise;
112+
if (event.target.checked) {
113+
emailPusherPromise = UserSettingsStore.addEmailPusher(address);
114+
} else {
115+
var emailPusher = UserSettingsStore.getEmailPusher(this.state.pushers, address);
116+
emailPusher.kind = null;
117+
emailPusherPromise = MatrixClientPeg.get().setPusher(emailPusher);
118+
}
119+
emailPusherPromise.done(() => {
120+
this._refreshFromServer();
121+
}, (error) => {
122+
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
123+
Modal.createDialog(ErrorDialog, {
124+
title: "Error saving email notification preferences",
125+
description: "Vector was unable to save your email notification preferences.",
126+
});
127+
});
128+
},
129+
105130
onNotifStateButtonClicked: function(event) {
106131
// FIXME: use .bind() rather than className metadata here surely
107132
var vectorRuleId = event.target.className.split("-")[0];
@@ -620,6 +645,24 @@ module.exports = React.createClass({
620645
return rows;
621646
},
622647

648+
emailNotificationsRow: function(address, label) {
649+
return (<div className="mx_UserNotifSettings_tableRow">
650+
<div className="mx_UserNotifSettings_inputCell">
651+
<input id="enableEmailNotifications_{address}"
652+
ref="enableEmailNotifications_{address}"
653+
type="checkbox"
654+
checked={ UserSettingsStore.hasEmailPusher(this.state.pushers, address) }
655+
onChange={ this.onEnableEmailNotificationsChange.bind(this, address) }
656+
/>
657+
</div>
658+
<div className="mx_UserNotifSettings_labelCell">
659+
<label htmlFor="enableEmailNotifications_{address}">
660+
{label}
661+
</label>
662+
</div>
663+
</div>);
664+
},
665+
623666
render: function() {
624667
var self = this;
625668

@@ -656,12 +699,29 @@ module.exports = React.createClass({
656699
{masterPushRuleDiv}
657700

658701
<div className="mx_UserSettings_notifTable">
659-
All notifications are currently disabled for all devices.
702+
All notifications are currently disabled for all targets.
660703
</div>
661704
</div>
662705
);
663706
}
664707

708+
var emailNotificationsRow;
709+
if (this.props.threepids.filter(function(tp) {
710+
if (tp.medium == "email") {
711+
return true;
712+
}
713+
}).length == 0) {
714+
emailNotificationsRow = <div>
715+
Add an email address above to configure email notifications
716+
</div>;
717+
} else {
718+
// This only supports the first email address in your profile for now
719+
emailNotificationsRow = this.emailNotificationsRow(
720+
this.props.threepids[0].address,
721+
"Enable email notifications ("+this.props.threepids[0].address+")"
722+
);
723+
}
724+
665725
// Build external push rules
666726
var externalRules = [];
667727
for (var i in this.state.externalPushRules) {
@@ -682,13 +742,11 @@ module.exports = React.createClass({
682742

683743
var devicesSection;
684744
if (this.state.pushers === undefined) {
685-
devicesSection = <div className="error">Unable to fetch device list</div>
745+
devicesSection = <div className="error">Unable to fetch notification target list</div>
686746
} else if (this.state.pushers.length == 0) {
687-
devicesSection = <div className="mx_UserSettings_devicesTable_nodevices">
688-
No devices are receiving push notifications
689-
</div>
747+
devicesSection = null;
690748
} else {
691-
// It would be great to be able to delete pushers from here too,
749+
// TODO: It would be great to be able to delete pushers from here too,
692750
// and this wouldn't be hard to add.
693751
var rows = [];
694752
for (var i = 0; i < this.state.pushers.length; ++i) {
@@ -698,17 +756,17 @@ module.exports = React.createClass({
698756
</tr>);
699757
}
700758
devicesSection = (<table className="mx_UserSettings_devicesTable">
701-
<thead>
702-
<tr>
703-
<th>Application</th>
704-
<th>Device</th>
705-
</tr>
706-
</thead>
707759
<tbody>
708760
{rows}
709761
</tbody>
710762
</table>);
711763
}
764+
if (devicesSection) {
765+
devicesSection = (<div>
766+
<h3>Notification targets</h3>
767+
{ devicesSection }
768+
</div>);
769+
}
712770

713771
var advancedSettings;
714772
if (externalRules.length) {
@@ -766,7 +824,7 @@ module.exports = React.createClass({
766824
</div>
767825
</div>
768826

769-
<h3>General use</h3>
827+
{ emailNotificationsRow }
770828

771829
<div className="mx_UserNotifSettings_pushRulesTableWrapper">
772830
<table className="mx_UserNotifSettings_pushRulesTable">
@@ -788,7 +846,6 @@ module.exports = React.createClass({
788846

789847
{ advancedSettings }
790848

791-
<h3>Devices</h3>
792849
{ devicesSection }
793850

794851
</div>

0 commit comments

Comments
 (0)