diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 7862adb31..14584220a 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -44,6 +44,15 @@ define([ } return; }; + + var getUid = common.getUid = function () { + if (store) { + if (store.getProxy() && store.getProxy().proxy) { + return store.getProxy().proxy.uid; + } + } + }; + var getRealtime = common.getRealtime = function () { if (store) { if (store.getProxy() && store.getProxy().info) { diff --git a/www/common/fsStore.js b/www/common/fsStore.js index e4b86c1c8..794a39ecd 100644 --- a/www/common/fsStore.js +++ b/www/common/fsStore.js @@ -145,6 +145,12 @@ define([ 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) { if (typeof(n) !== "string") { return; } Cryptpad.changeDisplayName(n); @@ -156,6 +162,7 @@ define([ var init = function (f, Cryptpad) { if (!Cryptpad || initialized) { return; } initialized = true; + var hash = Cryptpad.getUserHash() || localStorage.FS_hash || Cryptpad.createRandomHash(); if (!hash) { throw new Error('[Store.init] Unable to find or create a drive hash. Aborting...');