Join a team from a link

pull/1/head
yflory 5 years ago
parent 3d1b3b5d18
commit 400b39d46a

@ -112,7 +112,7 @@ define([
var to = setTimeout(function () { var to = setTimeout(function () {
cb(new Error("Timeout")); cb(new Error("Timeout"));
}, 5000); }, 15000);
Realtime.whenRealtimeSyncs(realtime, function () { Realtime.whenRealtimeSyncs(realtime, function () {
clearTimeout(to); clearTimeout(to);

@ -451,6 +451,7 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) {
// copy the new profile from the old one // copy the new profile from the old one
members[curve] = Util.clone(members[author]); members[curve] = Util.clone(members[author]);
members[curve].curvePublic = curve;
// and erase the old one // and erase the old one
delete members[author]; delete members[author];
return true; return true;

@ -446,6 +446,7 @@ define([
// If we've been kicked, don't try to update our data, we'll close everything // If we've been kicked, don't try to update our data, we'll close everything
// in the next nThen part // in the next nThen part
var state = roster.getState(); var state = roster.getState();
console.error(state);
var me = Util.find(ctx, ['store', 'proxy', 'curvePublic']); var me = Util.find(ctx, ['store', 'proxy', 'curvePublic']);
if (!state.members[me]) { return; } if (!state.members[me]) { return; }
@ -1364,7 +1365,7 @@ define([
}; };
var cryptput_config = { var cryptput_config = {
channel: previewKeys.channel, channel: inviteKeys.channel,
type: 'pad', type: 'pad',
version: 2, version: 2,
keys: { keys: {
@ -1470,6 +1471,46 @@ define([
}); });
}; };
var acceptLinkInvitation = function (ctx, data, cId, cb) {
var inviteContent;
nThen(function (waitFor) {
getInviteContent(ctx, data, cId, waitFor(function (obj) {
if (obj && obj.error) {
waitFor.abort();
return void cb(obj);
}
inviteContent = obj;
}));
}).nThen(function (waitFor) {
var rosterData = Util.find(inviteContent, ['teamData', 'keys', 'roster']);
var myKeys = inviteContent.ephemeral;
var rosterKeys = Crypto.Team.deriveMemberKeys(rosterData.edit, myKeys);
Roster.create({
network: ctx.store.network,
channel: rosterData.channel,
keys: rosterKeys,
anon_rpc: ctx.store.anon_rpc,
lastKnownHash: rosterData.lastKnownHash, // XXX Can we trust this user?
}, waitFor(function (err, roster) {
if (err) {
waitFor.abort();
console.error(err);
return void cb({error: 'ROSTER_ERROR'});
}
var myData = Messaging.createData(ctx.store.proxy, false);
roster.accept(myData.curvePublic, waitFor(function (err) {
if (err) {
waitFor.abort();
console.error(err);
return void cb({error: 'ACCEPT_ERROR'});
}
roster.stop();
}));
}));
}).nThen(function () {
joinTeam(ctx, inviteContent.teamData, cId, cb)
});
};
Team.init = function (cfg, waitFor, emit) { Team.init = function (cfg, waitFor, emit) {
var team = {}; var team = {};
@ -1627,12 +1668,12 @@ define([
if (cmd === 'CREATE_INVITE_LINK') { if (cmd === 'CREATE_INVITE_LINK') {
return void createInviteLink(ctx, data, clientId, cb); return void createInviteLink(ctx, data, clientId, cb);
} }
if (cmd === 'GET_INVITE_CONTENT') {
return void getInviteContent(ctx, data, clientId, cb);
}
if (cmd === 'GET_PREVIEW_CONTENT') { if (cmd === 'GET_PREVIEW_CONTENT') {
return void getPreviewContent(ctx, data, clientId, cb); return void getPreviewContent(ctx, data, clientId, cb);
} }
if (cmd === 'ACCEPT_LINK_INVITATION') {
return void acceptLinkInvitation(ctx, data, clientId, cb);
}
}; };
return team; return team;

@ -1096,7 +1096,7 @@ define([
})); }));
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
$spinner.text('get team data'); // XXX $spinner.text('get team data'); // XXX
APP.module.execCommand('GET_INVITE_CONTENT', { APP.module.execCommand('ACCEPT_LINK_INVITATION', {
bytes64: bytes64, bytes64: bytes64,
hash: hash, hash: hash,
password: pw, password: pw,
@ -1108,19 +1108,25 @@ define([
waitFor.abort(); waitFor.abort();
return; return;
} }
inviteContent = obj; // No error: join successful!
// TODO var $div = $('div.cp-team-list').empty();
// Accept/decline/decide later UI refreshList(common, function (content) {
$div.append(content);
$('div.cp-team-cat-list').click();
// XXX REMOVE INVITATION TAB
});
})); }));
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
}); });
}; };
nThen(function (waitFor) { nThen(function (waitFor) {
// XXX XXX Check number of teams first!
APP.module.execCommand("GET_PREVIEW_CONTENT", { APP.module.execCommand("GET_PREVIEW_CONTENT", {
seeds: seeds, seeds: seeds,
}, waitFor(function (json) { }, waitFor(function (json) {
if (json && jsoN.error) { // XXX this is failing with "team is disabled" if (json && json.error) { // XXX this is failing with "team is disabled"
// XXX APP.module is not ready yet? // XXX APP.module is not ready yet?
// err === DELETED: different message? // err === DELETED: different message?
$(errorBlock).text('ERROR'+json.error).show(); // XXX $(errorBlock).text('ERROR'+json.error).show(); // XXX

Loading…
Cancel
Save