Open pads in offline mode
parent
80a33a5cb5
commit
989020a436
|
@ -11,11 +11,13 @@ define([
|
|||
'/common/outer/local-store.js',
|
||||
'/common/outer/worker-channel.js',
|
||||
'/common/outer/login-block.js',
|
||||
'/common/outer/cache-store.js',
|
||||
|
||||
'/customize/application_config.js',
|
||||
'/bower_components/nthen/index.js',
|
||||
], function (Config, Messages, Util, Hash,
|
||||
Messaging, Constants, Feedback, Visible, UserObject, LocalStore, Channel, Block,
|
||||
Cache,
|
||||
AppConfig, Nthen) {
|
||||
|
||||
/* This file exposes functionality which is specific to Cryptpad, but not to
|
||||
|
@ -437,10 +439,35 @@ define([
|
|||
});
|
||||
};
|
||||
|
||||
common.getFileSize = function (href, password, cb) {
|
||||
postMessage("GET_FILE_SIZE", {href: href, password: password}, function (obj) {
|
||||
if (obj && obj.error) { return void cb(obj.error); }
|
||||
cb(undefined, obj.size);
|
||||
common.getFileSize = function (href, password, _cb) {
|
||||
var cb = Util.once(Util.mkAsync(_cb));
|
||||
var channel = Hash.hrefToHexChannelId(href, password);
|
||||
var error;
|
||||
Nthen(function (waitFor) {
|
||||
// Blobs can't change, if it's in the cache, use it
|
||||
Cache.getBlobCache(channel, waitFor(function(err, blob) {
|
||||
if (err) { return; }
|
||||
waitFor.abort();
|
||||
cb(null, blob.length);
|
||||
}));
|
||||
|
||||
}).nThen(function (waitFor) {
|
||||
// If it's not in the cache or it's not a blob, try to get the value from the server
|
||||
postMessage("GET_FILE_SIZE", {channel:channel}, waitFor(function (obj) {
|
||||
if (obj && obj.error) {
|
||||
// If disconnected, try to get the value from the channel cache (next nThen)
|
||||
error = obj.error;
|
||||
return;
|
||||
}
|
||||
waitFor.abort();
|
||||
cb(undefined, obj.size);
|
||||
}));
|
||||
}).nThen(function () {
|
||||
Cache.getChannelCache(channel, function(err, data) {
|
||||
if (err) { return void cb(error); }
|
||||
var size = data && Array.isArray(data.c) && data.c.join('').length;
|
||||
cb(null, size || 0);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -451,11 +478,23 @@ define([
|
|||
});
|
||||
};
|
||||
|
||||
common.isNewChannel = function (href, password, cb) {
|
||||
postMessage('IS_NEW_CHANNEL', {href: href, password: password}, function (obj) {
|
||||
if (obj.error) { return void cb(obj.error); }
|
||||
if (!obj) { return void cb('INVALID_RESPONSE'); }
|
||||
cb(undefined, obj.isNew);
|
||||
common.isNewChannel = function (href, password, _cb) {
|
||||
var cb = Util.once(Util.mkAsync(_cb));
|
||||
var channel = Hash.hrefToHexChannelId(href, password);
|
||||
var error;
|
||||
Nthen(function (waitFor) {
|
||||
// If it's not in the cache or it's not a blob, try to get the value from the server
|
||||
postMessage('IS_NEW_CHANNEL', {channel: channel}, waitFor(function (obj) {
|
||||
if (obj && obj.error) { error = obj.error; return; }
|
||||
if (!obj) { error = "INVALID_RESPONSE"; return; }
|
||||
waitFor.abort();
|
||||
cb(undefined, obj.isNew);
|
||||
}));
|
||||
}).nThen(function () {
|
||||
Cache.getChannelCache(channel, function(err, data) {
|
||||
if (err || !data) { return void cb(error); }
|
||||
cb(null, false);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ define([
|
|||
MT.displayAvatar = function (common, $container, href, name, _cb) {
|
||||
var cb = Util.once(Util.mkAsync(_cb || function () {}));
|
||||
var displayDefault = function () {
|
||||
var text = (href && typeof(href) === "string") ? href : Util.getFirstCharacter(name);
|
||||
var text = Util.getFirstCharacter(name || Messages.anonymous);
|
||||
var $avatar = $('<span>', {'class': 'cp-avatar-default'}).text(text);
|
||||
$container.append($avatar);
|
||||
if (cb) { cb(); }
|
||||
|
|
|
@ -1037,6 +1037,7 @@ define([
|
|||
//});
|
||||
|
||||
execCommand('GET_MY_INFO', null, function (e, info) {
|
||||
if (e) { return; }
|
||||
contactsData[info.curvePublic] = info;
|
||||
});
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ define([
|
|||
Realtime.whenRealtimeSyncs(s.sharedFolders[k].realtime, waitFor());
|
||||
}
|
||||
}
|
||||
}).nThen(function () { console.log('done');cb(); });
|
||||
}).nThen(function () { cb(); });
|
||||
};
|
||||
|
||||
Store.get = function (clientId, data, cb) {
|
||||
|
@ -1035,9 +1035,6 @@ define([
|
|||
});
|
||||
};
|
||||
Store.setPadTitle = function (clientId, data, cb) {
|
||||
if (store.offline) {
|
||||
return void cb({ error: 'OFFLINE' });
|
||||
}
|
||||
var title = data.title;
|
||||
var href = data.href;
|
||||
var channel = data.channel;
|
||||
|
@ -1110,6 +1107,11 @@ define([
|
|||
Array.prototype.push.apply(allData, res);
|
||||
});
|
||||
var contains = allData.length !== 0;
|
||||
if (store.offline && !contains) {
|
||||
return void cb({ error: 'OFFLINE' });
|
||||
} else if (store.offline) {
|
||||
return void cb();
|
||||
}
|
||||
allData.forEach(function (obj) {
|
||||
var pad = obj.data;
|
||||
pad.atime = +new Date();
|
||||
|
@ -1689,7 +1691,7 @@ define([
|
|||
noChainPad: true,
|
||||
channel: data.channel,
|
||||
metadata: data.metadata,
|
||||
network: store.network,
|
||||
network: store.network || store.networkPromise,
|
||||
//readOnly: data.readOnly,
|
||||
onConnect: function (wc, sendMessage) {
|
||||
channel.sendMessage = function (msg, cId, cb) {
|
||||
|
|
|
@ -45,6 +45,7 @@ define([
|
|||
window.addEventListener('message', onMsg);
|
||||
}).nThen(function (/*waitFor*/) {
|
||||
SFCommonO.start({
|
||||
cache: true,
|
||||
hash: hash,
|
||||
href: href,
|
||||
useCreationScreen: true,
|
||||
|
|
|
@ -431,6 +431,10 @@ define([
|
|||
}
|
||||
if (!stored && !parsed.hashData.password) {
|
||||
// We've received a link without /p/ and it doesn't work without a password: abort
|
||||
if (e === "ANON_RPC_NOT_READY") {
|
||||
// We're currently offline and the pad is not in our cache
|
||||
sframeChan.event('EV_OFFLINE');
|
||||
}
|
||||
return void todo();
|
||||
}
|
||||
// Wrong password or deleted file?
|
||||
|
|
|
@ -15,6 +15,7 @@ define([
|
|||
'/common/metadata-manager.js',
|
||||
|
||||
'/customize/application_config.js',
|
||||
'/common/outer/cache-store.js',
|
||||
'/common/common-realtime.js',
|
||||
'/common/common-util.js',
|
||||
'/common/common-hash.js',
|
||||
|
@ -39,6 +40,7 @@ define([
|
|||
MT,
|
||||
MetadataMgr,
|
||||
AppConfig,
|
||||
Cache,
|
||||
CommonRealtime,
|
||||
Util,
|
||||
Hash,
|
||||
|
@ -167,14 +169,22 @@ define([
|
|||
};
|
||||
|
||||
funcs.getFileSize = function (channelId, cb) {
|
||||
funcs.sendAnonRpcMsg("GET_FILE_SIZE", channelId, function (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') {
|
||||
return void cb(void 0, data.response[0]);
|
||||
} else {
|
||||
cb('INVALID_RESPONSE');
|
||||
}
|
||||
nThen(function (waitFor) {
|
||||
Cache.getBlobCache(channelId, waitFor(function(err, blob) {
|
||||
if (err) { return; }
|
||||
waitFor.abort();
|
||||
cb(null, blob.length);
|
||||
}));
|
||||
}).nThen(function () {
|
||||
funcs.sendAnonRpcMsg("GET_FILE_SIZE", channelId, function (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') {
|
||||
return void cb(void 0, data.response[0]);
|
||||
} else {
|
||||
cb('INVALID_RESPONSE');
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -678,6 +688,10 @@ define([
|
|||
UI.errorLoadingScreen(Messages.restrictedError);
|
||||
});
|
||||
|
||||
ctx.sframeChan.on("EV_OFFLINE", function () {
|
||||
UI.errorLoadingScreen("OFFLINE AND NO CACHE"); // XXX
|
||||
});
|
||||
|
||||
ctx.sframeChan.on("EV_PAD_PASSWORD_ERROR", function () {
|
||||
UI.errorLoadingScreen(Messages.password_error_seed);
|
||||
});
|
||||
|
|
|
@ -365,6 +365,9 @@ MessengerUI, Messages) {
|
|||
if (!toolbar.connected) { return; }
|
||||
updateUserList(toolbar, config);
|
||||
});
|
||||
setTimeout(function () {
|
||||
updateUserList(toolbar, config, true);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1246,8 +1249,8 @@ MessengerUI, Messages) {
|
|||
if (typeof el !== "string" || !el.trim()) { return; }
|
||||
if (typeof tb[el] === "function") {
|
||||
if (!init && config.displayed.indexOf(el) !== -1) { return; } // Already done
|
||||
toolbar[el] = tb[el](toolbar, config);
|
||||
if (!init) { config.displayed.push(el); }
|
||||
toolbar[el] = tb[el](toolbar, config);
|
||||
}
|
||||
});
|
||||
checkSize();
|
||||
|
|
Loading…
Reference in New Issue