From a2edf5be64e7d40431ec3a2875510770ad0c6b17 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 4 Sep 2019 17:59:44 +0200 Subject: [PATCH] Preparations for the Team refactoring --- www/common/outer/async-store.js | 25 +++++++++++++++++++++++++ www/common/outer/team.js | 21 ++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 900839d6f..1904ba9cd 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -43,6 +43,31 @@ define([ modules: {} }; + var getProxy = function (teamId) { + if (!teamId) { return store.proxy; } + try { + var teams = store.modules['team']; + var team = teams.getTeam(teamId); + if (team) { return; } + return team.proxy; + } catch (e) { + console.error(e); + return; + } + }; + var getManager = function (teamId) { + if (!teamId) { return store.manager; } + try { + var teams = store.modules['team']; + var team = teams.getTeam(teamId); + if (team) { return; } + return team.manager; + } catch (e) { + console.error(e); + return; + } + }; + var onSync = function (cb) { nThen(function (waitFor) { Realtime.whenRealtimeSyncs(store.realtime, waitFor()); diff --git a/www/common/outer/team.js b/www/common/outer/team.js index 90a8aee1c..bc49f8a3e 100644 --- a/www/common/outer/team.js +++ b/www/common/outer/team.js @@ -3,10 +3,15 @@ define([ '/common/common-hash.js', '/common/common-constants.js', '/common/common-realtime.js', + + '/common/outer/sharedfolder.js', + '/bower_components/chainpad-listmap/chainpad-listmap.js', '/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad/chainpad.dist.js', -], function (Util, Hash, Constants, Realtime, Listmap, Crypto, ChainPad) { +], function (Util, Hash, Constants, Realtime, + SF, + Listmap, Crypto, ChainPad) { var Team = {}; var initializeTeams = function (ctx, cb) { @@ -14,6 +19,13 @@ define([ cb(); }; + var onready = function (ctx, team, id, cb) { + // XXX + // load manager + // load shared folders + + }; + var openChannel = function (ctx, team, id, cb) { // XXX team password? var secret = Hash.getSecrets('team', team.href); @@ -35,9 +47,13 @@ define([ lm.proxy.on('create', function () { }).on('ready', function () { ctx.teams[id] = { + proxy: lm.proxy, listmap: lm, clients: [] }; + onReady(ctx, team, id, function () { + // TODO + }); if (ctx.onReadyHandlers.length) { ctx.onReadyHandlers.forEach(function (f) { try { @@ -101,6 +117,9 @@ define([ }); }); + team.getTeam = function (id) { + return ctx.teams[id]; + }; team.removeClient = function (clientId) { removeClient(ctx, clientId); };