Fix more async store issues

pull/1/head
yflory 7 years ago
parent d1277d7026
commit 664625a6ef

@ -67,7 +67,7 @@ define([
key: [Constants.tokenKey], key: [Constants.tokenKey],
value: token value: token
}, function (obj) { }, function (obj) {
if (obj.error) { return void cb(obj.error); } if (obj && obj.error) { return void cb(obj.error); }
cb(); cb();
}); });
}; };
@ -402,29 +402,36 @@ define([
common.clearOwnedChannel = function (channel, cb) { common.clearOwnedChannel = function (channel, cb) {
postMessage("CLEAR_OWNED_CHANNEL", {channel: channel}, function (obj) { postMessage("CLEAR_OWNED_CHANNEL", {channel: channel}, function (obj) {
if (obj.error) { return void cb(obj.error); } if (obj && obj.error) { return void cb(obj.error); }
cb(); cb(null, obj);
});
};
common.uploadChunk = function (data, cb) {
postMessage("UPLOAD_CHUNK", {chunk: data}, function (obj) {
if (obj && obj.error) { return void cb(obj.error); }
cb(null, obj);
}); });
}; };
common.uploadComplete = function (cb) { common.uploadComplete = function (cb) {
postMessage("UPLOAD_COMPLETE", null, function (obj) { postMessage("UPLOAD_COMPLETE", null, function (obj) {
if (obj.error) { return void cb(obj.error); } if (obj && obj.error) { return void cb(obj.error); }
cb(); cb(null, obj);
}); });
}; };
common.uploadStatus = function (size, cb) { common.uploadStatus = function (size, cb) {
postMessage("UPLOAD_STATUS", {size: size}, function (obj) { postMessage("UPLOAD_STATUS", {size: size}, function (obj) {
if (obj.error) { return void cb(obj.error); } if (obj && obj.error) { return void cb(obj.error); }
cb(); cb(null, obj);
}); });
}; };
common.uploadCancel = function (cb) { common.uploadCancel = function (cb) {
postMessage("UPLOAD_CANCEL", null, function (obj) { postMessage("UPLOAD_CANCEL", null, function (obj) {
if (obj.error) { return void cb(obj.error); } if (obj && obj.error) { return void cb(obj.error); }
cb(); cb(null, obj);
}); });
}; };
@ -434,7 +441,7 @@ define([
netfluxId: netfluxId, netfluxId: netfluxId,
href: window.location.href href: window.location.href
}, function (obj) { }, function (obj) {
if (obj.error) { return void cb(obj.error); } if (obj && obj.error) { return void cb(obj.error); }
cb(); cb();
}); });
}; };

