diff --git a/www/common/notifications.js b/www/common/notifications.js index d1fbbaff9..44125ed71 100644 --- a/www/common/notifications.js +++ b/www/common/notifications.js @@ -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 msg = content.msg; diff --git a/www/common/outer/mailbox-handlers.js b/www/common/outer/mailbox-handlers.js index 4f0543885..31479e1e4 100644 --- a/www/common/outer/mailbox-handlers.js +++ b/www/common/outer/mailbox-handlers.js @@ -444,11 +444,20 @@ define([ // If they declined the invitation, remove them from the roster (as a pending member) try { var module = ctx.store.modules['team']; - module.removeFromTeam(teamId, msg.author); + module.removeFromTeam(teamId, msg.author, true); } 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) { diff --git a/www/common/outer/team.js b/www/common/outer/team.js index 7c3398189..fd2661dc0 100644 --- a/www/common/outer/team.js +++ b/www/common/outer/team.js @@ -1698,8 +1698,22 @@ define([ team.getTeams = function () { 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; } + + // 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]) { ctx.onReadyHandlers[teamId].push({cb : function () { ctx.teams[teamId].roster.remove([curve], function (err) {