From 400b39d46ab24810a2cf163ca9444cf97bc7109c Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 18 Dec 2019 11:35:39 +0100 Subject: [PATCH] Join a team from a link --- www/common/cryptget.js | 2 +- www/common/outer/roster.js | 1 + www/common/outer/team.js | 49 ++++++++++++++++++++++++++++++++++---- www/teams/inner.js | 16 +++++++++---- 4 files changed, 58 insertions(+), 10 deletions(-) diff --git a/www/common/cryptget.js b/www/common/cryptget.js index 8a1684dba..37fc069a5 100644 --- a/www/common/cryptget.js +++ b/www/common/cryptget.js @@ -112,7 +112,7 @@ define([ var to = setTimeout(function () { cb(new Error("Timeout")); - }, 5000); + }, 15000); Realtime.whenRealtimeSyncs(realtime, function () { clearTimeout(to); diff --git a/www/common/outer/roster.js b/www/common/outer/roster.js index 6a1def6b9..8755bbd79 100644 --- a/www/common/outer/roster.js +++ b/www/common/outer/roster.js @@ -451,6 +451,7 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) { // copy the new profile from the old one members[curve] = Util.clone(members[author]); + members[curve].curvePublic = curve; // and erase the old one delete members[author]; return true; diff --git a/www/common/outer/team.js b/www/common/outer/team.js index b91e678a1..f4aee284a 100644 --- a/www/common/outer/team.js +++ b/www/common/outer/team.js @@ -446,6 +446,7 @@ define([ // If we've been kicked, don't try to update our data, we'll close everything // in the next nThen part var state = roster.getState(); + console.error(state); var me = Util.find(ctx, ['store', 'proxy', 'curvePublic']); if (!state.members[me]) { return; } @@ -1364,7 +1365,7 @@ define([ }; var cryptput_config = { - channel: previewKeys.channel, + channel: inviteKeys.channel, type: 'pad', version: 2, 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) { var team = {}; @@ -1627,12 +1668,12 @@ define([ if (cmd === 'CREATE_INVITE_LINK') { return void createInviteLink(ctx, data, clientId, cb); } - if (cmd === 'GET_INVITE_CONTENT') { - return void getInviteContent(ctx, data, clientId, cb); - } if (cmd === 'GET_PREVIEW_CONTENT') { return void getPreviewContent(ctx, data, clientId, cb); } + if (cmd === 'ACCEPT_LINK_INVITATION') { + return void acceptLinkInvitation(ctx, data, clientId, cb); + } }; return team; diff --git a/www/teams/inner.js b/www/teams/inner.js index 902fa403b..9e35b1416 100644 --- a/www/teams/inner.js +++ b/www/teams/inner.js @@ -1096,7 +1096,7 @@ define([ })); }).nThen(function (waitFor) { $spinner.text('get team data'); // XXX - APP.module.execCommand('GET_INVITE_CONTENT', { + APP.module.execCommand('ACCEPT_LINK_INVITATION', { bytes64: bytes64, hash: hash, password: pw, @@ -1108,19 +1108,25 @@ define([ waitFor.abort(); return; } - inviteContent = obj; - // TODO - // Accept/decline/decide later UI + // No error: join successful! + var $div = $('div.cp-team-list').empty(); + refreshList(common, function (content) { + $div.append(content); + $('div.cp-team-cat-list').click(); + // XXX REMOVE INVITATION TAB + }); + })); }).nThen(function (waitFor) { }); }; nThen(function (waitFor) { + // XXX XXX Check number of teams first! APP.module.execCommand("GET_PREVIEW_CONTENT", { seeds: seeds, }, 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? // err === DELETED: different message? $(errorBlock).text('ERROR'+json.error).show(); // XXX