aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
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) {