aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-04-08 20:12:10 -0700
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-04-08 20:21:05 -0700
commit58afd831a3e73f364e0418942b2553fa1fc2f098 (patch)
treead8bbf1ce8e2e0d07b9a28d9c5e61feb6bf1b94c /lib
parent57c80659bb02d029c077c0658b1353cfcbe41e30 (diff)
downloadpatchfoo-58afd831a3e73f364e0418942b2553fa1fc2f098.tar.gz
patchfoo-58afd831a3e73f364e0418942b2553fa1fc2f098.zip
Add new
Diffstat (limited to 'lib')
-rw-r--r--lib/serve.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/serve.js b/lib/serve.js
index d0e2e26..30c1239 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -208,6 +208,7 @@ Serve.prototype.path = function (url) {
}
m = /^([^.]*)(?:\.(.*))?$/.exec(url)
switch (m[1]) {
+ case '/new': return this.new(m[2])
case '/public': return this.public(m[2])
case '/private': return this.private(m[2])
case '/search': return this.search(m[2])
@@ -256,6 +257,46 @@ Serve.prototype.public = function (ext) {
)
}
+Serve.prototype.new = function (ext) {
+ var self = this
+ var q = self.query
+ var opts = {
+ gt: Number(q.gt) || Date.now(),
+ }
+
+ var read = self.app.createLogStream(opts)
+ self.req.on('closed', function () {
+ console.error('closing')
+ read(true, function (err) {
+ console.log('closed')
+ if (err && err !== true) console.error(new Error(err.stack))
+ })
+ })
+ pull.collect(function (err, msgs) {
+ if (err) return pull(
+ pull.once(u.renderError(err, ext).outerHTML),
+ self.wrapPage('peers'),
+ self.respondSink(500, {'Content-Type': ctype(ext)})
+ )
+ sort(msgs)
+ var maxTS = msgs.reduce(function (max, msg) {
+ return Math.max(msg.timestamp, max)
+ }, -Infinity)
+ pull(
+ pull.values(msgs),
+ self.renderThread(opts, null, q),
+ self.wrapNew({
+ gt: isFinite(maxTS) ? maxTS : opts.gt
+ }),
+ self.wrapMessages(),
+ self.wrapPage('new'),
+ self.respondSink(200, {
+ 'Content-Type': ctype(ext)
+ })
+ )
+ })(read)
+}
+
Serve.prototype.private = function (ext) {
var q = this.query
var opts = {
@@ -736,6 +777,7 @@ Serve.prototype.wrapPage = function (title, searchQ) {
),
h('body',
h('nav.nav-bar', h('form', {action: render.toUrl('/search'), method: 'get'},
+ h('a', {href: render.toUrl('/new?gt=' + Date.now())}, 'new') , ' ',
h('a', {href: render.toUrl('/public')}, 'public'), ' ',
h('a', {href: render.toUrl('/private')}, 'private') , ' ',
h('a', {href: render.toUrl('/peers')}, 'peers') , ' ',
@@ -836,6 +878,21 @@ Serve.prototype.wrapThread = function (opts) {
})
}
+Serve.prototype.wrapNew = function (opts) {
+ return function (read) {
+ return cat([
+ read,
+ pull.once(
+ h('tr', h('td.paginate', {colspan: 3},
+ h('a', {href: '?' + qs.stringify({
+ gt: opts.gt
+ })}, '↓ catchup')
+ )).outerHTML
+ )
+ ])
+ }
+}
+
Serve.prototype.wrapChannel = function (channel) {
var self = this
return u.hyperwrap(function (thread, cb) {