Improve getStrongerHash to also look inside shared folders

pull/1/head
yflory 5 years ago
parent e0a1b8724b
commit 4e4d01a471

@ -420,36 +420,6 @@ Version 1
};
// STORAGE
Hash.findStronger = function (href, channel, recents) {
var parsed = parsePadUrl(href);
if (!parsed.hash) { return false; }
var parsedHash = parsed.hashData;
// We can't have a stronger hash if we're already in edit mode
if (!parsedHash || parsedHash.mode === 'edit') { return; }
// We don't have stronger/weaker versions of files or users
if (parsedHash.type !== 'pad') { return; }
var stronger;
Object.keys(recents).some(function (id) {
var pad = recents[id];
// Not the same channel? reject
if (channel !== pad.channel) { return; }
// If this pad doesn't have an edit link, it can't be stronger
// XXX encrypted href
if (!pad.href || !pad.roHref) { return; }
// This is a pad with an EDIT href and using the same channel as our target
// ==> it is stronger
stronger = pad;
return true;
});
return stronger;
};
Hash.hrefToHexChannelId = function (href, password) {
var parsed = Hash.parsePadUrl(href);
if (!parsed || !parsed.hash) { return; }

@ -1200,6 +1200,11 @@ define([
if (!parsed.type || !parsed.hashData) { return void cb('E_INVALID_HREF'); }
hashes = Hash.getHashes(secret);
// If the current href is an edit one, return the existing hashes
var parsedHash = parsed.hashData;
if (!parsedHash || parsedHash.mode === 'edit') { return void cb(null, hashes); }
if (parsedHash.type !== 'pad') { return void cb(null, hashes); }
if (secret.version === 0) {
// It means we're using an old hash
hashes.editHash = window.location.hash.slice(1);
@ -1212,9 +1217,7 @@ define([
}
postMessage("GET_STRONGER_HASH", {
href: window.location.href,
channel: secret.channel,
password: secret.password
channel: secret.channel
}, function (hash) {
if (hash) { hashes.editHash = hash; }
cb(null, hashes);

@ -1265,21 +1265,17 @@ define([
// Get hashes for the share button
// If we can find a stronger hash
Store.getStrongerHash = function (clientId, data, cb) {
var found = getAllStores().some(function (s) {
var allPads = Util.find(s.proxy, ['drive', 'filesData']) || {};
Store.getStrongerHash = function (clientId, data, _cb) {
var cb = Util.once(_cb);
// If we have a stronger version in drive, add it and add a redirect button
var stronger = Hash.findStronger(data.href, data.channel, allPads);
var found = getAllStores().some(function (s) {
var stronger = s.manager.getEditHash(data.channel);
if (stronger) {
var parsed2 = Hash.parsePadUrl(stronger.href);
cb(parsed2.hash);
cb(stronger);
return true;
}
});
if (!found) {
cb();
}
if (!found) { cb(); }
};
// Universal

@ -297,6 +297,21 @@ define([
return data;
};
var getEditHash = function (Env, channel) {
var res = findChannel(Env, channel);
var stronger;
res.some(function (obj) {
if (!obj || !obj.data || !obj.data.href) { return; }
var parsed = Hash.parsePadUrl(obj.data.href);
var parsedHash = parsed.hashData;
if (!parsedHash || parsedHash.mode === 'view') { return; }
// We've found an edit hash!
stronger = parsed.hash;
return true;
});
return stronger;
};
/*
Drive RPC
*/
@ -961,6 +976,7 @@ define([
// Tools
findChannel: callWithEnv(findChannel),
findHref: callWithEnv(findHref),
getEditHash: callWithEnv(getEditHash),
user: Env.user,
folders: Env.folders
};

Loading…
Cancel
Save