diff options
Diffstat (limited to 'lib/render-msg.js')
-rw-r--r-- | lib/render-msg.js | 52 |
1 files changed, 30 insertions, 22 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)), |