diff --git a/www/common/outer/team.js b/www/common/outer/team.js index 9ffcae1fa..604e5277c 100644 --- a/www/common/outer/team.js +++ b/www/common/outer/team.js @@ -507,6 +507,26 @@ define([ }); }; + var leaveTeam = function (ctx, data, cId, cb) { + var teamId = data.teamId; + if (!teamId) { return void cb({error: 'EINVAL'}); } + var team = ctx.teams[teamId]; + if (!team) { return void cb ({error: 'ENOENT'}); } + if (!team.roster) { return void cb({error: 'NO_ROSTER'}); } + var curvePublic = ctx.store.proxy.curvePublic; + team.roster.remove([curvePublic], function (err) { + if (err) { return void cb({error: err}); } + team.lm.stop(); + team.roster.stop(); + team.proxy = {}; + delete ctx.teams[teamId]; + delete ctx.store.proxy.teams[teamId]; + ctx.emit('LEAVE_TEAM', teamId, team.clients); + ctx.updateMetadata(); + cb(); + }); + }; + var getTeamRoster = function (ctx, data, cId, cb) { var teamId = data.teamId; if (!teamId) { return void cb({error: 'EINVAL'}); } @@ -649,7 +669,7 @@ define([ 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 + // And leave the chat channel try { ctx.store.messenger.removeClient(cId); } catch (e) {} @@ -776,6 +796,9 @@ define([ if (cmd === 'INVITE_TO_TEAM') { return void inviteToTeam(ctx, data, clientId, cb); } + if (cmd === 'LEAVE_TEAM') { + return void leaveTeam(ctx, data, clientId, cb); + } if (cmd === 'JOIN_TEAM') { return void joinTeam(ctx, data, clientId, cb); } diff --git a/www/team/inner.js b/www/team/inner.js index 9c3f2bc58..1635248ce 100644 --- a/www/team/inner.js +++ b/www/team/inner.js @@ -511,6 +511,23 @@ define([ $header.append(invite); } + if (me && (me.role === 'ADMIN' || me.role === 'MEMBER')) { + var leave = h('button.btn.btn-danger', 'LEAVE THE TEAM'); + $(leave).click(function () { + UI.confirm("Your're going to leave this team and lose access to its entire drive. Are you sure?", function (yes) { + if (!yes) { return; } + APP.module.execCommand('LEAVE_TEAM', { + teamId: APP.team + }, function (obj) { + if (obj && obj.error) { + return void UI.warn(Messages.error); + } + }); + }); + }); + $header.append(leave); + } + return [ header, h('h3', 'OWNER'), // XXX