incorporate keganfeedback

pull/21833/head
Matthew Hodgson 2016-03-12 19:49:54 +00:00
parent a82d3710d1
commit 893e338917
2 changed files with 16 additions and 20 deletions

View File

@ -35,7 +35,7 @@ function deviceId() {
return id; return id;
} }
function createClient(hs_url, is_url, user_id, access_token, guestAccess) { function createClientForPeg(hs_url, is_url, user_id, access_token, guestAccess) {
var opts = { var opts = {
baseUrl: hs_url, baseUrl: hs_url,
idBaseUrl: is_url, idBaseUrl: is_url,
@ -69,7 +69,7 @@ if (localStorage) {
var guestAccess = new GuestAccess(localStorage); var guestAccess = new GuestAccess(localStorage);
if (access_token && user_id && hs_url) { if (access_token && user_id && hs_url) {
console.log("Restoring session for %s", user_id); console.log("Restoring session for %s", user_id);
createClient(hs_url, is_url, user_id, access_token, guestAccess); createClientForPeg(hs_url, is_url, user_id, access_token, guestAccess);
} }
else { else {
console.log("Session not found."); console.log("Session not found.");
@ -92,7 +92,7 @@ class MatrixClient {
// FIXME, XXX: this all seems very convoluted :( // FIXME, XXX: this all seems very convoluted :(
// //
// if we replace the singleton using URLs we bypass our createClient() // if we replace the singleton using URLs we bypass our createClientForPeg()
// global helper function... but if we replace it using // global helper function... but if we replace it using
// an access_token we don't? // an access_token we don't?
// //
@ -102,7 +102,6 @@ class MatrixClient {
// -matthew // -matthew
replaceUsingUrls(hs_url, is_url) { replaceUsingUrls(hs_url, is_url) {
// ...not to be confused with MatrixClientPeg's createClient...
matrixClient = Matrix.createClient({ matrixClient = Matrix.createClient({
baseUrl: hs_url, baseUrl: hs_url,
idBaseUrl: is_url idBaseUrl: is_url
@ -130,8 +129,7 @@ class MatrixClient {
} }
} }
this.guestAccess.markAsGuest(Boolean(isGuest)); this.guestAccess.markAsGuest(Boolean(isGuest));
// ...not to be confused with Matrix.createClient()... createClientForPeg(hs_url, is_url, user_id, access_token, this.guestAccess);
createClient(hs_url, is_url, user_id, access_token, this.guestAccess);
if (localStorage) { if (localStorage) {
try { try {
localStorage.setItem("mx_hs_url", hs_url); localStorage.setItem("mx_hs_url", hs_url);

View File

@ -118,8 +118,8 @@ module.exports = React.createClass({
componentDidMount: function() { componentDidMount: function() {
this._autoRegisterAsGuest = false; this._autoRegisterAsGuest = false;
if (this.props.enableGuest) { if (this.props.enableGuest) {
if (!this.getCurrentHsUrl() || !this.getCurrentIsUrl()) { if (!this.getCurrentHsUrl()) {
console.error("Cannot enable guest access: can't determine HS/IS URLs to use"); console.error("Cannot enable guest access: can't determine HS URL to use");
} }
else if (this.props.startingQueryParams.client_secret && this.props.startingQueryParams.sid) { else if (this.props.startingQueryParams.client_secret && this.props.startingQueryParams.sid) {
console.log("Not registering as guest; registration."); console.log("Not registering as guest; registration.");
@ -182,18 +182,18 @@ module.exports = React.createClass({
_registerAsGuest: function() { _registerAsGuest: function() {
var self = this; var self = this;
console.log("Doing guest login on %s", this.getCurrentHsUrl()); console.log("Doing guest login on %s", this.getCurrentHsUrl());
MatrixClientPeg.replaceUsingUrls( var hsUrl = this.getCurrentHsUrl();
this.getCurrentHsUrl(), var isUrl = this.getCurrentIsUrl();
this.getCurrentIsUrl()
); MatrixClientPeg.replaceUsingUrls(hsUrl, isUrl);
MatrixClientPeg.get().registerGuest().done(function(creds) { MatrixClientPeg.get().registerGuest().done(function(creds) {
console.log("Registered as guest: %s", creds.user_id); console.log("Registered as guest: %s", creds.user_id);
self._setAutoRegisterAsGuest(false); self._setAutoRegisterAsGuest(false);
self.onLoggedIn({ self.onLoggedIn({
userId: creds.user_id, userId: creds.user_id,
accessToken: creds.access_token, accessToken: creds.access_token,
homeserverUrl: self.getCurrentHsUrl(), homeserverUrl: hsUrl,
identityServerUrl: self.getCurrentIsUrl(), identityServerUrl: isUrl,
guest: true guest: true
}); });
}, function(err) { }, function(err) {
@ -214,12 +214,10 @@ module.exports = React.createClass({
switch (payload.action) { switch (payload.action) {
case 'logout': case 'logout':
if (window.localStorage) { if (window.localStorage) {
// preserve our HS & IS URLs for convenience
var hsUrl = this.getCurrentHsUrl();
var isUrl = this.getCurrentIsUrl();
window.localStorage.clear(); window.localStorage.clear();
window.localStorage.setItem("mx_hs_url", hsUrl); // preserve our HS & IS URLs for convenience
window.localStorage.setItem("mx_is_url", isUrl); window.localStorage.setItem("mx_hs_url", this.getCurrentHsUrl());
window.localStorage.setItem("mx_is_url", this.getCurrentIsUrl());
} }
Notifier.stop(); Notifier.stop();
UserActivity.stop(); UserActivity.stop();