@ -29,7 +29,7 @@ define([
Store.get = function (key, cb) { Store.get = function (key, cb) {
cb({result: Util.find(store.proxy, key)}); cb(Util.find(store.proxy, key));
}; };
Store.set = function (data, cb) { Store.set = function (data, cb) {
var path = data.key.slice(); var path = data.key.slice();
@ -164,22 +164,34 @@ define([
Store.clearOwnedChannel = function (data, cb) { Store.clearOwnedChannel = function (data, cb) {
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); } if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
store.rpc.clearOwnedChannel(data.channel, cb); store.rpc.clearOwnedChannel(data.channel, function (err, res) {
if (err) { return void cb({error:err}); }
cb(res);
});
}; };
Store.uploadComplete = function (data, cb) { Store.uploadComplete = function (data, cb) {
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); } if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
store.rpc.uploadComplete(cb); store.rpc.uploadComplete(function (err, res) {
if (err) { return void cb({error:err}); }
cb(res);
});
}; };
Store.uploadStatus = function (data, cb) { Store.uploadStatus = function (data, cb) {
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); } if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
store.rpc.uploadStatus(data.size, cb); store.rpc.uploadStatus(data.size, function (err, res) {
if (err) { return void cb({error:err}); }
cb(res);
});
}; };
Store.uploadCancel = function (data, cb) { Store.uploadCancel = function (data, cb) {
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); } if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
store.rpc.uploadCancel(cb); store.rpc.uploadCancel(function (err, res) {
if (err) { return void cb({error:err}); }
cb(res);
});
}; };
var arePinsSynced = function (cb) { var arePinsSynced = function (cb) {
@ -203,6 +215,15 @@ define([
}); });
}; };
Store.uploadChunk = function (data, cb) {
store.rpc.send.unauthenticated('UPLOAD', data.chunk, function (e, msg) {
cb({
error: e,
msg: msg
});
});
};
Store.initRpc = function (data, cb) { Store.initRpc = function (data, cb) {
require(['/common/pinpad.js'], function (Pinpad) { require(['/common/pinpad.js'], function (Pinpad) {
Pinpad.create(store.network, store.proxy, function (e, call) { Pinpad.create(store.network, store.proxy, function (e, call) {
@ -692,7 +713,7 @@ define([
postMessage("UPDATE_METADATA"); postMessage("UPDATE_METADATA");
}); });
proxy.on('change', [Constants.tokenKey], function () { proxy.on('change', [Constants.tokenKey], function () {
postMessage("UPDATE_TOKEN", { data: proxy[Constants.tokenKey] }); postMessage("UPDATE_TOKEN", { token: proxy[Constants.tokenKey] });
}); });
}; };
userObject.migrate(todo); userObject.migrate(todo);

@ -31,6 +31,9 @@ define([
case 'CLEAR_OWNED_CHANNEL': { case 'CLEAR_OWNED_CHANNEL': {
Store.clearOwnedChannel(data, cb); break; Store.clearOwnedChannel(data, cb); break;
} }
case 'UPLOAD_CHUNK': {
Store.uploadChunk(data, cb); break;
}
case 'UPLOAD_COMPLETE': { case 'UPLOAD_COMPLETE': {
Store.uploadComplete(data, cb); break; Store.uploadComplete(data, cb); break;
} }

@ -20,7 +20,7 @@ define([
var sendChunk = function (box, cb) { var sendChunk = function (box, cb) {
var enc = Nacl.util.encodeBase64(box); var enc = Nacl.util.encodeBase64(box);
common.rpc.send.unauthenticated('UPLOAD', enc, function (e, msg) { common.uploadChunk(enc, function (e, msg) {
cb(e, msg); cb(e, msg);
}); });
}; };

@ -114,8 +114,13 @@ define([
}); });
if (cfg.getSecrets) { if (cfg.getSecrets) {
var w = waitFor();
cfg.getSecrets(Cryptpad, Utils, waitFor(function (err, s) { cfg.getSecrets(Cryptpad, Utils, waitFor(function (err, s) {
secret = s; secret = s;
Cryptpad.getShareHashes(secret, function (err, h) {
hashes = h;
w();
});
})); }));
} else { } else {
secret = Utils.Hash.getSecrets(); secret = Utils.Hash.getSecrets();
@ -123,8 +128,8 @@ define([
// New pad: create a new random channel id // New pad: create a new random channel id
secret.channel = Utils.Hash.createChannelId(); secret.channel = Utils.Hash.createChannelId();
} }
}
Cryptpad.getShareHashes(secret, waitFor(function (err, h) { hashes = h; })); Cryptpad.getShareHashes(secret, waitFor(function (err, h) { hashes = h; }));
}
}).nThen(function () { }).nThen(function () {
var readOnly = secret.keys && !secret.keys.editKeyStr; var readOnly = secret.keys && !secret.keys.editKeyStr;
@ -247,7 +252,7 @@ define([
cb('ERROR'); cb('ERROR');
return; return;
} }
Cryptpad.changeDisplayName(newName, true); Cryptpad.changeMetadata();
cb(); cb();
}); });
}); });

@ -1,10 +1,8 @@
define([ define([
'jquery', 'jquery',
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
'/bower_components/textpatcher/TextPatcher.js',
'/common/toolbar3.js', '/common/toolbar3.js',
'json.sortify', 'json.sortify',
'/bower_components/chainpad-json-validator/json-ot.js',
'/common/common-util.js', '/common/common-util.js',
'/bower_components/nthen/index.js', '/bower_components/nthen/index.js',
'/common/sframe-common.js', '/common/sframe-common.js',
@ -22,10 +20,8 @@ define([
], function ( ], function (
$, $,
Crypto, Crypto,
TextPatcher,
Toolbar, Toolbar,
JSONSortify, JSONSortify,
JsonOT,
Util, Util,
nThen, nThen,
SFCommon, SFCommon,
@ -61,7 +57,6 @@ define([
var config = APP.config = { var config = APP.config = {
readOnly: readOnly, readOnly: readOnly,
transformFunction: JsonOT.validate,
// cryptpad debug logging (default is 1) // cryptpad debug logging (default is 1)
// logLevel: 0, // logLevel: 0,
validateContent: function (content) { validateContent: function (content) {
@ -123,11 +118,7 @@ define([
config.onReady = function (info) { config.onReady = function (info) {
if (APP.realtime !== info.realtime) { if (APP.realtime !== info.realtime) {
var realtime = APP.realtime = info.realtime; APP.realtime = info.realtime;
APP.patchText = TextPatcher.create({
realtime: realtime,
//logging: true
});
} }
var userDoc = APP.realtime.getUserDoc(); var userDoc = APP.realtime.getUserDoc();

@ -49,7 +49,7 @@ define([
editHash = hash; editHash = hash;
})); }));
}).nThen(function () { }).nThen(function () {
if (!editHash) { if (editHash) {
return void cb(null, Hash.getSecrets('profile', editHash)); return void cb(null, Hash.getSecrets('profile', editHash));
} }
// 3rd case: profile creation (create a new random hash, store it later if needed) // 3rd case: profile creation (create a new random hash, store it later if needed)

Loading…
Cancel
Save