From 9d0f33bad15084137d5ad8a7df1f8ba622cb05eb Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 31 Aug 2020 10:48:15 +0200 Subject: [PATCH] Fix team invitation issues --- www/common/notifications.js | 2 +- www/common/outer/mailbox-handlers.js | 13 +++++++++++-- www/common/outer/team.js | 16 +++++++++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) 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) {