mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-14 11:05:41 +05:00
Fix team invitation issues
This commit is contained in:
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 msg = content.msg;
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user