diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/render-msg.js | 74 | ||||
-rw-r--r-- | lib/render.js | 4 |
2 files changed, 77 insertions, 1 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 } |