mirror of https://github.com/xwiki-labs/cryptpad
Trim history prompt
This commit is contained in:
parent
59f427f1b5
commit
7bbb46c2ef
|
@ -2684,6 +2684,45 @@ define([
|
|||
|
||||
};
|
||||
|
||||
Messages.history_trimPrompt = "This document's history is very large ({0}) and it may impact the loading time. You can delete the unnecessary history.";
|
||||
UIElements.displayTrimHistoryPrompt = function (common, data) {
|
||||
var mb = Util.bytesToMegabytes(data.size);
|
||||
var text = Messages._getKey('history_trimPrompt', [
|
||||
Messages._getKey('formattedMB', [mb])
|
||||
]);
|
||||
var yes = h('button.cp-corner-primary', [
|
||||
h('span.fa.fa-trash-o'),
|
||||
Messages.trimHistory_button
|
||||
]);
|
||||
var no = h('button.cp-corner-cancel', Messages.crowdfunding_popup_no); // Not now
|
||||
var actions = h('div', [no, yes]);
|
||||
|
||||
var dontShowAgain = function () {
|
||||
var until = (+new Date()) + (7 * 24 * 3600 * 1000); // 7 days from now
|
||||
until = (+new Date()) + 30000; // XXX 30s from now
|
||||
if (data.drive) {
|
||||
common.setAttribute(['drive', 'trim'], until);
|
||||
return;
|
||||
}
|
||||
common.setPadAttribute('trim', until);
|
||||
};
|
||||
|
||||
var modal = UI.cornerPopup(text, actions, '', {});
|
||||
|
||||
$(yes).click(function () {
|
||||
modal.delete();
|
||||
if (data.drive) {
|
||||
common.openURL('/settings/#drive');
|
||||
return;
|
||||
}
|
||||
common.getSframeChannel().event('EV_PROPERTIES_OPEN');
|
||||
});
|
||||
$(no).click(function () {
|
||||
dontShowAgain();
|
||||
modal.delete();
|
||||
});
|
||||
};
|
||||
|
||||
UIElements.displayFriendRequestModal = function (common, data) {
|
||||
var msg = data.content.msg;
|
||||
var userData = msg.content.user;
|
||||
|
|
|
@ -1310,6 +1310,16 @@ define([
|
|||
if (APP.migrate && !readOnly) {
|
||||
onMigrateRdy.fire();
|
||||
}
|
||||
|
||||
// Check if history can/should be trimmed
|
||||
var cp = getLastCp();
|
||||
if (cp && cp.file && cp.hash) {
|
||||
var channels = [{
|
||||
channel: content.channel,
|
||||
lastKnownHash: cp.hash
|
||||
}];
|
||||
common.checkTrimHistory(channels);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -551,6 +551,8 @@ define([
|
|||
Thumb.initPadThumbnails(common, options.thumbnail);
|
||||
}
|
||||
}
|
||||
|
||||
common.checkTrimHistory();
|
||||
});
|
||||
};
|
||||
var onConnectionChange = function (info) {
|
||||
|
|
|
@ -264,6 +264,66 @@ define([
|
|||
return teamChatChannel;
|
||||
};
|
||||
|
||||
// When opening a pad, if were an owner check the history size and prompt for trimming if
|
||||
// necessary
|
||||
funcs.checkTrimHistory = function (channels, isDrive) {
|
||||
channels = channels || [];
|
||||
var priv = ctx.metadataMgr.getPrivateData();
|
||||
|
||||
var limit = 100 * 1024 * 1024; // 100MB
|
||||
limit = 100 * 1024; // XXX 100KB
|
||||
|
||||
var owned;
|
||||
nThen(function (w) {
|
||||
if (isDrive) {
|
||||
funcs.getAttribute(['drive', 'trim'], w(function (err, val) {
|
||||
if (err || typeof(val) !== "number") { return; }
|
||||
if (val < (+new Date())) { return; }
|
||||
w.abort();
|
||||
}));
|
||||
return;
|
||||
}
|
||||
funcs.getPadAttribute('trim', w(function (err, val) {
|
||||
if (err || typeof(val) !== "number") { return; }
|
||||
if (val < (+new Date())) { return; }
|
||||
w.abort();
|
||||
}));
|
||||
}).nThen(function (w) {
|
||||
// Check ownership
|
||||
// DRIVE
|
||||
if (isDrive) {
|
||||
if (!priv.isDriveOwned) { return void w.abort(); }
|
||||
return;
|
||||
}
|
||||
// PAD
|
||||
channels.push({ channel: priv.channel });
|
||||
funcs.getPadMetadata({
|
||||
channel: priv.channel
|
||||
}, w(function (md) {
|
||||
if (md && md.error) { return void w.abort(); }
|
||||
var owners = md.owners;
|
||||
owned = funcs.isOwned(owners);
|
||||
if (!owned) { return void w.abort(); }
|
||||
}));
|
||||
}).nThen(function () {
|
||||
// We're an owner: check the history size
|
||||
var history = funcs.makeUniversal('history');
|
||||
history.execCommand('GET_HISTORY_SIZE', {
|
||||
account: isDrive,
|
||||
pad: !isDrive,
|
||||
channels: channels,
|
||||
teamId: typeof(owned) === "number" && owned
|
||||
}, function (obj) {
|
||||
if (obj && obj.error) { return; } // can't get history size: abort
|
||||
var bytes = obj.size;
|
||||
if (!bytes || typeof(bytes) !== "number") { return; } // no history: abort
|
||||
if (bytes < limit) { return; }
|
||||
obj.drive = isDrive;
|
||||
UIElements.displayTrimHistoryPrompt(funcs, obj);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var cursorChannel;
|
||||
// common-ui-elements needs to be able to get the cursor channel to put it in metadata when
|
||||
// importing a template
|
||||
|
|
|
@ -310,6 +310,10 @@ define([
|
|||
onReconnect();
|
||||
});
|
||||
common.onLogout(function () { setEditable(false); });
|
||||
|
||||
// Check if our drive history needs to be trimmed
|
||||
common.checkTrimHistory(null, true);
|
||||
|
||||
});
|
||||
};
|
||||
main();
|
||||
|
|
|
@ -1087,6 +1087,8 @@ define([
|
|||
common.openPadChat(function () {});
|
||||
|
||||
UI.removeLoadingScreen();
|
||||
|
||||
common.checkTrimHistory();
|
||||
};
|
||||
|
||||
var onError = function (info) {
|
||||
|
|
Loading…
Reference in New Issue