Update display name in realtime across tabs and remember 'anonymous' name

This commit is contained in:
yflory
2017-02-16 15:35:03 +01:00
parent 7762ffcbff
commit e4dbe97d71
9 changed files with 62 additions and 111 deletions

View File

@@ -71,6 +71,7 @@ define([
var userHashKey = common.userHashKey = 'User_hash';
var userNameKey = common.userNameKey = 'User_name';
var fileHashKey = common.fileHashKey = 'FS_hash';
var displayNameKey = common.displayNameKey = 'cryptpad.username';
var login = common.login = function (hash, name, cb) {
if (!hash) { throw new Error('expected a user hash'); }
@@ -534,6 +535,25 @@ define([
});
};
// STORAGE: Display Name
var getLastName = common.getLastName = function (cb) {
common.getAttribute('username', function (err, userName) {
cb(err, userName);
});
};
var _onDisplayNameChanged = [];
var onDisplayNameChanged = common.onDisplayNameChanged = function (h) {
if (typeof(h) !== "function") { return; }
if (_onDisplayNameChanged.indexOf(h) !== -1) { return; }
_onDisplayNameChanged.push(h);
};
var changeDisplayName = common.changeDisplayName = function (newName) {
_onDisplayNameChanged.forEach(function (h) {
h(newName);
});
};
// STORAGE
var forgetPad = common.forgetPad = function (href, cb) {
var parsed = parsePadUrl(href);