Leave a team

pull/1/head
yflory 5 years ago
parent adac70567f
commit 4381ff8107

@ -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 getTeamRoster = function (ctx, data, cId, cb) {
var teamId = data.teamId; var teamId = data.teamId;
if (!teamId) { return void cb({error: 'EINVAL'}); } if (!teamId) { return void cb({error: 'EINVAL'}); }
@ -649,7 +669,7 @@ define([
var subscribe = function (ctx, id, cId, cb) { var subscribe = function (ctx, id, cId, cb) {
// Unsubscribe from other teams: one tab can only receive events about one team // Unsubscribe from other teams: one tab can only receive events about one team
removeClient(ctx, cId); removeClient(ctx, cId);
// And leave the channel channel // And leave the chat channel
try { try {
ctx.store.messenger.removeClient(cId); ctx.store.messenger.removeClient(cId);
} catch (e) {} } catch (e) {}
@ -776,6 +796,9 @@ define([
if (cmd === 'INVITE_TO_TEAM') { if (cmd === 'INVITE_TO_TEAM') {
return void inviteToTeam(ctx, data, clientId, cb); return void inviteToTeam(ctx, data, clientId, cb);
} }
if (cmd === 'LEAVE_TEAM') {
return void leaveTeam(ctx, data, clientId, cb);
}
if (cmd === 'JOIN_TEAM') { if (cmd === 'JOIN_TEAM') {
return void joinTeam(ctx, data, clientId, cb); return void joinTeam(ctx, data, clientId, cb);
} }

@ -511,6 +511,23 @@ define([
$header.append(invite); $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 [ return [
header, header,
h('h3', 'OWNER'), // XXX h('h3', 'OWNER'), // XXX

Loading…
Cancel
Save