Improve sharing between drive and teams

This commit is contained in:
yflory
2019-09-18 16:02:58 +02:00
parent fc2938a27e
commit 0d3f9db184
5 changed files with 75 additions and 37 deletions

View File

@@ -958,10 +958,13 @@ define([
expire = data.expire;
}
var storeLocally = data.teamId === -1;
if (data.teamId === -1) { data.teamId = undefined; }
// If a teamId is provided, it means we want to store the pad in a specific
// team drive. In this case, we just need to check if the pad is already
// stored in th eteam drive.
// If no team ID is provided, this may be a pad shared iwth its URL.
// stored in this team drive.
// If no team ID is provided, this may be a pad shared with its URL.
// We need to check if the pad is stored in any managers (user or teams).
// If it is stored, update its data, otherwise ask the user if they want to store it
var allData = [];
@@ -969,6 +972,7 @@ define([
var inMyDrive;
getAllStores().forEach(function (s) {
if (data.teamId && s.id !== data.teamId) { return; }
if (storeLocally && s.id) { return; }
var res = s.manager.findChannel(channel);
if (res.length) {

View File

@@ -447,16 +447,8 @@ define([
});
};
var subscribe = function (ctx, id, cId, cb) {
// Unsubscribe from other teams: one tab can only receive events about one team
Object.keys(ctx.teams).forEach(function (teamId) {
var c = ctx.teams[teamId].clients;
var idx = c.indexOf(cId);
if (idx !== -1) {
c.splice(idx, 1);
}
});
// Also remove from pending subscriptions
// Remove a client from all the team they're subscribed to
var removeClient = function (ctx, cId) {
Object.keys(ctx.onReadyHandlers).forEach(function (teamId) {
var idx = -1;
ctx.onReadyHandlers[teamId].some(function (obj, _idx) {
@@ -469,6 +461,17 @@ define([
ctx.onReadyHandlers[teamId].splice(idx, 1);
}
});
Object.keys(ctx.teams).forEach(function (id) {
var clients = ctx.teams[id].clients;
var idx = clients.indexOf(cId);
if (idx !== -1) { clients.splice(idx, 1); }
});
};
var subscribe = function (ctx, id, cId, cb) {
// Unsubscribe from other teams: one tab can only receive events about one team
removeClient(ctx, cId);
// And leave the channel channel
try {
ctx.store.messenger.removeClient(cId);
@@ -504,22 +507,6 @@ define([
ctx.store.messenger.openTeamChat(team.getChatData(), cId, cb);
};
// Remove a client from all the team they're subscribed to
var removeClient = function (ctx, cId) {
Object.keys(ctx.teams).forEach(function (id) {
// Remove from the subscribers
var clients = ctx.teams[id].clients;
var idx = clients.indexOf(cId);
if (idx !== -1) { clients.splice(idx, 1); }
// And remove from the onReady handlers in case they haven't finished loading
if (ctx.onReadyHandlers[id]) {
var idx2 = ctx.onReadyHandlers.indexOf(cId);
if (idx2 !== -1) { ctx.onReadyHandlers.splice(idx2, 1); }
}
});
};
Team.init = function (cfg, waitFor, emit) {
var team = {};
var store = cfg.store;