Add trim history RPC command
This commit is contained in:
parent
6db7fbac0f
commit
e6709f03aa
@ -739,6 +739,7 @@ define([
|
|||||||
if (data.rtChannel) { chan.push(data.rtChannel); }
|
if (data.rtChannel) { chan.push(data.rtChannel); }
|
||||||
if (data.lastVersion) { chan.push(Hash.hrefToHexChannelId(data.lastVersion)); }
|
if (data.lastVersion) { chan.push(Hash.hrefToHexChannelId(data.lastVersion)); }
|
||||||
var history = common.makeUniversal('history');
|
var history = common.makeUniversal('history');
|
||||||
|
var trimChannels = [];
|
||||||
NThen(function (waitFor) {
|
NThen(function (waitFor) {
|
||||||
chan.forEach(function (c) {
|
chan.forEach(function (c) {
|
||||||
common.getFileSize(c, waitFor(function (e, _bytes) {
|
common.getFileSize(c, waitFor(function (e, _bytes) {
|
||||||
@ -758,6 +759,7 @@ define([
|
|||||||
}, waitFor(function (obj) {
|
}, waitFor(function (obj) {
|
||||||
if (obj && obj.error) { return; }
|
if (obj && obj.error) { return; }
|
||||||
historyBytes = obj.size;
|
historyBytes = obj.size;
|
||||||
|
trimChannels = obj.channels;
|
||||||
}));
|
}));
|
||||||
}).nThen(function () {
|
}).nThen(function () {
|
||||||
if (bytes === 0) { return void cb(void 0, $d); }
|
if (bytes === 0) { return void cb(void 0, $d); }
|
||||||
@ -806,7 +808,7 @@ define([
|
|||||||
spinner.spin();
|
spinner.spin();
|
||||||
history.execCommand('TRIM_HISTORY', {
|
history.execCommand('TRIM_HISTORY', {
|
||||||
pad: true,
|
pad: true,
|
||||||
channels: chan.filter(function (c) { return c.length === 32; }),
|
channels: trimChannels,
|
||||||
teamId: typeof(owned) === "number" && owned
|
teamId: typeof(owned) === "number" && owned
|
||||||
}, function (obj) {
|
}, function (obj) {
|
||||||
if (obj && obj.error) {
|
if (obj && obj.error) {
|
||||||
@ -814,7 +816,6 @@ define([
|
|||||||
// XXX what are the possible errors?
|
// XXX what are the possible errors?
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO: obj.warning?
|
|
||||||
spinner.hide();
|
spinner.hide();
|
||||||
$(size).append(h('div.alert.alert-success', Messages.trimHistory_success || 'ok')); // XXX
|
$(size).append(h('div.alert.alert-success', Messages.trimHistory_success || 'ok')); // XXX
|
||||||
});
|
});
|
||||||
|
|||||||
@ -163,13 +163,14 @@ define([
|
|||||||
size += obj.size;
|
size += obj.size;
|
||||||
res.push({
|
res.push({
|
||||||
channel: channel,
|
channel: channel,
|
||||||
lastKnownHash: obj.hash
|
hash: obj.hash
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
}).nThen(function () {
|
}).nThen(function () {
|
||||||
cb({
|
cb({
|
||||||
warning: warning.length ? warning : undefined,
|
warning: warning.length ? warning : undefined,
|
||||||
|
channels: res,
|
||||||
size: size
|
size: size
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -185,24 +186,14 @@ define([
|
|||||||
|
|
||||||
var warning = [];
|
var warning = [];
|
||||||
|
|
||||||
// If account trim history, get the correct channels here
|
|
||||||
if (data.account) {
|
|
||||||
channels = getAccountChannels(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
channels.forEach(function (chan) {
|
channels.forEach(function (obj) {
|
||||||
chan = chan; // XXX
|
rpc.trimHistory(obj, waitFor(function (err) {
|
||||||
waitFor = waitFor; // XXX
|
|
||||||
/*
|
|
||||||
rpc.trimHistory(chan, waitFor(function (err) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
chanWarning = true;
|
|
||||||
warning.push(err);
|
warning.push(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
*/ // XXX TODO
|
|
||||||
});
|
});
|
||||||
}).nThen(function () {
|
}).nThen(function () {
|
||||||
// Only one channel and warning: error
|
// Only one channel and warning: error
|
||||||
|
|||||||
@ -125,6 +125,17 @@ var factory = function (Util, Rpc) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exp.trimHistory = function (data, _cb) {
|
||||||
|
var cb = Util.once(Util.mkAsync(_cb));
|
||||||
|
if (typeof(data) !== 'object' || !data.channel || !data.hash) {
|
||||||
|
return void cb('INVALID_ARGUMENTS');
|
||||||
|
}
|
||||||
|
rpc.send('TRIM_HISTORY', data, function (e) {
|
||||||
|
if (e) { return cb(e); }
|
||||||
|
cb();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
exp.clearOwnedChannel = function (channel, cb) {
|
exp.clearOwnedChannel = function (channel, cb) {
|
||||||
if (typeof(channel) !== 'string' || channel.length !== 32) {
|
if (typeof(channel) !== 'string' || channel.length !== 32) {
|
||||||
return void cb('INVALID_ARGUMENTS');
|
return void cb('INVALID_ARGUMENTS');
|
||||||
|
|||||||
@ -1221,6 +1221,7 @@ define([
|
|||||||
|
|
||||||
var $button = $(button);
|
var $button = $(button);
|
||||||
var size;
|
var size;
|
||||||
|
var channels = [];
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
APP.history.execCommand('GET_HISTORY_SIZE', {
|
APP.history.execCommand('GET_HISTORY_SIZE', {
|
||||||
account: true,
|
account: true,
|
||||||
@ -1230,9 +1231,9 @@ define([
|
|||||||
waitFor.abort();
|
waitFor.abort();
|
||||||
var error = h('div.alert.alert-danger', Messages.trimHistory_error || 'error'); // XXX
|
var error = h('div.alert.alert-danger', Messages.trimHistory_error || 'error'); // XXX
|
||||||
$(content).empty().append(error);
|
$(content).empty().append(error);
|
||||||
// TODO: obj.warning?
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
channels = obj.channels;
|
||||||
size = UIElements.prettySize(Number(obj.size));
|
size = UIElements.prettySize(Number(obj.size));
|
||||||
}));
|
}));
|
||||||
}).nThen(function () {
|
}).nThen(function () {
|
||||||
@ -1247,14 +1248,12 @@ define([
|
|||||||
$button.remove();
|
$button.remove();
|
||||||
spinner.spin();
|
spinner.spin();
|
||||||
APP.history.execCommand('TRIM_HISTORY', {
|
APP.history.execCommand('TRIM_HISTORY', {
|
||||||
account: true,
|
channels: channels
|
||||||
channels: []
|
|
||||||
}, function (obj) {
|
}, function (obj) {
|
||||||
if (obj && obj.error) {
|
if (obj && obj.error) {
|
||||||
// XXX what are the possible errors?
|
// XXX what are the possible errors?
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO: obj.warning?
|
|
||||||
spinner.hide();
|
spinner.hide();
|
||||||
$(content).append(h('div.alert.alert-success', Messages.trimHistory_success || 'ok')); // XXX
|
$(content).append(h('div.alert.alert-success', Messages.trimHistory_success || 'ok')); // XXX
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user