Fix issues with the async store
This commit is contained in:
@@ -571,12 +571,7 @@ define([
|
|||||||
// getPinnedUsage updates common.account.usage, and other values
|
// getPinnedUsage updates common.account.usage, and other values
|
||||||
// so we can just use those and only check for errors
|
// so we can just use those and only check for errors
|
||||||
var $container = $('<span>', {'class':'cp-limit-container'});
|
var $container = $('<span>', {'class':'cp-limit-container'});
|
||||||
var todo;
|
var todo = function (err, data) {
|
||||||
var updateUsage = Util.notAgainForAnother(function () {
|
|
||||||
common.getPinUsage(todo);
|
|
||||||
}, LIMIT_REFRESH_RATE);
|
|
||||||
|
|
||||||
todo = function (err, data) {
|
|
||||||
if (err) { return void console.error(err); }
|
if (err) { return void console.error(err); }
|
||||||
|
|
||||||
var usage = data.usage;
|
var usage = data.usage;
|
||||||
@@ -645,6 +640,10 @@ define([
|
|||||||
$limit.append($usage).append($text);
|
$limit.append($usage).append($text);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var updateUsage = Util.notAgainForAnother(function () {
|
||||||
|
common.getPinUsage(todo);
|
||||||
|
}, LIMIT_REFRESH_RATE);
|
||||||
|
|
||||||
setInterval(function () {
|
setInterval(function () {
|
||||||
updateUsage();
|
updateUsage();
|
||||||
}, LIMIT_REFRESH_RATE * 3);
|
}, LIMIT_REFRESH_RATE * 3);
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
define([
|
define([
|
||||||
'jquery',
|
|
||||||
'/api/config',
|
'/api/config',
|
||||||
'/customize/messages.js',
|
'/customize/messages.js',
|
||||||
'/common/common-util.js',
|
'/common/common-util.js',
|
||||||
@@ -15,7 +14,7 @@ define([
|
|||||||
'/common/pinpad.js',
|
'/common/pinpad.js',
|
||||||
'/customize/application_config.js',
|
'/customize/application_config.js',
|
||||||
'/bower_components/nthen/index.js',
|
'/bower_components/nthen/index.js',
|
||||||
], function ($, Config, Messages, Util, Hash,
|
], function (Config, Messages, Util, Hash,
|
||||||
Messaging, Realtime, Language, Constants, Feedback, LocalStore, AStore,
|
Messaging, Realtime, Language, Constants, Feedback, LocalStore, AStore,
|
||||||
Pinpad, AppConfig, Nthen) {
|
Pinpad, AppConfig, Nthen) {
|
||||||
|
|
||||||
@@ -238,13 +237,13 @@ define([
|
|||||||
postMessage("GET_TEMPLATES", null, function (obj) {
|
postMessage("GET_TEMPLATES", null, function (obj) {
|
||||||
if (obj && obj.error) { return void cb(obj.error); }
|
if (obj && obj.error) { return void cb(obj.error); }
|
||||||
if (!Array.isArray(obj)) { return void cb ('NOT_AN_ARRAY'); }
|
if (!Array.isArray(obj)) { return void cb ('NOT_AN_ARRAY'); }
|
||||||
if (!type) { return void cb(obj); }
|
if (!type) { return void cb(null, obj); }
|
||||||
|
|
||||||
var templates = obj.filter(function (f) {
|
var templates = obj.filter(function (f) {
|
||||||
var parsed = Hash.parsePadUrl(f.href);
|
var parsed = Hash.parsePadUrl(f.href);
|
||||||
return parsed.type === type;
|
return parsed.type === type;
|
||||||
});
|
});
|
||||||
cb(templates);
|
cb(null, templates);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -257,7 +256,8 @@ define([
|
|||||||
if (e) { throw new Error(e); }
|
if (e) { throw new Error(e); }
|
||||||
postMessage("ADD_PAD", {
|
postMessage("ADD_PAD", {
|
||||||
href: href,
|
href: href,
|
||||||
title: data.title
|
title: data.title,
|
||||||
|
path: ['template']
|
||||||
}, function (obj) {
|
}, function (obj) {
|
||||||
if (obj && obj.error) { return void cb(obj.error); }
|
if (obj && obj.error) { return void cb(obj.error); }
|
||||||
cb();
|
cb();
|
||||||
@@ -267,7 +267,7 @@ define([
|
|||||||
|
|
||||||
common.isTemplate = function (href, cb) {
|
common.isTemplate = function (href, cb) {
|
||||||
var rhref = Hash.getRelativeHref(href);
|
var rhref = Hash.getRelativeHref(href);
|
||||||
common.listTemplates(null, function (templates) {
|
common.listTemplates(null, function (err, templates) {
|
||||||
cb(void 0, templates.some(function (t) {
|
cb(void 0, templates.some(function (t) {
|
||||||
return t.href === rhref;
|
return t.href === rhref;
|
||||||
}));
|
}));
|
||||||
@@ -321,22 +321,22 @@ define([
|
|||||||
|
|
||||||
common.pinPads = function (pads, cb) {
|
common.pinPads = function (pads, cb) {
|
||||||
postMessage("PIN_PADS", pads, function (obj) {
|
postMessage("PIN_PADS", pads, function (obj) {
|
||||||
if (obj.error) { return void cb(obj.error); }
|
if (obj && obj.error) { return void cb(obj.error); }
|
||||||
cb();
|
cb(null, obj.hash);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
common.unpinPads = function (pads, cb) {
|
common.unpinPads = function (pads, cb) {
|
||||||
postMessage("UNPIN_PADS", pads, function (obj) {
|
postMessage("UNPIN_PADS", pads, function (obj) {
|
||||||
if (obj.error) { return void cb(obj.error); }
|
if (obj && obj.error) { return void cb(obj.error); }
|
||||||
cb();
|
cb(null, obj.hash);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
common.getPinnedUsage = function (cb) {
|
common.getPinnedUsage = function (cb) {
|
||||||
postMessage("GET_PINNED_USAGE", null, function (obj) {
|
postMessage("GET_PINNED_USAGE", null, function (obj) {
|
||||||
if (obj.error) { return void cb(obj.error); }
|
if (obj.error) { return void cb(obj.error); }
|
||||||
cb();
|
cb(null, obj.bytes);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -544,12 +544,6 @@ define([
|
|||||||
return void setTimeout(function () { f(void 0, env); });
|
return void setTimeout(function () { f(void 0, env); });
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
if (sessionStorage[Constants.newPadPathKey]) {
|
|
||||||
common.initialPath = sessionStorage[Constants.newPadPathKey];
|
|
||||||
delete sessionStorage[Constants.newPadPathKey];
|
|
||||||
}
|
|
||||||
|
|
||||||
var provideFeedback = function () {
|
var provideFeedback = function () {
|
||||||
if (typeof(window.Proxy) === 'undefined') {
|
if (typeof(window.Proxy) === 'undefined') {
|
||||||
Feedback.send("NO_PROXIES");
|
Feedback.send("NO_PROXIES");
|
||||||
@@ -581,8 +575,12 @@ define([
|
|||||||
query: onMessage, // TODO temporary, will be replaced by a webworker channel
|
query: onMessage, // TODO temporary, will be replaced by a webworker channel
|
||||||
userHash: LocalStore.getUserHash(),
|
userHash: LocalStore.getUserHash(),
|
||||||
anonHash: LocalStore.getFSHash(),
|
anonHash: LocalStore.getFSHash(),
|
||||||
localToken: localStorage.getItem(Constants.tokenKey)
|
localToken: tryParsing(localStorage.getItem(Constants.tokenKey))
|
||||||
};
|
};
|
||||||
|
if (sessionStorage[Constants.newPadPathKey]) {
|
||||||
|
cfg.initialPath = sessionStorage[Constants.newPadPathKey];
|
||||||
|
delete sessionStorage[Constants.newPadPathKey];
|
||||||
|
}
|
||||||
AStore.query("CONNECT", cfg, waitFor(function (data) {
|
AStore.query("CONNECT", cfg, waitFor(function (data) {
|
||||||
if (data.error) { throw new Error(data.error); }
|
if (data.error) { throw new Error(data.error); }
|
||||||
|
|
||||||
@@ -606,8 +604,6 @@ define([
|
|||||||
//Messaging.addDirectMessageHandler(common);
|
//Messaging.addDirectMessageHandler(common);
|
||||||
initFeedback(data.feedback);
|
initFeedback(data.feedback);
|
||||||
}));
|
}));
|
||||||
}).nThen(function (waitFor) {
|
|
||||||
$(waitFor());
|
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
// Load the new pad when the hash has changed
|
// Load the new pad when the hash has changed
|
||||||
var oldHref = document.location.href;
|
var oldHref = document.location.href;
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ define(['json.sortify'], function (Sortify) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (metadataObj.title !== rememberedTitle) {
|
if (metadataObj.title !== rememberedTitle) {
|
||||||
console.log("Title update\n" + metadataObj.title + '\n');
|
|
||||||
rememberedTitle = metadataObj.title;
|
rememberedTitle = metadataObj.title;
|
||||||
titleChangeHandlers.forEach(function (f) { f(metadataObj.title); });
|
titleChangeHandlers.forEach(function (f) { f(metadataObj.title); });
|
||||||
}
|
}
|
||||||
@@ -73,30 +72,45 @@ define(['json.sortify'], function (Sortify) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var netfluxId;
|
||||||
|
var isReady = false;
|
||||||
|
var readyHandlers = [];
|
||||||
sframeChan.on('EV_METADATA_UPDATE', function (ev) {
|
sframeChan.on('EV_METADATA_UPDATE', function (ev) {
|
||||||
meta = ev;
|
meta = ev;
|
||||||
if (ev.priv) {
|
if (ev.priv) {
|
||||||
priv = ev.priv;
|
priv = ev.priv;
|
||||||
}
|
}
|
||||||
|
if (netfluxId) {
|
||||||
|
meta.user.netfluxId = netfluxId;
|
||||||
|
}
|
||||||
|
if (!isReady) {
|
||||||
|
isReady = true;
|
||||||
|
readyHandlers.forEach(function (f) { f(); });
|
||||||
|
}
|
||||||
change(true);
|
change(true);
|
||||||
});
|
});
|
||||||
sframeChan.on('EV_RT_CONNECT', function (ev) {
|
sframeChan.on('EV_RT_CONNECT', function (ev) {
|
||||||
meta.user.netfluxId = ev.myID;
|
netfluxId = ev.myID;
|
||||||
members = ev.members;
|
members = ev.members;
|
||||||
|
if (!meta.user) { return; }
|
||||||
|
meta.user.netfluxId = netfluxId;
|
||||||
change(true);
|
change(true);
|
||||||
});
|
});
|
||||||
sframeChan.on('EV_RT_JOIN', function (ev) {
|
sframeChan.on('EV_RT_JOIN', function (ev) {
|
||||||
members.push(ev);
|
members.push(ev);
|
||||||
|
if (!meta.user) { return; }
|
||||||
change(false);
|
change(false);
|
||||||
});
|
});
|
||||||
sframeChan.on('EV_RT_LEAVE', function (ev) {
|
sframeChan.on('EV_RT_LEAVE', function (ev) {
|
||||||
var idx = members.indexOf(ev);
|
var idx = members.indexOf(ev);
|
||||||
if (idx === -1) { console.log('Error: ' + ev + ' not in members'); return; }
|
if (idx === -1) { console.log('Error: ' + ev + ' not in members'); return; }
|
||||||
members.splice(idx, 1);
|
members.splice(idx, 1);
|
||||||
|
if (!meta.user) { return; }
|
||||||
change(false);
|
change(false);
|
||||||
});
|
});
|
||||||
sframeChan.on('EV_RT_DISCONNECT', function () {
|
sframeChan.on('EV_RT_DISCONNECT', function () {
|
||||||
members = [];
|
members = [];
|
||||||
|
if (!meta.user) { return; }
|
||||||
change(true);
|
change(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -140,6 +154,10 @@ define(['json.sortify'], function (Sortify) {
|
|||||||
},
|
},
|
||||||
getNetfluxId : function () {
|
getNetfluxId : function () {
|
||||||
return meta.user.netfluxId;
|
return meta.user.netfluxId;
|
||||||
|
},
|
||||||
|
onReady: function (f) {
|
||||||
|
if (isReady) { return void f(); }
|
||||||
|
readyHandlers.push(f);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -300,7 +300,6 @@ define([
|
|||||||
avatar: Util.find(store.proxy, ['profile', 'avatar']),
|
avatar: Util.find(store.proxy, ['profile', 'avatar']),
|
||||||
profile: Util.find(store.proxy, ['profile', 'view']),
|
profile: Util.find(store.proxy, ['profile', 'view']),
|
||||||
curvePublic: store.proxy.curvePublic,
|
curvePublic: store.proxy.curvePublic,
|
||||||
netfluxId: store.network.webChannels[0].myID
|
|
||||||
},
|
},
|
||||||
// "priv" is not shared with other users but is needed by the apps
|
// "priv" is not shared with other users but is needed by the apps
|
||||||
priv: {
|
priv: {
|
||||||
@@ -458,7 +457,8 @@ define([
|
|||||||
var pad = makePad(data.href, data.title);
|
var pad = makePad(data.href, data.title);
|
||||||
store.userObject.pushData(pad, function (e, id) {
|
store.userObject.pushData(pad, function (e, id) {
|
||||||
if (e) { return void cb({error: "Error while adding a template:"+ e}); }
|
if (e) { return void cb({error: "Error while adding a template:"+ e}); }
|
||||||
store.userObject.add(id, ['template']);
|
var path = data.path || ['root'];
|
||||||
|
store.userObject.add(id, path);
|
||||||
onSync(cb);
|
onSync(cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -546,7 +546,8 @@ define([
|
|||||||
if (!contains) {
|
if (!contains) {
|
||||||
Store.addPad({
|
Store.addPad({
|
||||||
href: href,
|
href: href,
|
||||||
title: title
|
title: title,
|
||||||
|
path: store.data && store.data.initialPath
|
||||||
}, cb);
|
}, cb);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -599,7 +600,6 @@ define([
|
|||||||
|
|
||||||
// Messaging
|
// Messaging
|
||||||
var getMessagingCfg = function () {
|
var getMessagingCfg = function () {
|
||||||
console.log(store, store.network);
|
|
||||||
return {
|
return {
|
||||||
proxy: store.proxy,
|
proxy: store.proxy,
|
||||||
realtime: store.realtime,
|
realtime: store.realtime,
|
||||||
@@ -624,7 +624,7 @@ define([
|
|||||||
var onReady = function (returned, cb) {
|
var onReady = function (returned, cb) {
|
||||||
var proxy = store.proxy;
|
var proxy = store.proxy;
|
||||||
var userObject = store.userObject = UserObject.init(proxy.drive, {
|
var userObject = store.userObject = UserObject.init(proxy.drive, {
|
||||||
pinPads: function (pads, cb) { Store.pinPads({pads: pads}, cb); },
|
pinPads: Store.pinPads,
|
||||||
loggedIn: store.loggedIn
|
loggedIn: store.loggedIn
|
||||||
});
|
});
|
||||||
var todo = function () {
|
var todo = function () {
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ define([
|
|||||||
if (cfg.addData) {
|
if (cfg.addData) {
|
||||||
cfg.addData(metaObj.priv, Cryptpad);
|
cfg.addData(metaObj.priv, Cryptpad);
|
||||||
}
|
}
|
||||||
|
|
||||||
sframeChan.event('EV_METADATA_UPDATE', metaObj);
|
sframeChan.event('EV_METADATA_UPDATE', metaObj);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -228,7 +229,7 @@ define([
|
|||||||
sframeChan.on('Q_SET_PAD_TITLE_IN_DRIVE', function (newTitle, cb) {
|
sframeChan.on('Q_SET_PAD_TITLE_IN_DRIVE', function (newTitle, cb) {
|
||||||
currentTitle = newTitle;
|
currentTitle = newTitle;
|
||||||
setDocumentTitle();
|
setDocumentTitle();
|
||||||
Cryptpad.renamePad(newTitle, undefined, function (err) {
|
Cryptpad.setPadTitle(newTitle, undefined, function (err) {
|
||||||
cb(err);
|
cb(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -122,7 +122,6 @@ define([
|
|||||||
funcs.getFileSize = function (href, cb) {
|
funcs.getFileSize = function (href, cb) {
|
||||||
var channelId = Hash.hrefToHexChannelId(href);
|
var channelId = Hash.hrefToHexChannelId(href);
|
||||||
funcs.sendAnonRpcMsg("GET_FILE_SIZE", channelId, function (data) {
|
funcs.sendAnonRpcMsg("GET_FILE_SIZE", channelId, function (data) {
|
||||||
console.log(data);
|
|
||||||
if (!data) { return void cb("No response"); }
|
if (!data) { return void cb("No response"); }
|
||||||
if (data.error) { return void cb(data.error); }
|
if (data.error) { return void cb(data.error); }
|
||||||
if (data.response && data.response.length && typeof(data.response[0]) === 'number') {
|
if (data.response && data.response.length && typeof(data.response[0]) === 'number') {
|
||||||
@@ -329,7 +328,7 @@ define([
|
|||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
SFrameChannel.create(window.parent, waitFor(function (sfc) { ctx.sframeChan = sfc; }), true);
|
SFrameChannel.create(window.parent, waitFor(function (sfc) { ctx.sframeChan = sfc; }), true);
|
||||||
// CpNfInner.start() should be here....
|
// CpNfInner.start() should be here....
|
||||||
}).nThen(function () {
|
}).nThen(function (waitFor) {
|
||||||
localForage.clear();
|
localForage.clear();
|
||||||
|
|
||||||
ctx.metadataMgr = MetadataMgr.create(ctx.sframeChan);
|
ctx.metadataMgr = MetadataMgr.create(ctx.sframeChan);
|
||||||
@@ -390,6 +389,8 @@ define([
|
|||||||
} catch (e) { Feedback.init(false); }
|
} catch (e) { Feedback.init(false); }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ctx.metadataMgr.onReady(waitFor());
|
||||||
|
}).nThen(function () {
|
||||||
ctx.sframeChan.ready();
|
ctx.sframeChan.ready();
|
||||||
cb(funcs);
|
cb(funcs);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -487,7 +487,6 @@ define([
|
|||||||
|
|
||||||
// FILES DATA
|
// FILES DATA
|
||||||
exp.pushData = function (data, cb) {
|
exp.pushData = function (data, cb) {
|
||||||
// TODO: can only be called from outside atm
|
|
||||||
if (!pinPads) { return; }
|
if (!pinPads) { return; }
|
||||||
if (typeof cb !== "function") { cb = function () {}; }
|
if (typeof cb !== "function") { cb = function () {}; }
|
||||||
var todo = function () {
|
var todo = function () {
|
||||||
@@ -498,8 +497,8 @@ define([
|
|||||||
if (!loggedIn || !AppConfig.enablePinning || config.testMode) {
|
if (!loggedIn || !AppConfig.enablePinning || config.testMode) {
|
||||||
return void todo();
|
return void todo();
|
||||||
}
|
}
|
||||||
pinPads([Hash.hrefToHexChannelId(data.href)], function (e) {
|
pinPads([Hash.hrefToHexChannelId(data.href)], function (obj) {
|
||||||
if (e) { return void cb(e); }
|
if (obj && obj.error) { return void cb(obj.error); }
|
||||||
todo();
|
todo();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -120,7 +120,6 @@ define([
|
|||||||
decrypted.callback();
|
decrypted.callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(decrypted);
|
|
||||||
$dlview.show();
|
$dlview.show();
|
||||||
$dlform.hide();
|
$dlform.hide();
|
||||||
var $dlButton = $dlview.find('media-tag button');
|
var $dlButton = $dlview.find('media-tag button');
|
||||||
@@ -174,7 +173,6 @@ define([
|
|||||||
var progress = e.originalEvent;
|
var progress = e.originalEvent;
|
||||||
var p = progress.percent +'%';
|
var p = progress.percent +'%';
|
||||||
$progress.width(p);
|
$progress.width(p);
|
||||||
console.log(progress.percent);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user