diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index a09869a08..129b6a46f 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -2079,7 +2079,7 @@ define([ */ // NOTE: The callback must stay SYNCHRONOUS var LIMIT_REFRESH_RATE = 30000; // milliseconds - UIElements.createUsageBar = function (common, cb) { + UIElements.createUsageBar = function (common, teamId, cb) { if (AppConfig.hideUsageBar) { return cb('USAGE_BAR_HIDDEN'); } if (!common.isLoggedIn()) { return cb("NOT_LOGGED_IN"); } // getPinnedUsage updates common.account.usage, and other values @@ -2161,15 +2161,20 @@ define([ }; var updateUsage = Util.notAgainForAnother(function () { - common.getPinUsage(todo); + common.getPinUsage(teamId, todo); }, LIMIT_REFRESH_RATE); - setInterval(function () { + var interval = setInterval(function () { updateUsage(); }, LIMIT_REFRESH_RATE * 3); updateUsage(); cb(null, $container); + return { + stop: function () { + clearInterval(interval); + } + }; }; // Create a button with a dropdown menu diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index c389bb4ce..a7b554420 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -223,8 +223,8 @@ define([ }); }; - common.getPinnedUsage = function (cb) { - postMessage("GET_PINNED_USAGE", null, function (obj) { + common.getPinnedUsage = function (data, cb) { + postMessage("GET_PINNED_USAGE", data, function (obj) { if (obj.error) { return void cb(obj.error); } cb(null, obj.bytes); }); @@ -237,14 +237,14 @@ define([ }); }; - common.getPinLimit = function (cb) { - postMessage("GET_PIN_LIMIT", null, function (obj) { + common.getPinLimit = function (data, cb) { + postMessage("GET_PIN_LIMIT", data, function (obj) { if (obj.error) { return void cb(obj.error); } cb(undefined, obj.limit, obj.plan, obj.note); }); }; - common.isOverPinLimit = function (cb) { + common.isOverPinLimit = function (teamId, cb) { if (!LocalStore.isLoggedIn()) { return void cb(null, false); } var usage; var andThen = function (e, limit, plan) { @@ -258,9 +258,13 @@ define([ var todo = function (e, used) { if (e) { return void cb(e); } usage = used; - common.getPinLimit(andThen); + common.getPinLimit({ + teamId: teamId + }, andThen); }; - common.getPinnedUsage(todo); + common.getPinnedUsage({ + teamId: teamId + }, todo); }; common.clearOwnedChannel = function (channel, cb) { diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 8f4d7854b..d77da7c39 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -227,10 +227,11 @@ define([ var account = {}; Store.getPinnedUsage = function (clientId, data, cb) { - if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); } + var s = getStore(data && data.teamId); + if (!s.rpc) { return void cb({error: 'RPC_NOT_READY'}); } - store.rpc.getFileListSize(function (err, bytes) { - if (typeof(bytes) === 'number') { + s.rpc.getFileListSize(function (err, bytes) { + if (!s.id && typeof(bytes) === 'number') { account.usage = bytes; } cb({bytes: bytes}); @@ -250,18 +251,20 @@ define([ }; // Get current user limits Store.getPinLimit = function (clientId, data, cb) { - if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); } + var s = getStore(data && data.teamId); + if (!s.rpc) { return void cb({error: 'RPC_NOT_READY'}); } var ALWAYS_REVALIDATE = true; if (ALWAYS_REVALIDATE || typeof(account.limit) !== 'number' || typeof(account.plan) !== 'string' || typeof(account.note) !== 'string') { - return void store.rpc.getLimit(function (e, limit, plan, note) { + return void s.rpc.getLimit(function (e, limit, plan, note) { if (e) { return void cb({error: e}); } - account.limit = limit; - account.plan = plan; - account.note = note; - cb(account); + var data = s.id ? {} : account; + data.limit = limit; + data.plan = plan; + data.note = note; + cb(data); }); } cb(account); diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 5bfd8f898..d3e49559d 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -378,7 +378,7 @@ define([ }); sframeChan.on('Q_GET_PIN_LIMIT_STATUS', function (data, cb) { - Cryptpad.isOverPinLimit(function (e, overLimit, limits) { + Cryptpad.isOverPinLimit(null, function (e, overLimit, limits) { cb({ error: e, overLimit: overLimit, @@ -905,8 +905,8 @@ define([ } }); - sframeChan.on('Q_PIN_GET_USAGE', function (data, cb) { - Cryptpad.isOverPinLimit(function (err, overLimit, data) { + sframeChan.on('Q_PIN_GET_USAGE', function (teamId, cb) { + Cryptpad.isOverPinLimit(teamId, function (err, overLimit, data) { cb({ error: err, data: data diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index 11061fd80..2f22a2b57 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -327,9 +327,9 @@ define([ if (cb) { cb(data); } }); }; - funcs.getPinUsage = function (cb) { + funcs.getPinUsage = function (teamId, cb) { cb = cb || $.noop; - ctx.sframeChan.query('Q_PIN_GET_USAGE', null, function (err, data) { + ctx.sframeChan.query('Q_PIN_GET_USAGE', teamId, function (err, data) { cb(err || data.error, data.data); }); }; diff --git a/www/drive/inner.js b/www/drive/inner.js index fd0101154..ed986bf32 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -160,7 +160,7 @@ define([ /* add the usage */ if (APP.loggedIn) { - common.createUsageBar(function (err, $limitContainer) { + common.createUsageBar(null, function (err, $limitContainer) { if (err) { return void DriveUI.logError(err); } APP.$limit = $limitContainer; }, true); diff --git a/www/settings/inner.js b/www/settings/inner.js index 22ad7cc49..6fe07e3fe 100644 --- a/www/settings/inner.js +++ b/www/settings/inner.js @@ -1519,7 +1519,7 @@ define([ // Settings app var createUsageButton = function () { - common.createUsageBar(function (err, $bar) { + common.createUsageBar(null, function (err, $bar) { if (err) { return void console.error(err); } APP.$usage.html('').append($bar); }, true); diff --git a/www/team/inner.js b/www/team/inner.js index c9a0ff4ca..68851dd6e 100644 --- a/www/team/inner.js +++ b/www/team/inner.js @@ -213,6 +213,11 @@ define([ if (!proxy.drive || typeof(proxy.drive) !== 'object') { throw new Error("Corrupted drive"); } + if (APP.usageBar) { APP.usageBar.stop(); } + APP.usageBar = common.createUsageBar(APP.team, function (err, $limitContainer) { + if (err) { return void DriveUI.logError(err); } + driveAPP.$limit = $limitContainer; + }, true); driveAPP.team = id; var drive = DriveUI.create(common, { proxy: proxy, @@ -722,16 +727,6 @@ define([ driveAPP.$displayName.text(name); }); - /* add the usage */ - // XXX Teams - if (false) { - // Synchronous callback... - common.createUsageBar(function (err, $limitContainer) { - if (err) { return void DriveUI.logError(err); } - driveAPP.$limit = $limitContainer; - }, true); - } - // Load the Team module var onEvent = function (obj) { var ev = obj.ev;