diff --git a/www/common/notifications.js b/www/common/notifications.js index f152e741a..5c8db3806 100644 --- a/www/common/notifications.js +++ b/www/common/notifications.js @@ -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 " + teamName +""; + return text; + }; + if (!content.archived) { + content.dismissHandler = defaultDismiss(common, data); + } + }; + handlers['INVITE_TO_TEAM_ANSWER'] = 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 686f474ed..e3b3639a3 100644 --- a/www/common/outer/mailbox-handlers.js +++ b/www/common/outer/mailbox-handlers.js @@ -323,7 +323,7 @@ define([ 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 team = myTeams[k]; return team.channel === content.team.channel; @@ -339,6 +339,19 @@ define([ 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) { var msg = data.msg; var content = msg.content; @@ -349,7 +362,7 @@ define([ return void cb(true); } - var myTeams = Util.find(ctx, ['store', 'proxy', 'teams']); + var myTeams = Util.find(ctx, ['store', 'proxy', 'teams']) || {}; var teamId; var team; Object.keys(myTeams).some(function (k) { diff --git a/www/common/outer/team.js b/www/common/outer/team.js index bddd77e52..9d169152a 100644 --- a/www/common/outer/team.js +++ b/www/common/outer/team.js @@ -150,6 +150,9 @@ define([ ctx.updateMetadata(); 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); }); @@ -552,7 +555,7 @@ define([ // TODO send guest keys only in the future var getInviteData = function (ctx, teamId) { var teamData = Util.find(ctx, ['store', 'proxy', 'teams', teamId]); - if (!teamData) { return; } + if (!teamData) { return {}; } var data = Util.clone(teamData); delete data.owner; return data; @@ -593,9 +596,25 @@ define([ if (!team) { return void cb ({error: 'ENOENT'}); } if (!team.roster) { return void cb({error: 'NO_ROSTER'}); } 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) { 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; } - if (!ctx.teams[teamId]) { return void console.error("TEAM MODULE ERROR"); } - ctx.teams[teamId].roster.remove([curve], function (err) { + var team = ctx.teams[teamId]; + if (!team) { return void console.error("TEAM MODULE ERROR"); } + team.roster.remove([curve], function (err) { if (err && err !== 'NO_CHANGE') { console.error(err); } });