From d6d54412877e4a7c226c13423c46ca12048004b6 Mon Sep 17 00:00:00 2001 From: cel Date: Wed, 1 Feb 2017 11:58:16 -0800 Subject: Add messagesByType view --- lib/serve.js | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/lib/serve.js b/lib/serve.js index 507fe72..0dd403a 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -123,6 +123,7 @@ Serve.prototype.path = function (url) { } m = /^(\/?[^\/]*)(\/.*)?$/.exec(url) switch (m[1]) { + case '/type': return this.type(m[2]) case '/static': return this.static(m[2]) case '/emoji': return this.emoji(m[2]) } @@ -212,6 +213,29 @@ Serve.prototype.search = function (ext) { ) } +Serve.prototype.type = function (path) { + var q = this.query + var type = path.substr(1) + var opts = { + reverse: !q.forwards, + lt: Number(q.lt) || Date.now(), + gt: Number(q.gt) || -Infinity, + limit: Number(q.limit) || 12, + type: type, + } + + pull( + this.app.sbot.messagesByType(opts), + this.renderThreadPaginated(opts, null, q), + this.wrapMessages(), + this.wrapType(type), + this.wrapPage('type: ' + type), + this.respondSink(200, { + 'Content-Type': ctype('html') + }) + ) +} + Serve.prototype.vote = function (ext) { var self = this @@ -457,7 +481,7 @@ Serve.prototype.renderThreadPaginated = function (opts, feedId, q) { return pull( paginate( function onFirst(msg, cb) { - var num = feedId ? msg.value.sequence : msg.timestamp + var num = feedId ? msg.value.sequence : msg.timestamp || msg.ts if (q.forwards) { link({ lt: num, @@ -474,7 +498,7 @@ Serve.prototype.renderThreadPaginated = function (opts, feedId, q) { }, this.app.render.renderFeeds(), function onLast(msg, cb) { - var num = feedId ? msg.value.sequence : msg.timestamp + var num = feedId ? msg.value.sequence : msg.timestamp || msg.ts if (q.forwards) { link({ lt: null, @@ -672,6 +696,20 @@ Serve.prototype.wrapChannel = function (channel) { }) } +Serve.prototype.wrapType = function (type) { + var self = this + return u.hyperwrap(function (thread, cb) { + cb(null, [ + h('section', + h('h3.feed-name', + h('a', {href: self.app.render.toUrl('/type/' + type)}, + h('code', type), 's')) + ), + thread + ]) + }) +} + function rows(str) { return String(str).split(/[^\n]{70}|\n/).length } -- cgit v1.2.3