Teams: setPadAttribute and getPadAttribute

pull/1/head
yflory 5 years ago
parent 4c339afc6c
commit 35a429d30c

@ -761,18 +761,42 @@ define([
* - attr (Array) * - attr (Array)
* - value (String) * - value (String)
*/ */
var getAllStores = function () {
var stores = [store];
var teamModule = store.modules['team'];
if (teamModule) {
var teams = teamModule.getTeams().map(function (id) {
return teamModule.getTeam(id);
});
Array.prototype.push.apply(stores, teams);
}
return stores;
};
Store.setPadAttribute = function (clientId, data, cb) { Store.setPadAttribute = function (clientId, data, cb) {
store.manager.setPadAttribute(data, function () { getAllStores.forEach(function (s) {
sendDriveEvent('DRIVE_CHANGE', { s.manager.setPadAttribute(data, function () {
path: ['drive', UserObject.FILES_DATA] var send = s.id ? s.sendEvent : sendDriveEvent;
}, clientId); send('DRIVE_CHANGE', {
onSync(cb); path: ['drive', UserObject.FILES_DATA]
}, clientId);
onSync(s.id, cb);
});
}); });
}; };
Store.getPadAttribute = function (clientId, data, cb) { Store.getPadAttribute = function (clientId, data, cb) {
store.manager.getPadAttribute(data, function (err, val) { var res = {};
if (err) { return void cb({error: err}); } nThen(function (waitFor) {
cb(val); getAllStores.forEach(function (s) {
s.manager.getPadAttribute(data, waitFor(function (err, val) {
if (err) { return; }
if (!res.value || res.atime < val.atime) {
res.atime = val.atime;
res.value = val.value;
}
}));
});
}).nThen(function () {
cb(res.value);
}); });
}; };

@ -37,11 +37,13 @@ define([
// load shared folders // load shared folders
// ~resetPins for the team? // ~resetPins for the team?
// getPinLimit // getPinLimit
ctx.teams[id] = team;
cb();
}; };
var openChannel = function (ctx, team, id, cb) { var openChannel = function (ctx, teamData, id, cb) {
// XXX team password? // XXX team password?
var secret = Hash.getSecrets('team', team.href); var secret = Hash.getSecrets('team', teamData.href);
var crypto = Crypto.createEncryptor(secret.keys); var crypto = Crypto.createEncryptor(secret.keys);
var cfg = { var cfg = {
@ -65,7 +67,8 @@ define([
// types are DRIVE_CHANGE, DRIVE_REMOVE and DRIVE_LOG // types are DRIVE_CHANGE, DRIVE_REMOVE and DRIVE_LOG
}; };
ctx.teams[id] = { var team = {
id: id,
proxy: lm.proxy, proxy: lm.proxy,
listmap: lm, listmap: lm,
clients: [], clients: [],
@ -78,6 +81,7 @@ define([
onReady(ctx, team, id, function () { onReady(ctx, team, id, function () {
// TODO // TODO
cb();
}); });
if (ctx.onReadyHandlers.length) { if (ctx.onReadyHandlers.length) {
ctx.onReadyHandlers.forEach(function (f) { ctx.onReadyHandlers.forEach(function (f) {
@ -145,6 +149,9 @@ define([
team.getTeam = function (id) { team.getTeam = function (id) {
return ctx.teams[id]; return ctx.teams[id];
}; };
team.getTeams = function () {
return Object.keys(ctx.teams);
};
team.removeClient = function (clientId) { team.removeClient = function (clientId) {
removeClient(ctx, clientId); removeClient(ctx, clientId);
}; };

@ -736,11 +736,15 @@ define([
// We're going to return the value with the most recent atime. The attributes may have been // We're going to return the value with the most recent atime. The attributes may have been
// updated in a shared folder by another user, so the most recent one is more likely to be the // updated in a shared folder by another user, so the most recent one is more likely to be the
// correct one. // correct one.
// NOTE: we also return the atime, so that we can also check with each team manager
var getPadAttribute = function (Env, data, cb) { var getPadAttribute = function (Env, data, cb) {
cb = cb || function () {}; cb = cb || function () {};
var sfId = Env.user.userObject.getSFIdFromHref(data.href); var sfId = Env.user.userObject.getSFIdFromHref(data.href);
if (sfId) { if (sfId) {
return void cb(null, Env.user.proxy[UserObject.SHARED_FOLDERS][sfId][data.attr]); setTimeout(function () {
cb(null, Env.user.proxy[UserObject.SHARED_FOLDERS][sfId][data.attr]);
});
return;
} }
var datas = findHref(Env, data.href); var datas = findHref(Env, data.href);
var res = {}; var res = {};
@ -753,7 +757,9 @@ define([
res.value = value; res.value = value;
} }
}); });
cb(null, res.value); setTimeout(function () {
cb(null, res);
});
}; };
var getTagsList = function (Env) { var getTagsList = function (Env) {

Loading…
Cancel
Save