Fix team invitation issues

pull/1/head
yflory 4 years ago
parent 6566d38c70
commit 9d0f33bad1

@ -312,7 +312,7 @@ define([
} }
}; };
handlers['INVITE_TO_TEAM_ANSWER'] = function(common, data) { handlers['INVITE_TO_TEAM_ANSWERED'] = function(common, data) {
var content = data.content; var content = data.content;
var msg = content.msg; var msg = content.msg;

@ -444,11 +444,20 @@ define([
// If they declined the invitation, remove them from the roster (as a pending member) // If they declined the invitation, remove them from the roster (as a pending member)
try { try {
var module = ctx.store.modules['team']; var module = ctx.store.modules['team'];
module.removeFromTeam(teamId, msg.author); module.removeFromTeam(teamId, msg.author, true);
} catch (e) { console.error(e); } } catch (e) { console.error(e); }
} }
cb(false); box.sendMessage({
type: 'INVITE_TO_TEAM_ANSWERED',
content: {
user: userData,
team: team,
answer: content.answer
}
}, function () {});
cb(true);
}; };
handlers['TEAM_EDIT_RIGHTS'] = function (ctx, box, data, cb) { handlers['TEAM_EDIT_RIGHTS'] = function (ctx, box, data, cb) {

@ -1698,8 +1698,22 @@ define([
team.getTeams = function () { team.getTeams = function () {
return Object.keys(ctx.teams); return Object.keys(ctx.teams);
}; };
team.removeFromTeam = function (teamId, curve) {
var isPending = function (teamId, curve) {
var team = ctx.teams[teamId];
if (!team) { return; }
var state = team.roster && team.roster.getState();
if (!state.members) { return; }
var m = state.members[curve] || {};
return m.pending;
};
team.removeFromTeam = function (teamId, curve, pendingOnly) {
if (!teams[teamId]) { return; } if (!teams[teamId]) { return; }
// When receiving a negative answer to a team invitation, remove
// the pending user from the roster.
if (pendingOnly && !isPending(teamId, curve) { return; }
if (ctx.onReadyHandlers[teamId]) { if (ctx.onReadyHandlers[teamId]) {
ctx.onReadyHandlers[teamId].push({cb : function () { ctx.onReadyHandlers[teamId].push({cb : function () {
ctx.teams[teamId].roster.remove([curve], function (err) { ctx.teams[teamId].roster.remove([curve], function (err) {

Loading…
Cancel
Save