From f76defc54c292f33838caf35eca329793ff7d733 Mon Sep 17 00:00:00 2001 From: cel Date: Thu, 22 Aug 2019 18:57:57 -0700 Subject: Implement limit for /new Fix %CtcZaNNWEWFwdCOZL343mxFXUvqV5BPVMv+CM8ELOCo=.sha256 --- lib/serve.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib') diff --git a/lib/serve.js b/lib/serve.js index 34861bc..1206b36 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -75,6 +75,8 @@ Serve.prototype.go = function () { this.res.setTimeout(0) var conf = self.app.config.patchfoo || {} + this.conf = conf + var authtok = conf.auth || null if (authtok) { var auth = this.req.headers['authorization'] @@ -524,8 +526,10 @@ Serve.prototype.new = function (ext) { var self = this var q = self.query var latest = (/latest=([^;]*)/.exec(self.req.headers.cookie) || [])[1] + var limit = Number(q.limit || self.conf.newLimit || 500) var opts = { gt: Number(q.gt) || Number(latest) || Date.now(), + limit: limit } if (q.catchup) self.setCookie('latest', opts.gt, {'Max-Age': 86400000}) @@ -552,6 +556,7 @@ Serve.prototype.new = function (ext) { pull.values(msgs), self.renderThread(), self.wrapNew({ + reachedLimit: msgs.length === limit && limit, gt: isFinite(maxTS) ? maxTS : Date.now() }), self.wrapMessages(), @@ -3415,10 +3420,14 @@ Serve.prototype.wrapNew = function (opts) { cb(null, [ composer, h('table.ssb-msgs', + opts.reachedLimit ? h('tr', h('td.paginate.msg-left', {colspan: 3}, + 'Reached limit of ' + opts.reachedLimit + ' messages' + )) : '', thread, h('tr', h('td.paginate.msg-left', {colspan: 3}, h('form', {method: 'get', action: ''}, h('input', {type: 'hidden', name: 'gt', value: opts.gt}), + self.query.limit ? h('input', {type: 'hidden', name: 'limit', value: self.query.limit}) : '', h('input', {type: 'hidden', name: 'catchup', value: '1'}), h('input', {type: 'submit', value: 'catchup'}) ) -- cgit v1.2.3