From 684a05c5f4bc21386aa5f3a7f103836a60cc7f00 Mon Sep 17 00:00:00 2001 From: cel Date: Fri, 14 Apr 2017 20:02:43 -0700 Subject: Render ssb-dns messages --- lib/render-msg.js | 29 +++++++++++++++++++++++++++++ lib/render.js | 5 +++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/render-msg.js b/lib/render-msg.js index 711a759..1873128 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -201,6 +201,7 @@ RenderMsg.prototype.message = function (raw, cb) { case 'issue': return this.issue(cb) case 'issue-edit': return this.issueEdit(cb) case 'music-release-cc': return this.musicRelease(cb) + case 'ssb-dns': return this.dns(cb) case 'ferment/audio': case 'robeson/audio': return this.audio(cb) @@ -302,6 +303,9 @@ RenderMsg.prototype.title = function (cb) { else cb(null, '%' + self.c.type + ': ' + (self.c.title || title(self.c.text))) } else { + if (self.c.type === 'ssb-dns') + cb(null, self.c.record && JSON.stringify(self.c.record.data) || self.msg.key) + else self.app.getAbout(self.msg.key, function (err, about) { if (err) return cb(err) if (about.name) return cb(null, about.name) @@ -652,6 +656,31 @@ RenderMsg.prototype.musicRelease = function (cb) { ], cb) } +RenderMsg.prototype.dns = function (cb) { + var self = this + var record = self.c.record || {} + var done = multicb({pluck: 1, spread: true}) + var elCb = done() + self.wrap([ + h('div', + h('p', + h('ins', {title: 'name'}, record.name), ' ', + h('span', {title: 'ttl'}, record.ttl), ' ', + h('span', {title: 'class'}, record.class), ' ', + h('span', {title: 'type'}, record.type) + ), + h('pre', {title: 'data'}, + JSON.stringify(record.data || record.value, null, 2)), + !self.c.branch ? null : h('div', + 'replaces: ', u.toArray(self.c.branch).map(function (id, i) { + return [self.link1(id, done()), i === 0 ? ', ' : ''] + }) + ) + ) + ], elCb) + done(cb) +} + RenderMsg.prototype.wifiNetwork = function (cb) { var net = this.c.network || {} this.wrap([ diff --git a/lib/render.js b/lib/render.js index 80e4893..7890c1f 100644 --- a/lib/render.js +++ b/lib/render.js @@ -162,7 +162,7 @@ Render.prototype.prepareLink = function (link, cb) { if (typeof link === 'string') link = {link: link} if (link.name || !link.link) cb(null, link) else this.app.getAbout(link.link, function (err, about) { - if (err) return cb(err) + if (err) return cb(null, link) link.name = about.name || (link.link.substr(0, 8) + '…') if (link.name && link.name[0] === link.link[0]) { link.name = link.name.substr(1) @@ -188,7 +188,8 @@ Render.prototype.idLink = function (link, cb) { self.prepareLink(link, function (err, link) { if (err) return cb(err) a.href = self.toUrl(link.link) - a.childNodes[0].textContent = '@' + link.name + var sigil = link.link && link.link[0] || '@' + a.childNodes[0].textContent = sigil + link.name cb() }) return a -- cgit v1.2.3