aboutsummaryrefslogtreecommitdiff
path: root/lib/render-msg.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-02-01 10:36:08 -0800
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-02-04 02:53:51 -0800
commit5b3dc4bf49f367de33fcd4e6e21281ffec91b6a7 (patch)
tree01e6cadda612c7832ac008e6dff2cf7fe816f59a /lib/render-msg.js
parent4f3840b0b2f765a02d8b90c8cb2e9270458b8ae2 (diff)
downloadpatchfoo-5b3dc4bf49f367de33fcd4e6e21281ffec91b6a7.tar.gz
patchfoo-5b3dc4bf49f367de33fcd4e6e21281ffec91b6a7.zip
Render ferment message types
Diffstat (limited to 'lib/render-msg.js')
-rw-r--r--lib/render-msg.js74
1 files changed, 73 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)
+}