mirror of https://github.com/xwiki-labs/cryptpad
add a unique id to user objects, define a getter
This commit is contained in:
parent
d1c32ea1f8
commit
40f5e1706f
www/common
|
@ -44,6 +44,15 @@ define([
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var getUid = common.getUid = function () {
|
||||||
|
if (store) {
|
||||||
|
if (store.getProxy() && store.getProxy().proxy) {
|
||||||
|
return store.getProxy().proxy.uid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var getRealtime = common.getRealtime = function () {
|
var getRealtime = common.getRealtime = function () {
|
||||||
if (store) {
|
if (store) {
|
||||||
if (store.getProxy() && store.getProxy().info) {
|
if (store.getProxy() && store.getProxy().info) {
|
||||||
|
|
|
@ -145,6 +145,12 @@ define([
|
||||||
proxy.allowUserFeedback = true;
|
proxy.allowUserFeedback = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof(proxy.uid) !== 'string' || proxy.uid.length !== 32) {
|
||||||
|
// even anonymous users should have a persistent, unique-ish id
|
||||||
|
console.log('generating a persistent identifier');
|
||||||
|
proxy.uid = Cryptpad.createChannelId();
|
||||||
|
}
|
||||||
|
|
||||||
proxy.on('change', [Cryptpad.displayNameKey], function (o, n, p) {
|
proxy.on('change', [Cryptpad.displayNameKey], function (o, n, p) {
|
||||||
if (typeof(n) !== "string") { return; }
|
if (typeof(n) !== "string") { return; }
|
||||||
Cryptpad.changeDisplayName(n);
|
Cryptpad.changeDisplayName(n);
|
||||||
|
@ -156,6 +162,7 @@ define([
|
||||||
var init = function (f, Cryptpad) {
|
var init = function (f, Cryptpad) {
|
||||||
if (!Cryptpad || initialized) { return; }
|
if (!Cryptpad || initialized) { return; }
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
|
||||||
var hash = Cryptpad.getUserHash() || localStorage.FS_hash || Cryptpad.createRandomHash();
|
var hash = Cryptpad.getUserHash() || localStorage.FS_hash || Cryptpad.createRandomHash();
|
||||||
if (!hash) {
|
if (!hash) {
|
||||||
throw new Error('[Store.init] Unable to find or create a drive hash. Aborting...');
|
throw new Error('[Store.init] Unable to find or create a drive hash. Aborting...');
|
||||||
|
|
Loading…
Reference in New Issue