mirror of https://github.com/xwiki-labs/cryptpad
On-demand anon creation drive
This commit is contained in:
parent
d81e1f3ecd
commit
508201ab28
|
@ -499,7 +499,6 @@ define([
|
|||
var isNew = function () {
|
||||
error = undefined;
|
||||
postMessage('IS_NEW_CHANNEL', {channel: channel}, function (obj) {
|
||||
console.error(obj);
|
||||
if (obj && obj.error) { error = obj.error; }
|
||||
if (!obj) { error = "INVALID_RESPONSE"; }
|
||||
|
||||
|
|
|
@ -26,13 +26,14 @@ define([
|
|||
'/bower_components/chainpad/chainpad.dist.js',
|
||||
'/bower_components/chainpad-netflux/chainpad-netflux.js',
|
||||
'/bower_components/chainpad-listmap/chainpad-listmap.js',
|
||||
'/bower_components/netflux-websocket/netflux-client.js',
|
||||
'/bower_components/nthen/index.js',
|
||||
'/bower_components/saferphore/index.js',
|
||||
], function (Sortify, UserObject, ProxyManager, Migrate, Hash, Util, Constants, Feedback,
|
||||
Realtime, Messaging, Pinpad, Cache,
|
||||
SF, Cursor, OnlyOffice, Mailbox, Profile, Team, Messenger, History,
|
||||
NetConfig, AppConfig,
|
||||
Crypto, ChainPad, CpNetflux, Listmap, nThen, Saferphore) {
|
||||
Crypto, ChainPad, CpNetflux, Listmap, Netflux, nThen, Saferphore) {
|
||||
|
||||
var onReadyEvt = Util.mkEvent(true);
|
||||
var onCacheReadyEvt = Util.mkEvent(true);
|
||||
|
@ -588,8 +589,8 @@ define([
|
|||
var metadata = {
|
||||
// "user" is shared with everybody via the userlist
|
||||
user: {
|
||||
name: proxy[Constants.displayNameKey] || "",
|
||||
uid: proxy.uid,
|
||||
name: proxy[Constants.displayNameKey] || store.noDriveName || "",
|
||||
uid: proxy.uid || Hash.createChannelId(), // Random uid in nodrive mode
|
||||
avatar: Util.find(proxy, ['profile', 'avatar']),
|
||||
profile: Util.find(proxy, ['profile', 'view']),
|
||||
color: getUserColor(),
|
||||
|
@ -855,6 +856,10 @@ define([
|
|||
|
||||
// Set the display name (username) in the proxy
|
||||
Store.setDisplayName = function (clientId, value, cb) {
|
||||
if (!store.proxy) {
|
||||
store.noDriveName = value;
|
||||
return void cb();
|
||||
}
|
||||
if (store.modules['profile']) {
|
||||
store.modules['profile'].setName(value);
|
||||
}
|
||||
|
@ -1446,6 +1451,8 @@ define([
|
|||
};
|
||||
// Teams support offline/cache mode
|
||||
if (obj.type === "team") { return void todo(); }
|
||||
// If we're in "noDrive" mode
|
||||
if (!store.proxy) { return void todo(); }
|
||||
// Other modules should wait for the ready event
|
||||
onReadyEvt.reg(todo);
|
||||
}
|
||||
|
@ -1634,7 +1641,6 @@ define([
|
|||
};
|
||||
|
||||
Store.joinPad = function (clientId, data) {
|
||||
console.error('JOINPAD');
|
||||
if (data.versionHash) {
|
||||
return void getVersionHash(clientId, data);
|
||||
}
|
||||
|
@ -1711,12 +1717,15 @@ define([
|
|||
postMessage(clientId, "PAD_CACHE_READY");
|
||||
},
|
||||
onReady: function (pad) {
|
||||
console.warn(pad);
|
||||
var padData = pad.metadata || {};
|
||||
channel.data = padData;
|
||||
if (padData && padData.validateKey && store.messenger) {
|
||||
store.messenger.storeValidateKey(data.channel, padData.validateKey);
|
||||
}
|
||||
if (!store.proxy) {
|
||||
postMessage(clientId, "PAD_READY", pad.noCache);
|
||||
return;
|
||||
}
|
||||
onReadyEvt.reg(function () {
|
||||
postMessage(clientId, "PAD_READY", pad.noCache);
|
||||
});
|
||||
|
@ -1775,7 +1784,6 @@ console.warn(pad);
|
|||
websocketURL: NetConfig.getWebsocketURL(),
|
||||
//readOnly: data.readOnly,
|
||||
onConnect: function (wc, sendMessage) {
|
||||
console.warn('CONNECT');
|
||||
channel.sendMessage = function (msg, cId, cb) {
|
||||
// Send to server
|
||||
sendMessage(msg, function (err) {
|
||||
|
@ -2754,11 +2762,6 @@ console.warn('CONNECT');
|
|||
return void cb({error: '[Store.init] Unable to find or create a drive hash. Aborting...'});
|
||||
}
|
||||
|
||||
var lock = false;
|
||||
if (!data.userHash && !data.anonHash) {
|
||||
lock = true;
|
||||
}
|
||||
|
||||
var updateProgress = function (data) {
|
||||
data.type = 'drive';
|
||||
postMessage(clientId, 'LOADING_DRIVE', data);
|
||||
|
@ -2770,6 +2773,7 @@ console.warn('CONNECT');
|
|||
var listmapConfig = {
|
||||
data: {},
|
||||
websocketURL: NetConfig.getWebsocketURL(),
|
||||
network: store.network,
|
||||
channel: secret.channel,
|
||||
readOnly: false,
|
||||
validateKey: secret.keys.validateKey || undefined,
|
||||
|
@ -2778,7 +2782,6 @@ console.warn('CONNECT');
|
|||
userName: 'fs',
|
||||
logLevel: 1,
|
||||
ChainPad: ChainPad,
|
||||
lock: lock,
|
||||
updateProgress: updateProgress,
|
||||
classic: true,
|
||||
};
|
||||
|
@ -2926,7 +2929,50 @@ console.warn('CONNECT');
|
|||
*/
|
||||
var initialized = false;
|
||||
|
||||
var noDrive = [];
|
||||
// If we load CryptPad for the first time from an existing pad, don't create a
|
||||
// drive automatically.
|
||||
var onNoDrive = function (clientId, cb) {
|
||||
var andThen = function () {
|
||||
// To be able to use all the features inside the pad, we need to
|
||||
// initialize the chat (messenger) and the cursor modules.
|
||||
loadUniversal(Cursor, 'cursor', function () {});
|
||||
loadUniversal(Messenger, 'messenger', function () {});
|
||||
store.messenger = store.modules['messenger'];
|
||||
|
||||
// And now we're ready
|
||||
initAnonRpc(null, null, function () {
|
||||
cb({});
|
||||
});
|
||||
};
|
||||
|
||||
// We need an anonymous RPC to be able to check if the pad exists and to get
|
||||
// its metadata, so we have to create a network first.
|
||||
if (!store.network) {
|
||||
var wsUrl = NetConfig.getWebsocketURL();
|
||||
return void Netflux.connect(wsUrl).then(function (network) {
|
||||
store.network = network;
|
||||
// We need to know the HistoryKeeper ID to initialize the anon RPC
|
||||
// Join a basic ephemeral channel, get the ID and leave it instantly
|
||||
network.join('0000000000000000000000000000000000').then(function (wc) {
|
||||
var hk;
|
||||
wc.members.forEach(function (p) { if (p.length === 16) { hk = p; } });
|
||||
network.historyKeeper = hk;
|
||||
wc.leave();
|
||||
|
||||
andThen();
|
||||
}, function (err) {
|
||||
console.error(err);
|
||||
cb({error: 'GET_HK'});
|
||||
});
|
||||
}, function (err) {
|
||||
console.error(err);
|
||||
cb({error: 'OFFLINE'});
|
||||
});
|
||||
}
|
||||
andThen();
|
||||
};
|
||||
|
||||
|
||||
Store.init = function (clientId, data, _callback) {
|
||||
var callback = Util.once(_callback);
|
||||
|
||||
|
@ -2961,20 +3007,28 @@ console.warn('CONNECT');
|
|||
Cache.disable();
|
||||
}
|
||||
|
||||
postMessage = function (clientId, cmd, d, cb) {
|
||||
data.query(clientId, cmd, d, cb);
|
||||
};
|
||||
broadcast = function (excludes, cmd, d, cb) {
|
||||
data.broadcast(excludes, cmd, d, cb);
|
||||
};
|
||||
if (data.query && data.broadcast) {
|
||||
postMessage = function (clientId, cmd, d, cb) {
|
||||
data.query(clientId, cmd, d, cb);
|
||||
};
|
||||
broadcast = function (excludes, cmd, d, cb) {
|
||||
data.broadcast(excludes, cmd, d, cb);
|
||||
};
|
||||
}
|
||||
|
||||
// First tab, no user hash, no anon hash and this app doesn't need a drive
|
||||
// ==> don't create a drive
|
||||
if (data.noDrive && !data.userHash && !data.anonHash) {
|
||||
noDrive.push(clientId);
|
||||
// XXX We need a network before initAnonRpc...
|
||||
return void initAnonRpc(null, null, function () {
|
||||
callback({});
|
||||
return void onNoDrive(clientId, function (obj) {
|
||||
if (obj && obj.error) {
|
||||
// if we can't properly initialize the noDrive mode, use normal mode
|
||||
if (obj.error === 'GET_HK') {
|
||||
data.noDrive = false;
|
||||
Store.init(clientId, data, _callback);
|
||||
return;
|
||||
}
|
||||
}
|
||||
callback(obj);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -180,9 +180,10 @@ define([
|
|||
var updateCursor = function (ctx, data, client, cb) {
|
||||
var c = ctx.clients[client];
|
||||
if (!c) { return void cb({error: 'NO_CLIENT'}); }
|
||||
data.color = Util.find(ctx.store.proxy, ['settings', 'general', 'cursor', 'color']);
|
||||
data.name = ctx.store.proxy[Constants.displayNameKey] || Messages.anonymous;
|
||||
data.avatar = Util.find(ctx.store.proxy, ['profile', 'avatar']);
|
||||
var proxy = ctx.store.proxy || {};
|
||||
data.color = Util.find(proxy, ['settings', 'general', 'cursor', 'color']);
|
||||
data.name = proxy[Constants.displayNameKey] || ctx.store.noDriveName || Messages.anonymous;
|
||||
data.avatar = Util.find(proxy, ['profile', 'avatar']);
|
||||
c.cursor = data;
|
||||
sendMyCursor(ctx, client);
|
||||
cb();
|
||||
|
@ -241,6 +242,12 @@ define([
|
|||
|
||||
Cursor.init = function (cfg, waitFor, emit) {
|
||||
var cursor = {};
|
||||
|
||||
// Already initialized by a "noDrive" tab?
|
||||
if (cfg.store && cfg.store.modules && cfg.store.modules['cursor']) {
|
||||
return cfg.store.modules['cursor'];
|
||||
}
|
||||
|
||||
var ctx = {
|
||||
store: cfg.store,
|
||||
emit: emit,
|
||||
|
|
|
@ -213,7 +213,7 @@ define([
|
|||
if (parsed[0] !== Types.mapId) { return; } // Don't send your key if it's already an ACK
|
||||
|
||||
// Answer with your own key
|
||||
var proxy = ctx.store.proxy;
|
||||
var proxy = ctx.store.proxy || {};
|
||||
var myData = createData(proxy);
|
||||
delete myData.channel;
|
||||
var rMsg = [Types.mapIdAck, myData, channel.wc.myID];
|
||||
|
@ -537,6 +537,8 @@ define([
|
|||
if (peer === hk) { return; }
|
||||
if (channel.readOnly) { return; }
|
||||
|
||||
if (channel.isPadChat) { return; }
|
||||
|
||||
// Join event will be sent once we are able to ID this peer
|
||||
var myData = createData(proxy);
|
||||
delete myData.channel;
|
||||
|
@ -653,7 +655,7 @@ define([
|
|||
if (channel.onUserlistUpdate) {
|
||||
channel.onUserlistUpdate();
|
||||
}
|
||||
var proxy = ctx.store.proxy;
|
||||
var proxy = ctx.store.proxy || {};
|
||||
var online = channel.wc.members.some(function (nId) {
|
||||
if (nId === ctx.store.network.historyKeeper) { return; }
|
||||
var data = channel.mapId[nId] || undefined;
|
||||
|
@ -664,7 +666,7 @@ define([
|
|||
};
|
||||
|
||||
var getMyInfo = function (ctx, cb) {
|
||||
var proxy = ctx.store.proxy;
|
||||
var proxy = ctx.store.proxy || {};
|
||||
cb({
|
||||
curvePublic: proxy.curvePublic,
|
||||
displayName: proxy[Constants.displayNameKey]
|
||||
|
@ -939,6 +941,14 @@ define([
|
|||
Msg.init = function (cfg, waitFor, emit) {
|
||||
var messenger = {};
|
||||
var store = cfg.store;
|
||||
|
||||
// Already initialized by a "noDrive" tab
|
||||
// If this one is a normal tab, add the missing listener if we can
|
||||
if (store.messenger) {
|
||||
store.messenger.addListener();
|
||||
return store.messenger;
|
||||
}
|
||||
|
||||
if (AppConfig.availablePadTypes.indexOf('contacts') === -1) { return; }
|
||||
var ctx = {
|
||||
store: store,
|
||||
|
@ -952,9 +962,14 @@ define([
|
|||
range_requests: {}
|
||||
};
|
||||
|
||||
store.proxy.on('change', ['mutedUsers'], function () {
|
||||
ctx.emit('UPDATE_MUTED', null, getAllClients(ctx));
|
||||
});
|
||||
messenger.addListener = function () {
|
||||
if (store.proxy) {
|
||||
store.proxy.on('change', ['mutedUsers'], function () {
|
||||
ctx.emit('UPDATE_MUTED', null, getAllClients(ctx));
|
||||
});
|
||||
}
|
||||
};
|
||||
messenger.addListener();
|
||||
|
||||
ctx.store.network.on('message', function(msg, sender) {
|
||||
onDirectMessage(ctx, msg, sender);
|
||||
|
|
|
@ -152,7 +152,6 @@ define([
|
|||
cb('OK');
|
||||
});
|
||||
sframeChan.on('EV_RT_READY', function () {
|
||||
console.error('INNER READY');
|
||||
if (isReady) { return; }
|
||||
if (updateLoadingProgress) {
|
||||
updateLoadingProgress({
|
||||
|
|
|
@ -487,7 +487,6 @@ define([
|
|||
}
|
||||
// Not a file, so we can use `isNewChannel`
|
||||
Cryptpad.isNewChannel(currentPad.href, password, w(function(e, isNew) {
|
||||
alert('ko');
|
||||
if (isNew && expire && expire < (+new Date())) {
|
||||
sframeChan.event("EV_EXPIRED_ERROR");
|
||||
waitFor.abort();
|
||||
|
|
Loading…
Reference in New Issue