From 5b3dc4bf49f367de33fcd4e6e21281ffec91b6a7 Mon Sep 17 00:00:00 2001 From: cel Date: Wed, 1 Feb 2017 10:36:08 -0800 Subject: Render ferment message types --- lib/render-msg.js | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- lib/render.js | 4 +++ static/styles.css | 5 +++- 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/lib/render-msg.js b/lib/render-msg.js index 5d16544..c6c6f35 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -112,6 +112,8 @@ RenderMsg.prototype.message = function (raw, cb) { if (typeof this.c === 'string') return this.encrypted(cb) switch (this.c.type) { case 'post': return this.post(cb) + case 'ferment/like': + case 'robeson/like': case 'vote': return this.vote(cb) case 'about': return this.about(cb) case 'contact': return this.contact(cb) @@ -121,6 +123,15 @@ RenderMsg.prototype.message = function (raw, cb) { case 'git-update': return this.gitUpdate(cb) case 'pull-request': return this.gitPullRequest(cb) case 'issue': return this.issue(cb) + case 'ferment/audio': + case 'robeson/audio': + return this.audio(cb) + case 'ferment/repost': + case 'robeson/repost': + return this.repost(cb) + case 'ferment/update': + case 'robeson/update': + return this.update(cb) default: return this.object(cb) } } @@ -146,7 +157,7 @@ RenderMsg.prototype.post = function (cb) { RenderMsg.prototype.vote = function (cb) { var self = this - var v = self.c.vote || {} + var v = self.c.vote || self.c.like || {} self.link(v, function (err, a) { if (err) return cb(err) self.wrapMini([ @@ -369,3 +380,64 @@ RenderMsg.prototype.issues = function (cb) { done(cb) return els } + +RenderMsg.prototype.repost = function (cb) { + var self = this + var id = u.linkDest(self.c.repost) + self.app.getMsg(id, function (err, msg) { + if (err && err.name == 'NotFoundError') + gotMsg(null, id.substring(0, 10)+'...(missing)') + else if (err) gotMsg(err) + else if (self.msg.value.private) self.app.unboxMsg(msg, gotMsg) + else gotMsg(null, msg) + }) + 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) { + self.wrapMini(['reposted ', + h('code.ssb-id', + h('a', {href: self.render.toUrl(id)}, id)), + h('div', err ? u.renderError(err) : msgEl || '') + ], cb) + }) + } +} + +RenderMsg.prototype.update = function (cb) { + var id = String(this.c.update) + this.wrapMini([ + h('div', 'updated ', h('code.ssb-id', + h('a', {href: this.render.toUrl(id)}, id))), + this.c.title ? h('h4.msg-title', this.c.title) : '', + this.c.description ? h('div', + {innerHTML: this.render.markdown(this.c.description)}) : '' + ], cb) +} + +function formatDuration(s) { + return Math.floor(s / 60) + ':' + ('0' + s % 60).substr(-2) +} + +RenderMsg.prototype.audio = function (cb) { + // fileName, fallbackFileName, overview + this.wrap(h('table', h('tr', + h('td', + this.c.artworkSrc + ? h('a', {href: this.render.toUrl(this.c.artworkSrc)}, h('img', { + src: this.render.imageUrl(this.c.artworkSrc), + alt: ' ', + width: 72, + height: 72, + })) + : ''), + h('td', + h('a', {href: this.render.toUrl(this.c.audioSrc)}, this.c.title), + isFinite(this.c.duration) + ? ' (' + formatDuration(this.c.duration) + ')' + : '', + this.c.description + ? h('p', {innerHTML: this.render.markdown(this.c.description)}) + : '' + ))), cb) +} diff --git a/lib/render.js b/lib/render.js index f68c8aa..7af5149 100644 --- a/lib/render.js +++ b/lib/render.js @@ -77,6 +77,8 @@ Render.prototype.markdown = function (text, mentions) { } Render.prototype.imageUrl = function (ref) { + var m = /^blobstore:(.*)/.exec(ref) + if (m) ref = m[1] return this.opts.img_base + ref } @@ -93,6 +95,8 @@ Render.prototype.toUrl = function (href) { case '#': return this.opts.base + encodeURIComponent(href) case '/': return this.opts.base + href.substr(1) } + var m = /^blobstore:(.*)/.exec(href) + if (m) return this.opts.blob_base + m[1] if (/^javascript:/.test(href)) return false return href } diff --git a/static/styles.css b/static/styles.css index c49027e..790e6ab 100644 --- a/static/styles.css +++ b/static/styles.css @@ -95,10 +95,13 @@ pre { .msg-main, .msg-right { border-top: 1px solid #ddd; - vertical-align: top; padding: .5ex; } +td { + vertical-align: top; +} + .msg-main { width: 100%; } -- cgit v1.2.3