Notify the other user when we kick them from a team

pull/1/head
yflory 5 years ago
parent 977198122f
commit 1a9229e0ec

@ -271,6 +271,22 @@ define([
} }
}; };
handlers['KICKED_FROM_TEAM'] = function (common, data) {
var content = data.content;
var msg = content.msg;
// Display the notification
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
var teamName = Util.fixHTML(Util.find(msg, ['content', 'teamName']) || '');
content.getFormatText = function () {
var text = name + " has kicked you from join the team <b>" + teamName +"</b>";
return text;
};
if (!content.archived) {
content.dismissHandler = defaultDismiss(common, data);
}
};
handlers['INVITE_TO_TEAM_ANSWER'] = function (common, data) { handlers['INVITE_TO_TEAM_ANSWER'] = function (common, data) {
var content = data.content; var content = data.content;
var msg = content.msg; var msg = content.msg;

@ -323,7 +323,7 @@ define([
if (invitedTo[content.team.channel]) { return void cb(true); } if (invitedTo[content.team.channel]) { return void cb(true); }
var myTeams = Util.find(ctx, ['store', 'proxy', 'teams']); var myTeams = Util.find(ctx, ['store', 'proxy', 'teams']) || {};
var alreadyMember = Object.keys(myTeams).some(function (k) { var alreadyMember = Object.keys(myTeams).some(function (k) {
var team = myTeams[k]; var team = myTeams[k];
return team.channel === content.team.channel; return team.channel === content.team.channel;
@ -339,6 +339,19 @@ define([
delete invitedTo[channel]; delete invitedTo[channel];
}; };
handlers['KICKED_FROM_TEAM'] = function (ctx, box, data, cb) {
var msg = data.msg;
var content = msg.content;
if (msg.author !== content.user.curvePublic) { return void cb(true); }
if (!content.teamChannel) {
console.log('Remove invalid notification');
return void cb(true);
}
cb(false);
};
handlers['INVITE_TO_TEAM_ANSWER'] = function (ctx, box, data, cb) { handlers['INVITE_TO_TEAM_ANSWER'] = function (ctx, box, data, cb) {
var msg = data.msg; var msg = data.msg;
var content = msg.content; var content = msg.content;
@ -349,7 +362,7 @@ define([
return void cb(true); return void cb(true);
} }
var myTeams = Util.find(ctx, ['store', 'proxy', 'teams']); var myTeams = Util.find(ctx, ['store', 'proxy', 'teams']) || {};
var teamId; var teamId;
var team; var team;
Object.keys(myTeams).some(function (k) { Object.keys(myTeams).some(function (k) {

@ -150,6 +150,9 @@ define([
ctx.updateMetadata(); ctx.updateMetadata();
return; return;
} }
var teamData = Util.find(ctx, ['store', 'proxy', 'teams', id]);
if (teamData) { teamData.metadata = state.metadata; }
ctx.updateMetadata();
ctx.emit('ROSTER_CHANGE', id, team.clients); ctx.emit('ROSTER_CHANGE', id, team.clients);
}); });
@ -552,7 +555,7 @@ define([
// TODO send guest keys only in the future // TODO send guest keys only in the future
var getInviteData = function (ctx, teamId) { var getInviteData = function (ctx, teamId) {
var teamData = Util.find(ctx, ['store', 'proxy', 'teams', teamId]); var teamData = Util.find(ctx, ['store', 'proxy', 'teams', teamId]);
if (!teamData) { return; } if (!teamData) { return {}; }
var data = Util.clone(teamData); var data = Util.clone(teamData);
delete data.owner; delete data.owner;
return data; return data;
@ -593,9 +596,25 @@ define([
if (!team) { return void cb ({error: 'ENOENT'}); } if (!team) { return void cb ({error: 'ENOENT'}); }
if (!team.roster) { return void cb({error: 'NO_ROSTER'}); } if (!team.roster) { return void cb({error: 'NO_ROSTER'}); }
if (!data.curvePublic) { return void cb({error: 'MISSING_DATA'}); } if (!data.curvePublic) { return void cb({error: 'MISSING_DATA'}); }
var state = team.roster.getState();
var userData = state.members[data.curvePublic];
console.error(userData);
team.roster.remove([data.curvePublic], function (err) { team.roster.remove([data.curvePublic], function (err) {
if (err) { return void cb({error: err}); } if (err) { return void cb({error: err}); }
cb(); // The user has been removed, send them a notification
if (!userData || !userData.notifications) { return cb(); }
console.log('send notif');
ctx.store.mailbox.sendTo('KICKED_FROM_TEAM', {
user: Messaging.createData(ctx.store.proxy, false),
teamChannel: getInviteData(ctx, teamId).channel,
teamName: getInviteData(ctx, teamId).metadata.name
}, {
channel: userData.notifications,
curvePublic: userData.curvePublic
}, function (obj) {
cb(obj);
});
}); });
}; };
@ -713,8 +732,9 @@ define([
}}); }});
return; return;
} }
if (!ctx.teams[teamId]) { return void console.error("TEAM MODULE ERROR"); } var team = ctx.teams[teamId];
ctx.teams[teamId].roster.remove([curve], function (err) { if (!team) { return void console.error("TEAM MODULE ERROR"); }
team.roster.remove([curve], function (err) {
if (err && err !== 'NO_CHANGE') { console.error(err); } if (err && err !== 'NO_CHANGE') { console.error(err); }
}); });

Loading…
Cancel
Save