From 1d314631403500c6df17ab57292f9218d4e00ac5 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 2 Jun 2016 13:14:52 +0100 Subject: [PATCH] set email branding after registration --- src/Signup.js | 7 +----- src/UserSettingsStore.js | 4 ++-- .../structures/login/Registration.js | 22 ++++++++++++++++++- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Signup.js b/src/Signup.js index c4fce88262..4518955d95 100644 --- a/src/Signup.js +++ b/src/Signup.js @@ -51,7 +51,6 @@ class Register extends Signup { this.username = undefined; // desired this.email = undefined; // desired this.password = undefined; // desired - this.brand = undefined; // optional brand to let the HS brand its mail notifs } setClientSecret(secret) { @@ -74,10 +73,6 @@ class Register extends Signup { this.guestAccessToken = token; } - setBrand(brand) { - this.brand = brand; - } - getStep() { return this._step; } @@ -136,7 +131,7 @@ class Register extends Signup { return MatrixClientPeg.get().register( this.username, this.password, this.params.sessionId, authDict, bindEmail, - this.guestAccessToken, this.brand + this.guestAccessToken ).then(function(result) { self.credentials = result; self.setStep("COMPLETE"); diff --git a/src/UserSettingsStore.js b/src/UserSettingsStore.js index cf7131eb7b..9bb1388e76 100644 --- a/src/UserSettingsStore.js +++ b/src/UserSettingsStore.js @@ -100,7 +100,7 @@ module.exports = { return this.getEmailPusher(pushers, address) !== undefined; }, - addEmailPusher: function(address) { + addEmailPusher: function(address, data) { return MatrixClientPeg.get().setPusher({ kind: 'email', app_id: "m.email", @@ -108,7 +108,7 @@ module.exports = { app_display_name: 'Email Notifications', device_display_name: address, lang: navigator.language, - data: {}, + data: data, append: true, // We always append for email pushers since we don't want to stop other accounts notifying to the same email address }); }, diff --git a/src/components/structures/login/Registration.js b/src/components/structures/login/Registration.js index e1b3780435..2f15a3b5df 100644 --- a/src/components/structures/login/Registration.js +++ b/src/components/structures/login/Registration.js @@ -22,6 +22,7 @@ var sdk = require('../../../index'); var dis = require('../../../dispatcher'); var Signup = require("../../../Signup"); var ServerConfig = require("../../views/login/ServerConfig"); +var MatrixClientPeg = require("../../../MatrixClientPeg"); var RegistrationForm = require("../../views/login/RegistrationForm"); var CaptchaForm = require("../../views/login/CaptchaForm"); @@ -67,7 +68,6 @@ module.exports = React.createClass({ this.registerLogic.setRegistrationUrl(this.props.registrationUrl); this.registerLogic.setIdSid(this.props.idSid); this.registerLogic.setGuestAccessToken(this.props.guestAccessToken); - this.registerLogic.setBrand(this.props.brand); this.registerLogic.recheckState(); }, @@ -147,6 +147,26 @@ module.exports = React.createClass({ identityServerUrl: self.registerLogic.getIdentityServerUrl(), accessToken: response.access_token }); + + if (self.props.brand) { + MatrixClientPeg.get().getPushers().done((resp)=>{ + var pushers = resp.pushers; + for (var i = 0; i < pushers.length; ++i) { + if (pushers[i].kind == 'email') { + var emailPusher = pushers[i]; + emailPusher.data = { brand: self.props.brand }; + MatrixClientPeg.get().setPusher(emailPusher).done(() => { + console.log("Set email branding to " + self.props.brand); + }, (error) => { + console.error("Couldn't set email branding: " + error); + }); + } + } + }, (error) => { + console.error("Couldn't get pushers: " + error); + }); + } + }, function(err) { if (err.message) { self.setState({