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