|
|
@ -26,13 +26,14 @@ define([
|
|
|
|
'/bower_components/chainpad/chainpad.dist.js',
|
|
|
|
'/bower_components/chainpad/chainpad.dist.js',
|
|
|
|
'/bower_components/chainpad-netflux/chainpad-netflux.js',
|
|
|
|
'/bower_components/chainpad-netflux/chainpad-netflux.js',
|
|
|
|
'/bower_components/chainpad-listmap/chainpad-listmap.js',
|
|
|
|
'/bower_components/chainpad-listmap/chainpad-listmap.js',
|
|
|
|
|
|
|
|
'/bower_components/netflux-websocket/netflux-client.js',
|
|
|
|
'/bower_components/nthen/index.js',
|
|
|
|
'/bower_components/nthen/index.js',
|
|
|
|
'/bower_components/saferphore/index.js',
|
|
|
|
'/bower_components/saferphore/index.js',
|
|
|
|
], function (Sortify, UserObject, ProxyManager, Migrate, Hash, Util, Constants, Feedback,
|
|
|
|
], function (Sortify, UserObject, ProxyManager, Migrate, Hash, Util, Constants, Feedback,
|
|
|
|
Realtime, Messaging, Pinpad, Cache,
|
|
|
|
Realtime, Messaging, Pinpad, Cache,
|
|
|
|
SF, Cursor, OnlyOffice, Mailbox, Profile, Team, Messenger, History,
|
|
|
|
SF, Cursor, OnlyOffice, Mailbox, Profile, Team, Messenger, History,
|
|
|
|
NetConfig, AppConfig,
|
|
|
|
NetConfig, AppConfig,
|
|
|
|
Crypto, ChainPad, CpNetflux, Listmap, nThen, Saferphore) {
|
|
|
|
Crypto, ChainPad, CpNetflux, Listmap, Netflux, nThen, Saferphore) {
|
|
|
|
|
|
|
|
|
|
|
|
var onReadyEvt = Util.mkEvent(true);
|
|
|
|
var onReadyEvt = Util.mkEvent(true);
|
|
|
|
var onCacheReadyEvt = Util.mkEvent(true);
|
|
|
|
var onCacheReadyEvt = Util.mkEvent(true);
|
|
|
@ -588,8 +589,8 @@ define([
|
|
|
|
var metadata = {
|
|
|
|
var metadata = {
|
|
|
|
// "user" is shared with everybody via the userlist
|
|
|
|
// "user" is shared with everybody via the userlist
|
|
|
|
user: {
|
|
|
|
user: {
|
|
|
|
name: proxy[Constants.displayNameKey] || "",
|
|
|
|
name: proxy[Constants.displayNameKey] || store.noDriveName || "",
|
|
|
|
uid: proxy.uid,
|
|
|
|
uid: proxy.uid || Hash.createChannelId(), // Random uid in nodrive mode
|
|
|
|
avatar: Util.find(proxy, ['profile', 'avatar']),
|
|
|
|
avatar: Util.find(proxy, ['profile', 'avatar']),
|
|
|
|
profile: Util.find(proxy, ['profile', 'view']),
|
|
|
|
profile: Util.find(proxy, ['profile', 'view']),
|
|
|
|
color: getUserColor(),
|
|
|
|
color: getUserColor(),
|
|
|
@ -855,6 +856,10 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
// Set the display name (username) in the proxy
|
|
|
|
// Set the display name (username) in the proxy
|
|
|
|
Store.setDisplayName = function (clientId, value, cb) {
|
|
|
|
Store.setDisplayName = function (clientId, value, cb) {
|
|
|
|
|
|
|
|
if (!store.proxy) {
|
|
|
|
|
|
|
|
store.noDriveName = value;
|
|
|
|
|
|
|
|
return void cb();
|
|
|
|
|
|
|
|
}
|
|
|
|
if (store.modules['profile']) {
|
|
|
|
if (store.modules['profile']) {
|
|
|
|
store.modules['profile'].setName(value);
|
|
|
|
store.modules['profile'].setName(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1446,6 +1451,8 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
// Teams support offline/cache mode
|
|
|
|
// Teams support offline/cache mode
|
|
|
|
if (obj.type === "team") { return void todo(); }
|
|
|
|
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
|
|
|
|
// Other modules should wait for the ready event
|
|
|
|
onReadyEvt.reg(todo);
|
|
|
|
onReadyEvt.reg(todo);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1634,7 +1641,6 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Store.joinPad = function (clientId, data) {
|
|
|
|
Store.joinPad = function (clientId, data) {
|
|
|
|
console.error('JOINPAD');
|
|
|
|
|
|
|
|
if (data.versionHash) {
|
|
|
|
if (data.versionHash) {
|
|
|
|
return void getVersionHash(clientId, data);
|
|
|
|
return void getVersionHash(clientId, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1711,12 +1717,15 @@ define([
|
|
|
|
postMessage(clientId, "PAD_CACHE_READY");
|
|
|
|
postMessage(clientId, "PAD_CACHE_READY");
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onReady: function (pad) {
|
|
|
|
onReady: function (pad) {
|
|
|
|
console.warn(pad);
|
|
|
|
|
|
|
|
var padData = pad.metadata || {};
|
|
|
|
var padData = pad.metadata || {};
|
|
|
|
channel.data = padData;
|
|
|
|
channel.data = padData;
|
|
|
|
if (padData && padData.validateKey && store.messenger) {
|
|
|
|
if (padData && padData.validateKey && store.messenger) {
|
|
|
|
store.messenger.storeValidateKey(data.channel, padData.validateKey);
|
|
|
|
store.messenger.storeValidateKey(data.channel, padData.validateKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!store.proxy) {
|
|
|
|
|
|
|
|
postMessage(clientId, "PAD_READY", pad.noCache);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
onReadyEvt.reg(function () {
|
|
|
|
onReadyEvt.reg(function () {
|
|
|
|
postMessage(clientId, "PAD_READY", pad.noCache);
|
|
|
|
postMessage(clientId, "PAD_READY", pad.noCache);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -1775,7 +1784,6 @@ console.warn(pad);
|
|
|
|
websocketURL: NetConfig.getWebsocketURL(),
|
|
|
|
websocketURL: NetConfig.getWebsocketURL(),
|
|
|
|
//readOnly: data.readOnly,
|
|
|
|
//readOnly: data.readOnly,
|
|
|
|
onConnect: function (wc, sendMessage) {
|
|
|
|
onConnect: function (wc, sendMessage) {
|
|
|
|
console.warn('CONNECT');
|
|
|
|
|
|
|
|
channel.sendMessage = function (msg, cId, cb) {
|
|
|
|
channel.sendMessage = function (msg, cId, cb) {
|
|
|
|
// Send to server
|
|
|
|
// Send to server
|
|
|
|
sendMessage(msg, function (err) {
|
|
|
|
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...'});
|
|
|
|
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) {
|
|
|
|
var updateProgress = function (data) {
|
|
|
|
data.type = 'drive';
|
|
|
|
data.type = 'drive';
|
|
|
|
postMessage(clientId, 'LOADING_DRIVE', data);
|
|
|
|
postMessage(clientId, 'LOADING_DRIVE', data);
|
|
|
@ -2770,6 +2773,7 @@ console.warn('CONNECT');
|
|
|
|
var listmapConfig = {
|
|
|
|
var listmapConfig = {
|
|
|
|
data: {},
|
|
|
|
data: {},
|
|
|
|
websocketURL: NetConfig.getWebsocketURL(),
|
|
|
|
websocketURL: NetConfig.getWebsocketURL(),
|
|
|
|
|
|
|
|
network: store.network,
|
|
|
|
channel: secret.channel,
|
|
|
|
channel: secret.channel,
|
|
|
|
readOnly: false,
|
|
|
|
readOnly: false,
|
|
|
|
validateKey: secret.keys.validateKey || undefined,
|
|
|
|
validateKey: secret.keys.validateKey || undefined,
|
|
|
@ -2778,7 +2782,6 @@ console.warn('CONNECT');
|
|
|
|
userName: 'fs',
|
|
|
|
userName: 'fs',
|
|
|
|
logLevel: 1,
|
|
|
|
logLevel: 1,
|
|
|
|
ChainPad: ChainPad,
|
|
|
|
ChainPad: ChainPad,
|
|
|
|
lock: lock,
|
|
|
|
|
|
|
|
updateProgress: updateProgress,
|
|
|
|
updateProgress: updateProgress,
|
|
|
|
classic: true,
|
|
|
|
classic: true,
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -2926,7 +2929,50 @@ console.warn('CONNECT');
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
var initialized = false;
|
|
|
|
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) {
|
|
|
|
Store.init = function (clientId, data, _callback) {
|
|
|
|
var callback = Util.once(_callback);
|
|
|
|
var callback = Util.once(_callback);
|
|
|
|
|
|
|
|
|
|
|
@ -2961,20 +3007,28 @@ console.warn('CONNECT');
|
|
|
|
Cache.disable();
|
|
|
|
Cache.disable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
postMessage = function (clientId, cmd, d, cb) {
|
|
|
|
if (data.query && data.broadcast) {
|
|
|
|
data.query(clientId, cmd, d, cb);
|
|
|
|
postMessage = function (clientId, cmd, d, cb) {
|
|
|
|
};
|
|
|
|
data.query(clientId, cmd, d, cb);
|
|
|
|
broadcast = function (excludes, cmd, d, cb) {
|
|
|
|
};
|
|
|
|
data.broadcast(excludes, 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
|
|
|
|
// First tab, no user hash, no anon hash and this app doesn't need a drive
|
|
|
|
// ==> don't create a drive
|
|
|
|
// ==> don't create a drive
|
|
|
|
if (data.noDrive && !data.userHash && !data.anonHash) {
|
|
|
|
if (data.noDrive && !data.userHash && !data.anonHash) {
|
|
|
|
noDrive.push(clientId);
|
|
|
|
return void onNoDrive(clientId, function (obj) {
|
|
|
|
// XXX We need a network before initAnonRpc...
|
|
|
|
if (obj && obj.error) {
|
|
|
|
return void initAnonRpc(null, null, function () {
|
|
|
|
// if we can't properly initialize the noDrive mode, use normal mode
|
|
|
|
callback({});
|
|
|
|
if (obj.error === 'GET_HK') {
|
|
|
|
|
|
|
|
data.noDrive = false;
|
|
|
|
|
|
|
|
Store.init(clientId, data, _callback);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(obj);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|