Fix joining your own team

pull/1/head
yflory 5 years ago
parent 361292ff01
commit 826a86c7d6

@ -1489,6 +1489,17 @@ define([
inviteContent = obj; inviteContent = obj;
})); }));
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
// Check if you're already a member of this team
var chan = Util.find(inviteContent, ['teamData', 'channel']);
var myTeams = ctx.store.proxy.teams || {};
var isMember = Object.keys(myTeams).some(function (k) {
var t = myTeams[k];
return t.channel === chan;
});
if (isMember) {
waitFor.abort();
return void cb({error: 'ALREADY_MEMBER'});
}
// Accept the roster invitation: relplace our ephemeral keys with our user keys // Accept the roster invitation: relplace our ephemeral keys with our user keys
var rosterData = Util.find(inviteContent, ['teamData', 'keys', 'roster']); var rosterData = Util.find(inviteContent, ['teamData', 'keys', 'roster']);
var myKeys = inviteContent.ephemeral; var myKeys = inviteContent.ephemeral;
@ -1512,12 +1523,12 @@ define([
var state = roster.getState(); var state = roster.getState();
rosterState = state.members[myKeys.curvePublic]; rosterState = state.members[myKeys.curvePublic];
roster.accept(myData.curvePublic, waitFor(function (err) { roster.accept(myData.curvePublic, waitFor(function (err) {
roster.stop();
if (err) { if (err) {
waitFor.abort(); waitFor.abort();
console.error(err); console.error(err);
return void cb({error: 'ACCEPT_ERROR'}); return void cb({error: 'ACCEPT_ERROR'});
} }
roster.stop();
})); }));
})); }));
}).nThen(function () { }).nThen(function () {

@ -1127,6 +1127,7 @@ define([
password: pw, password: pw,
}, waitFor(function (obj) { }, waitFor(function (obj) {
if (obj && obj.error) { if (obj && obj.error) {
console.error(obj.error);
// Wrong password or other error... // Wrong password or other error...
waitFor.abort(); waitFor.abort();
if (obj.error === 'INVALID_INVITE_CONTENT') { if (obj.error === 'INVALID_INVITE_CONTENT') {

Loading…
Cancel
Save