mirror of https://github.com/xwiki-labs/cryptpad
Join a team from a link
This commit is contained in:
parent
3d1b3b5d18
commit
400b39d46a
|
@ -112,7 +112,7 @@ define([
|
|||
|
||||
var to = setTimeout(function () {
|
||||
cb(new Error("Timeout"));
|
||||
}, 5000);
|
||||
}, 15000);
|
||||
|
||||
Realtime.whenRealtimeSyncs(realtime, function () {
|
||||
clearTimeout(to);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue