From 5d9c8f37261403909eb24bbb60d5f3ea261ca85d Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 12 Apr 2016 16:19:20 +0100 Subject: [PATCH 1/3] Support config for email notifs Add support to notif settings for adding an email pusher, only for the first email address for now. --- .../views/settings/Notifications.js | 73 +++++++++++++++++-- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/src/components/views/settings/Notifications.js b/src/components/views/settings/Notifications.js index 749bc9ae7a..061f79f0cf 100644 --- a/src/components/views/settings/Notifications.js +++ b/src/components/views/settings/Notifications.js @@ -226,6 +226,11 @@ module.exports = React.createClass({ ERROR: "ERROR" // There was an error }, + propTypes: { + // The array of threepids from the JS SDK (required for email notifications) + threepids: React.PropTypes.array.isRequired, + }, + getInitialState: function() { return { phase: this.phases.LOADING, @@ -883,6 +888,41 @@ module.exports = React.createClass({ return rows; }, + emailNotificationsRow: function(address, label) { + return (
+
+ { + var emailPusherPromise; + if (e.target.checked) { + emailPusherPromise = UserSettingsStore.addEmailPusher(address); + } else { + var emailPusher = UserSettingsStore.getEmailPusher(this.state.pushers, address); + emailPusher.kind = null; + emailPusherPromise = MatrixClientPeg.get().setPusher(emailPusher); + } + emailPusherPromise.done(() => { + this._refreshFromServer(); + }, (error) => { + var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); + Modal.createDialog(ErrorDialog, { + title: "Error saving email notification preferences", + description: "Vector was unable to save your email notification preferences.", + }); + }); + }} /> +
+
+ +
+
); + }, + render: function() { var self = this; @@ -928,6 +968,23 @@ module.exports = React.createClass({ ); } + var emailNotificationsRow; + if (this.props.threepids.filter(function(tp) { + if (tp.medium == "email") { + return true; + } + }).length == 0) { + emailNotificationsRow =
+ Add an email address above to configure email notifications +
; + } else { + // This only supports the first email address in your profile for now + emailNotificationsRow = this.emailNotificationsRow( + this.props.threepids[0].address, + "Enable email notifications ("+this.props.threepids[0].address+")" + ); + } + // Build external push rules var externalRules = []; for (var i in this.state.externalPushRules) { @@ -958,17 +1015,19 @@ module.exports = React.createClass({ // and this wouldn't be hard to add. var rows = []; for (var i = 0; i < this.state.pushers.length; ++i) { - rows.push( - {this.state.pushers[i].app_display_name} - {this.state.pushers[i].device_display_name} + var p = this.state.pushers[i]; + + rows.push( + {p.app_display_name} + {p.device_display_name} ); } - devicesSection = ( + devicesSection = (
- - {rows} + + {rows}
Application Device
); } @@ -1026,6 +1085,8 @@ module.exports = React.createClass({ + { emailNotificationsRow } +

General use

From efe1c767f03c2451215cca3951750f8825def864 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 3 May 2016 11:36:44 +0100 Subject: [PATCH 2/3] Un-inline onChange --- .../views/settings/Notifications.js | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/components/views/settings/Notifications.js b/src/components/views/settings/Notifications.js index 2a66fff420..2f445cadd6 100644 --- a/src/components/views/settings/Notifications.js +++ b/src/components/views/settings/Notifications.js @@ -107,6 +107,26 @@ module.exports = React.createClass({ UserSettingsStore.setEnableNotifications(event.target.checked); }, + onEnableEmailNotificationsChange: function(address, event) { + var emailPusherPromise; + if (event.target.checked) { + emailPusherPromise = UserSettingsStore.addEmailPusher(address); + } else { + var emailPusher = UserSettingsStore.getEmailPusher(this.state.pushers, address); + emailPusher.kind = null; + emailPusherPromise = MatrixClientPeg.get().setPusher(emailPusher); + } + emailPusherPromise.done(() => { + this._refreshFromServer(); + }, (error) => { + var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); + Modal.createDialog(ErrorDialog, { + title: "Error saving email notification preferences", + description: "Vector was unable to save your email notification preferences.", + }); + }); + }, + onNotifStateButtonClicked: function(event) { // FIXME: use .bind() rather than className metadata here surely var vectorRuleId = event.target.className.split("-")[0]; @@ -632,25 +652,8 @@ module.exports = React.createClass({ ref="enableEmailNotifications_{address}" type="checkbox" checked={ UserSettingsStore.hasEmailPusher(this.state.pushers, address) } - onChange={ (e) => { - var emailPusherPromise; - if (e.target.checked) { - emailPusherPromise = UserSettingsStore.addEmailPusher(address); - } else { - var emailPusher = UserSettingsStore.getEmailPusher(this.state.pushers, address); - emailPusher.kind = null; - emailPusherPromise = MatrixClientPeg.get().setPusher(emailPusher); - } - emailPusherPromise.done(() => { - this._refreshFromServer(); - }, (error) => { - var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); - Modal.createDialog(ErrorDialog, { - title: "Error saving email notification preferences", - description: "Vector was unable to save your email notification preferences.", - }); - }); - }} /> + onChange={ this.onEnableEmailNotificationsChange.bind(this, address) } + />
); @@ -742,13 +742,11 @@ module.exports = React.createClass({ var devicesSection; if (this.state.pushers === undefined) { - devicesSection =
Unable to fetch device list
+ devicesSection =
Unable to fetch notification target list
} else if (this.state.pushers.length == 0) { - devicesSection =
- No devices are receiving push notifications -
+ devicesSection = null; } else { - // It would be great to be able to delete pushers from here too, + // TODO: It would be great to be able to delete pushers from here too, // and this wouldn't be hard to add. var rows = []; for (var i = 0; i < this.state.pushers.length; ++i) { @@ -758,17 +756,17 @@ module.exports = React.createClass({ ); } devicesSection = ( - - - - - - {rows}
ApplicationDevice
); } + if (devicesSection) { + devicesSection = (
+

Notification targets

+ { devicesSection } +
); + } var advancedSettings; if (externalRules.length) { @@ -828,8 +826,6 @@ module.exports = React.createClass({ { emailNotificationsRow } -

General use

-
@@ -850,7 +846,6 @@ module.exports = React.createClass({ { advancedSettings } -

Devices

{ devicesSection }