Use offline state per team and not global state
parent
b1f29678ca
commit
ebd007fdb9
|
@ -57,11 +57,11 @@ define([
|
|||
});
|
||||
proxy.on('disconnect', function () {
|
||||
team.offline = true;
|
||||
team.sendEvent('NETWORK_DISCONNECT');
|
||||
team.sendEvent('NETWORK_DISCONNECT', team.id);
|
||||
});
|
||||
proxy.on('reconnect', function () {
|
||||
team.offline = false;
|
||||
team.sendEvent('NETWORK_RECONNECT');
|
||||
team.sendEvent('NETWORK_RECONNECT', team.id);
|
||||
});
|
||||
}
|
||||
proxy.on('change', [], function (o, n, p) {
|
||||
|
@ -931,7 +931,9 @@ define([
|
|||
if (!team) { return void cb ({error: 'ENOENT'}); }
|
||||
if (!team.roster) { return void cb({error: 'NO_ROSTER'}); }
|
||||
var state = team.roster.getState() || {};
|
||||
cb(state.metadata || {});
|
||||
var md = state.metadata || {};
|
||||
md.offline = team.offline;
|
||||
cb(md);
|
||||
};
|
||||
|
||||
var setTeamMetadata = function (ctx, data, cId, cb) {
|
||||
|
@ -1879,15 +1881,15 @@ define([
|
|||
var t = Util.clone(teams);
|
||||
Object.keys(t).forEach(function (id) {
|
||||
// If failure to load the team, don't send it
|
||||
if (ctx.teams[id]) { return; }
|
||||
if (ctx.teams[id]) {
|
||||
t[id].offline = ctx.teams[id].offline;
|
||||
return;
|
||||
}
|
||||
t[id].error = true;
|
||||
});
|
||||
cb(t);
|
||||
};
|
||||
team.execCommand = function (clientId, obj, cb) {
|
||||
if (ctx.store.offline) {
|
||||
return void cb({ error: 'OFFLINE' });
|
||||
}
|
||||
|
||||
var cmd = obj.cmd;
|
||||
var data = obj.data;
|
||||
|
@ -1911,30 +1913,36 @@ define([
|
|||
return void setTeamMetadata(ctx, data, clientId, cb);
|
||||
}
|
||||
if (cmd === 'OFFER_OWNERSHIP') {
|
||||
if (ctx.store.offline) { return void cb({ error: 'OFFLINE' }); }
|
||||
return void offerOwnership(ctx, data, clientId, cb);
|
||||
}
|
||||
if (cmd === 'ANSWER_OWNERSHIP') {
|
||||
if (ctx.store.offline) { return void cb({ error: 'OFFLINE' }); }
|
||||
return void answerOwnership(ctx, data, clientId, cb);
|
||||
}
|
||||
if (cmd === 'DESCRIBE_USER') {
|
||||
return void describeUser(ctx, data, clientId, cb);
|
||||
}
|
||||
if (cmd === 'INVITE_TO_TEAM') {
|
||||
if (ctx.store.offline) { return void cb({ error: 'OFFLINE' }); }
|
||||
return void inviteToTeam(ctx, data, clientId, cb);
|
||||
}
|
||||
if (cmd === 'LEAVE_TEAM') {
|
||||
return void leaveTeam(ctx, data, clientId, cb);
|
||||
}
|
||||
if (cmd === 'JOIN_TEAM') {
|
||||
if (ctx.store.offline) { return void cb({ error: 'OFFLINE' }); }
|
||||
return void joinTeam(ctx, data, clientId, cb);
|
||||
}
|
||||
if (cmd === 'REMOVE_USER') {
|
||||
return void removeUser(ctx, data, clientId, cb);
|
||||
}
|
||||
if (cmd === 'DELETE_TEAM') {
|
||||
if (ctx.store.offline) { return void cb({ error: 'OFFLINE' }); }
|
||||
return void deleteTeam(ctx, data, clientId, cb);
|
||||
}
|
||||
if (cmd === 'CREATE_TEAM') {
|
||||
if (ctx.store.offline) { return void cb({ error: 'OFFLINE' }); }
|
||||
return void createTeam(ctx, data, clientId, cb);
|
||||
}
|
||||
if (cmd === 'GET_EDITABLE_FOLDERS') {
|
||||
|
@ -1947,6 +1955,7 @@ define([
|
|||
return void getPreviewContent(ctx, data, clientId, cb);
|
||||
}
|
||||
if (cmd === 'ACCEPT_LINK_INVITATION') {
|
||||
if (ctx.store.offline) { return void cb({ error: 'OFFLINE' }); }
|
||||
return void acceptLinkInvitation(ctx, data, clientId, cb);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -46,7 +46,9 @@ define([
|
|||
Backup,
|
||||
Messages)
|
||||
{
|
||||
var APP = {};
|
||||
var APP = {
|
||||
teams: {}
|
||||
};
|
||||
var driveAPP = {};
|
||||
var saveAs = window.saveAs;
|
||||
//var SHARED_FOLDER_NAME = Messages.fm_sharedFolderName;
|
||||
|
@ -211,6 +213,11 @@ define([
|
|||
if (obj && obj.error) {
|
||||
return void UI.warn(Messages.error);
|
||||
}
|
||||
|
||||
// Refresh offline state
|
||||
APP.teams[APP.team] = APP.teams[APP.team] || {};
|
||||
APP.teams[APP.team].offline = obj.offline;
|
||||
|
||||
common.displayAvatar($avatar, obj.avatar, obj.name);
|
||||
$category.append($avatar);
|
||||
$avatar.append(h('span.cp-sidebarlayout-category-name', obj.name));
|
||||
|
@ -333,6 +340,11 @@ define([
|
|||
});
|
||||
APP.drive = drive;
|
||||
driveAPP.refresh = drive.refresh;
|
||||
|
||||
if (APP.teams[id] && APP.teams[id].offline) {
|
||||
setEditable(false);
|
||||
drive.refresh();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -406,7 +418,18 @@ define([
|
|||
|
||||
content.push(h('h3', Messages.team_listTitle + ' ' + slots));
|
||||
|
||||
var metadataMgr = common.getMetadataMgr();
|
||||
var privateData = metadataMgr.getPrivateData();
|
||||
var teams = privateData.teams || {};
|
||||
APP.teams = {};
|
||||
|
||||
keys.forEach(function (id) {
|
||||
if (!obj[id].empty) {
|
||||
APP.teams[id] = {
|
||||
offline: obj[id] && obj[id].offline
|
||||
};
|
||||
}
|
||||
|
||||
var team = obj[id];
|
||||
if (team.empty) {
|
||||
list.push(h('div.cp-team-list-team.empty', [
|
||||
|
@ -1433,27 +1456,37 @@ define([
|
|||
}
|
||||
});
|
||||
|
||||
var onDisconnect = function (noAlert) {
|
||||
var teams = privateData.teams || {};
|
||||
|
||||
var onDisconnect = function (teamId) {
|
||||
if (APP.team && teamId && APP.team !== teamId) { return; }
|
||||
setEditable(false);
|
||||
if (APP.team && driveAPP.refresh) { driveAPP.refresh(); }
|
||||
toolbar.failed();
|
||||
if (!noAlert) { UIElements.disconnectAlert(); }
|
||||
UIElements.disconnectAlert();
|
||||
};
|
||||
var onReconnect = function () {
|
||||
var onReconnect = function (teamId) {
|
||||
if (APP.team && teamId && APP.team !== teamId) { return; }
|
||||
setEditable(true);
|
||||
if (APP.team && driveAPP.refresh) { driveAPP.refresh(); }
|
||||
toolbar.reconnecting();
|
||||
UIElements.reconnectAlert();
|
||||
};
|
||||
|
||||
sframeChan.on('EV_DRIVE_LOG', function (msg) {
|
||||
UI.log(msg);
|
||||
sframeChan.on('EV_DRIVE_LOG', function (data) {
|
||||
UI.log(data.msg);
|
||||
});
|
||||
sframeChan.on('EV_NETWORK_DISCONNECT', function () {
|
||||
onDisconnect();
|
||||
sframeChan.on('EV_NETWORK_DISCONNECT', function (teamId) {
|
||||
onDisconnect(teamId);
|
||||
if (teamId && APP.teams[teamId]) {
|
||||
APP.teams[teamId].offline = true;
|
||||
}
|
||||
});
|
||||
sframeChan.on('EV_NETWORK_RECONNECT', function () {
|
||||
onReconnect();
|
||||
sframeChan.on('EV_NETWORK_RECONNECT', function (teamId) {
|
||||
onReconnect(teamId);
|
||||
if (teamId && APP.teams[teamId]) {
|
||||
APP.teams[teamId].offline = false;
|
||||
}
|
||||
});
|
||||
common.onLogout(function () { setEditable(false); });
|
||||
});
|
||||
|
|
|
@ -85,10 +85,10 @@ define([
|
|||
sframeChan.event('EV_'+obj.data.ev, obj.data.data);
|
||||
}
|
||||
if (obj.data.ev === 'NETWORK_RECONNECT') {
|
||||
sframeChan.event('EV_NETWORK_RECONNECT');
|
||||
sframeChan.event('EV_NETWORK_RECONNECT', obj.data.data);
|
||||
}
|
||||
if (obj.data.ev === 'NETWORK_DISCONNECT') {
|
||||
sframeChan.event('EV_NETWORK_DISCONNECT');
|
||||
sframeChan.event('EV_NETWORK_DISCONNECT', obj.data.data);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue