aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-02-01 11:58:16 -0800
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-02-04 02:53:52 -0800
commitd6d54412877e4a7c226c13423c46ca12048004b6 (patch)
treeac90edbb9253939dc5a951740f29b08d60eb2996 /lib
parent60be78331201630b434d0e542b30366224c4e09a (diff)
downloadpatchfoo-d6d54412877e4a7c226c13423c46ca12048004b6.tar.gz
patchfoo-d6d54412877e4a7c226c13423c46ca12048004b6.zip
Add messagesByType view
Diffstat (limited to 'lib')
-rw-r--r--lib/serve.js42
1 files 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
}