From 0373df4b547ca9bc2d07dab0c4d7720ee4cce69e Mon Sep 17 00:00:00 2001 From: cel Date: Thu, 27 Apr 2017 11:17:24 -1000 Subject: Add catchup links to messages in live view --- lib/render-msg.js | 52 ++++++++++++++++++++++++++++++---------------------- lib/render.js | 8 ++++---- lib/serve.js | 17 ++++++++++++++--- 3 files changed, 48 insertions(+), 29 deletions(-) diff --git a/lib/render-msg.js b/lib/render-msg.js index b91659a..f2812c7 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -14,8 +14,10 @@ function RenderMsg(render, app, msg, opts) { var content = this.value.content this.c = content || {} this.isMissing = !content - var opts = opts || {} - this.shouldWrap = opts.wrap !== false + + if (typeof opts === 'boolean') opts = {raw: opts} + this.opts = opts || {} + this.shouldWrap = this.opts.wrap !== false } RenderMsg.prototype.toUrl = function (href) { @@ -109,14 +111,7 @@ RenderMsg.prototype.wrap = function (content, cb) { h('code', h('a.ssb-id', {href: this.toUrl(this.msg.key)}, this.msg.key)), channel ? [' ', h('a', {href: this.toUrl(channel)}, channel)] : '')), - h('td.msg-right', this.msg.key ? - h('form', {method: 'post', action: ''}, - this.msg.rel ? [this.msg.rel, ' '] : '', - h('a', {href: this.toUrl(this.msg.key) + '?raw'}, 'raw'), ' ', - this.voteFormInner('dig') - ) : [ - this.msg.rel ? [this.msg.rel, ' '] : '' - ]) + h('td.msg-right', this.actions()) ), h('tr', h('td.msg-content', {colspan: 2}, this.issues(done()), @@ -143,18 +138,30 @@ RenderMsg.prototype.wrapMini = function (content, cb) { }, htime(date)), ' ', this.issues(done()), content), - h('td.msg-right', this.msg.key ? - h('form', {method: 'post', action: ''}, - this.msg.rel ? [this.msg.rel, ' '] : '', - h('a', {href: this.toUrl(this.msg.key) + '?raw'}, 'raw'), ' ', - this.voteFormInner('dig') - ) : [ - this.msg.rel ? [this.msg.rel, ' '] : '' - ]) + h('td.msg-right', this.actions()) )) done(cb) } +RenderMsg.prototype.actions = function () { + return this.msg.key ? + h('form', {method: 'post', action: ''}, + this.msg.rel ? [this.msg.rel, ' '] : '', + this.opts.withGt && this.msg.timestamp ? [ + h('a', {href: '?gt=' + this.msg.timestamp}, '↓'), ' '] : '', + h('a', {href: this.toUrl(this.msg.key) + '?raw'}, 'raw'), ' ', + this.voteFormInner('dig') + ) : [ + this.msg.rel ? [this.msg.rel, ' '] : '' + ] +} + +RenderMsg.prototype.sync = function (cb) { + cb(null, h('tr.msg-row', h('td', {colspan: 3}, + h('hr') + ))) +} + RenderMsg.prototype.recpsLine = function (cb) { if (!this.value.private) return cb(), '' var author = this.value.author @@ -182,8 +189,9 @@ RenderMsg.prototype.voteFormInner = function (expression) { h('input', {type: 'submit', name: 'expression', value: expression})] } -RenderMsg.prototype.message = function (raw, cb) { - if (raw) return this.raw(cb) +RenderMsg.prototype.message = function (cb) { + if (this.opts.raw) return this.raw(cb) + if (this.msg.sync) return this.sync(cb) if (typeof this.c === 'string') return this.encrypted(cb) if (this.isMissing) return this.missing(cb) switch (this.c.type) { @@ -313,7 +321,7 @@ RenderMsg.prototype.title = function (cb) { if (err) return cb(err) var name = about.name || about.title || about.description if (name) return cb(null, name) - self.message(false, function (err, el) { + self.message(function (err, el) { if (err) return cb(err) cb(null, '%' + title(h('div', el).textContent)) }) @@ -613,7 +621,7 @@ RenderMsg.prototype.repost = function (cb) { function gotMsg(err, msg) { if (err) return cb(err) var renderMsg = new RenderMsg(self.render, self.app, msg, {wrap: false}) - renderMsg.message(false, function (err, msgEl) { + renderMsg.message(function (err, msgEl) { self.wrapMini(['reposted ', h('code.ssb-id', h('a', {href: self.render.toUrl(id)}, id)), diff --git a/lib/render.js b/lib/render.js index 7890c1f..cca56f0 100644 --- a/lib/render.js +++ b/lib/render.js @@ -224,13 +224,13 @@ Render.prototype.msgLink = function (msg, cb) { return a } -Render.prototype.renderMsg = function (msg, raw, cb) { - new RenderMsg(this, this.app, msg).message(raw, cb) +Render.prototype.renderMsg = function (msg, opts, cb) { + new RenderMsg(this, this.app, msg, opts).message(cb) } -Render.prototype.renderFeeds = function (raw) { +Render.prototype.renderFeeds = function (opts) { var self = this return paramap(function (msg, cb) { - self.renderMsg(msg, raw, cb) + self.renderMsg(msg, opts, cb) }, 4) } diff --git a/lib/serve.js b/lib/serve.js index a377c04..9e1cbb5 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -382,11 +382,22 @@ Serve.prototype.search = function (ext) { Serve.prototype.live = function (ext) { var self = this + var q = self.query + var opts = { + live: true, + } + var gt = Number(q.gt) + if (gt) opts.gt = gt + else opts.old = false pull( - self.app.sbot.createLogStream({old: false}), - self.renderThread(), - self.wrapMessages(), + ph('table', {class: 'ssb-msgs'}, pull( + self.app.sbot.createLogStream(opts), + self.app.render.renderFeeds({ + withGt: true, + }), + pull.map(u.toHTML) + )), self.wrapPage('live'), self.respondSink(200, { 'Content-Type': ctype(ext), -- cgit v1.2.3