Skip to content

Commit

Permalink
Merge branch 'drive-history-fixes' into soon
Browse files Browse the repository at this point in the history
  • Loading branch information
ansuz committed Apr 13, 2022
2 parents b3d109f + a562bbc commit c6e22ca
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
30 changes: 26 additions & 4 deletions www/common/drive-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -4525,6 +4525,14 @@ define([
var type = $contextMenu.attr('data-menu-type');
var $this = $(this);

var prefix = /cp\-app\-drive\-context\-/;
var command = Util.slice(this.classList)
.map(c => {
if (!prefix.test(c)) { return; }
return c.replace(prefix, '');
}).filter(Boolean);
console.log(command);

var el, data;
if (paths.length === 0) {
log(Messages.fm_forbidden);
Expand Down Expand Up @@ -4784,9 +4792,13 @@ define([
common: common
};
if (padType === 'file') {
return void Share.getFileShareModal(common, padData);
return void Share.getFileShareModal(common, padData, function (err) {
if (err) { UI.warn(Messages.error); }
});
}
Share.getShareModal(common, padData);
Share.getShareModal(common, padData, function (err) {
if (err) { UI.warn(Messages.error); }
});
}
}
else if ($this.hasClass('cp-app-drive-context-savelocal')) {
Expand Down Expand Up @@ -4875,7 +4887,10 @@ define([
el = manager.find(paths[0].path.slice(1), APP.newSharedFolder);
}
APP.getProperties(el, function (e) {
if (e) { return void logError(e); }
if (e) {
UI.warn(Messages.error);
return void logError(e, el);
}
});
}
else if ($this.hasClass("cp-app-drive-context-access")) {
Expand All @@ -4886,7 +4901,10 @@ define([
el = manager.find(paths[0].path.slice(1), APP.newSharedFolder);
}
APP.getAccess(el, function (e) {
if (e) { return void logError(e); }
if (e) {
UI.warn(Messages.error);
return void logError(e);
}
});
}
else if ($this.hasClass("cp-app-drive-context-hashtag")) {
Expand Down Expand Up @@ -5130,14 +5148,17 @@ define([
if (!obj || typeof(obj) !== "object" || Object.keys(obj).length === 0) {
return;
}
manager.setHistoryMode(true);
copyObjectValue(folders[history.sfId], obj);
refresh();
return;
}

history.sfId = false;

var ok = manager.isValidDrive(obj.drive);
if (!ok) { return; }
manager.setHistoryMode(true);

var restricted = files.restrictedFolders;
copyObjectValue(files, obj.drive);
Expand All @@ -5147,6 +5168,7 @@ define([
refresh();
};
history.onLeaveHistory = function () {
manager.setHistoryMode(false);
copyObjectValue(files, proxy.drive);
refresh();
};
Expand Down
13 changes: 13 additions & 0 deletions www/common/inner/common-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ define([
data.allowed = obj.allowed;
data.rejected = obj.rejected;
};
// trying to get data from server
// should be authoritative, so override whatever you have in memory
Modal.loadMetadata = function (Env, data, waitFor, redraw) {
Env.common.getPadMetadata({
channel: data.channel
Expand All @@ -35,6 +37,7 @@ define([
nThen(function (waitFor) {
var priv = common.getMetadataMgr().getPrivateData();
var base = priv.origin;
// this fetches attributes from your shared worker's memory
common.getPadAttribute('', waitFor(function (err, val) {
if (err || !val) {
if (opts.access) {
Expand All @@ -50,6 +53,14 @@ define([
}
return;
}
// we delete owners because this query to the worker
// is concurrent with the call to the server.
// we shouldn't trust local information about ownership or expiration
// over that provided by the server, so we simply ignore the local version.
// this could be made more correct at the expense of some latency by not
// running the two queries concurrently, but we consider responsiveness
// more of a priority I guess. Maybe reconsider that if you find
// that this causes any bugs.
if (!val.fileType) {
delete val.owners;
delete val.expire;
Expand All @@ -59,8 +70,10 @@ define([
if (data.roHref) { data.roHref = base + data.roHref; }
}), opts.href);

if (opts.channel) { data.channel = opts.channel; }
// If this is a file, don't try to look for metadata
if (opts.channel && opts.channel.length > 32) { return; }
// this fetches data from the server
Modal.loadMetadata(Env, data, waitFor);
}).nThen(function () {
if (opts.channel) { data.channel = opts.channel; }
Expand Down
2 changes: 1 addition & 1 deletion www/common/inner/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ define([
opts.access = true; // Allow the use of the modal even if the pad is not stored

var hashes = opts.hashes;
if (!hashes || (!hashes.editHash && !hashes.viewHash && !opts.static)) { return; }
if (!hashes || (!hashes.editHash && !hashes.viewHash && !opts.static)) { return cb("NO_HASHES"); }

var teams = getEditableTeams(common, opts);
opts.teams = teams;
Expand Down
12 changes: 10 additions & 2 deletions www/common/proxy-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,10 @@ define([
};

var getSharedFolderData = function (Env, id) {
if (!Env.folders[id]) { return {}; }
var proxy = Env.folders[id].proxy;
var inHistory;
if (Env.isHistoryMode && !Env.folders[id]) { inHistory = true; }
else if (!Env.folders[id]) { return {}; }
var proxy = inHistory? {}: Env.folders[id].proxy;

// Clean deprecated values
if (Object.keys(proxy.metadata || {}).length > 1) {
Expand Down Expand Up @@ -522,6 +524,7 @@ define([
href: '/drive/#' + hashes.editHash,
roHref: '/drive/#' + hashes.viewHash,
channel: secret.channel,
lastTitle: data.name,
ctime: +new Date(),
};
if (data.password) { folderData.password = data.password; }
Expand Down Expand Up @@ -1562,6 +1565,10 @@ define([
return Env.user.userObject.getOwnedPads(Env.edPublic);
};

var setHistoryMode = function (Env, flag) {
Env.isHistoryMode = Boolean(flag);
};

var getFolderData = function (Env, path) {
var resolved = _resolvePath(Env, path);
if (!resolved || !resolved.userObject) { return {}; }
Expand Down Expand Up @@ -1657,6 +1664,7 @@ define([
// Manager
addProxy: callWithEnv(addProxy),
removeProxy: callWithEnv(removeProxy),
setHistoryMode: callWithEnv(setHistoryMode),
// Drive RPC commands
rename: callWithEnv(renameInner),
move: callWithEnv(moveInner),
Expand Down

0 comments on commit c6e22ca

Please sign in to comment.