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 // 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) { Hash.hrefToHexChannelId = function (href, password) {
var parsed = Hash.parsePadUrl(href); var parsed = Hash.parsePadUrl(href);
if (!parsed || !parsed.hash) { return; } if (!parsed || !parsed.hash) { return; }

@ -1200,6 +1200,11 @@ define([
if (!parsed.type || !parsed.hashData) { return void cb('E_INVALID_HREF'); } if (!parsed.type || !parsed.hashData) { return void cb('E_INVALID_HREF'); }
hashes = Hash.getHashes(secret); 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) { if (secret.version === 0) {
// It means we're using an old hash // It means we're using an old hash
hashes.editHash = window.location.hash.slice(1); hashes.editHash = window.location.hash.slice(1);
@ -1212,9 +1217,7 @@ define([
} }
postMessage("GET_STRONGER_HASH", { postMessage("GET_STRONGER_HASH", {
href: window.location.href, channel: secret.channel
channel: secret.channel,
password: secret.password
}, function (hash) { }, function (hash) {
if (hash) { hashes.editHash = hash; } if (hash) { hashes.editHash = hash; }
cb(null, hashes); cb(null, hashes);

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

@ -297,6 +297,21 @@ define([
return data; 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 Drive RPC
*/ */
@ -961,6 +976,7 @@ define([
// Tools // Tools
findChannel: callWithEnv(findChannel), findChannel: callWithEnv(findChannel),
findHref: callWithEnv(findHref), findHref: callWithEnv(findHref),
getEditHash: callWithEnv(getEditHash),
user: Env.user, user: Env.user,
folders: Env.folders folders: Env.folders
}; };

Loading…
Cancel
Save