From 6d54ac255cb2f96433e88d9c2482074749bd4eea Mon Sep 17 00:00:00 2001 From: cel Date: Tue, 17 Oct 2017 12:31:56 -1000 Subject: Fix handling limit --- lib/app.js | 2 +- lib/render.js | 11 ++++++++--- lib/serve.js | 16 +++++++++------- 3 files changed, 18 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/app.js b/lib/app.js index b5140e1..3374f41 100644 --- a/lib/app.js +++ b/lib/app.js @@ -355,7 +355,7 @@ App.prototype.createLogStream = function (opts) { App.prototype.createFeedStream = function (opts) { // work around opts.gt being treated as opts.gte sometimes var limit = Number(opts.limit) - if (opts.gt && opts.limit && !opts.reverse) return pull( + if (opts.gt && limit && !opts.reverse) return pull( this.sbot.createFeedStream(u.mergeOpts(opts, {limit: opts.limit + 1})), pull.filter(function (msg) { return msg && msg.value.timestamp !== opts.gt diff --git a/lib/render.js b/lib/render.js index a86bd92..c43ee76 100644 --- a/lib/render.js +++ b/lib/render.js @@ -314,9 +314,14 @@ Render.prototype.renderMsg = function (msg, opts, cb) { Render.prototype.renderFeeds = function (opts) { var self = this - return paramap(function (msg, cb) { - self.renderMsg(msg, opts, cb) - }, 4) + var limit = Number(opts.limit) + return pull( + paramap(function (msg, cb) { + self.renderMsg(msg, opts, cb) + }, 4), + pull.filter(Boolean), + limit && pull.take(limit) + ) } Render.prototype.gitCommitBody = function (body) { diff --git a/lib/serve.js b/lib/serve.js index 56fddef..2bbc80d 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -351,7 +351,6 @@ Serve.prototype.public = function (ext) { this.app.createLogStream(opts), this.renderThreadPaginated(opts, null, q), this.wrapMessages(), - pull.take(Number(q.limit) || 12), this.wrapPublic(), this.wrapPage('public'), this.respondSink(200, { @@ -422,7 +421,6 @@ Serve.prototype.private = function (ext) { pull( this.app.streamPrivate(opts), - pull.take(Number(q.limit) || 12), this.renderThreadPaginated(opts, null, q), this.wrapMessages(), this.wrapPrivate(opts), @@ -449,7 +447,6 @@ Serve.prototype.mentions = function (ext) { ph('h3', 'Mentions'), pull( self.app.streamMentions(opts), - pull.take(Number(q.limit) || 12), self.app.unboxMessages(), self.renderThreadPaginated(opts, null, q), self.wrapMessages() @@ -917,7 +914,6 @@ Serve.prototype.type = function (path) { pull( this.app.sbot.messagesByType(opts), - pull.take(Number(q.limit) || 12), this.renderThreadPaginated(opts, null, q), this.wrapMessages(), this.wrapType(type), @@ -983,7 +979,6 @@ Serve.prototype.channel = function (path) { pull( this.app.streamChannel(opts), - pull.take(Number(q.limit) || 12), this.renderThreadPaginated(opts, null, q), this.wrapMessages(), this.wrapChannel(channel), @@ -1065,7 +1060,6 @@ Serve.prototype.userFeed = function (id, path) { if (err) self.app.error(err) pull( self.app.sbot.createUserStream(opts), - pull.take(Number(q.limit) || 20), self.renderThreadPaginated(opts, id, q), self.wrapMessages(), self.wrapUserFeed(isScrolled, id), @@ -1242,6 +1236,7 @@ Serve.prototype.renderThread = function (opts) { feed: opts && opts.feed, msgId: opts && opts.msgId, filter: this.query.filter, + limit: Number(this.query.limit) || 12, }), pull.map(u.toHTML) ) @@ -1285,7 +1280,14 @@ Serve.prototype.renderThreadPaginated = function (opts, feedId, q) { })) } }, - this.app.render.renderFeeds(opts), + this.app.render.renderFeeds({ + raw: false, + full: this.query.full != null, + feed: opts && opts.feed, + msgId: opts && opts.msgId, + filter: this.query.filter, + limit: Number(this.query.limit) || 12, + }), function onLast(msg, cb) { var num = feedId ? msg.value.sequence : opts.sortByTimestamp ? msg.value.timestamp : -- cgit v1.2.3