diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 71848e36d..e027738ad 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -2273,7 +2273,7 @@ define([ var o = e.oldValue; var n = e.newValue; if (!o && n) { - document.location.reload(); + LocalStore.loginReload(); } else if (o && !n) { LocalStore.logout(); } diff --git a/www/common/outer/local-store.js b/www/common/outer/local-store.js index 8c39e8e9e..fbda718d4 100644 --- a/www/common/outer/local-store.js +++ b/www/common/outer/local-store.js @@ -129,6 +129,18 @@ define([ if (cb) { cb(); } }; + var loginHandlers = []; + LocalStore.loginReload = function () { + loginHandlers.forEach(function (h) { + if (typeof (h) === "function") { h(); } + }); + document.location.reload(); + }; + LocalStore.onLogin = function (h) { + if (typeof (h) !== "function") { return; } + if (loginHandlers.indexOf(h) !== -1) { return; } + loginHandlers.push(h); + }; LocalStore.onLogout = function (h) { if (typeof (h) !== "function") { return; } if (logoutHandlers.indexOf(h) !== -1) { return; } diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 7253d8f1a..61cc1e694 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -511,7 +511,19 @@ define([ Cryptpad.onMetadataChanged(updateMeta); sframeChan.onReg('EV_METADATA_UPDATE', updateMeta); + Utils.LocalStore.onLogin(function () { + var ohc = window.onhashchange; + window.onhashchange = function () {}; + window.location.hash = currentPad.hash; + window.onhashchange = ohc; + ohc({reset: true}); + }); Utils.LocalStore.onLogout(function () { + var ohc = window.onhashchange; + window.onhashchange = function () {}; + window.location.hash = currentPad.hash; + window.onhashchange = ohc; + ohc({reset: true}); sframeChan.event('EV_LOGOUT'); });