aboutsummaryrefslogtreecommitdiff
path: root/lib/render-msg.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/render-msg.js')
-rw-r--r--lib/render-msg.js41
1 files changed, 37 insertions, 4 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js
index 97b71d7..475965a 100644
--- a/lib/render-msg.js
+++ b/lib/render-msg.js
@@ -4,6 +4,7 @@ var multicb = require('multicb')
var u = require('./util')
var mdInline = require('./markdown-inline')
var ssbKeys = require('ssb-keys')
+var qs = require('querystring')
module.exports = RenderMsg
@@ -546,7 +547,8 @@ RenderMsg.prototype.link = function (link, cb) {
RenderMsg.prototype.link1 = function (link, cb) {
var self = this
- var ref = u.linkDest(link)
+ var ref = u.linkDest(link) +
+ (link && link.query ? '?' + qs.stringify(link.query) : '')
if (!ref) return cb(), ''
var a = h('a', {href: self.toUrl(ref)}, ref)
self.getName(ref, function (err, name) {
@@ -999,6 +1001,37 @@ function linkName(link) {
return link.name
}
+var knownLinkProps = {
+ link: true,
+ query: true,
+ name: true,
+ type: true,
+ size: true
+}
+
+RenderMsg.prototype.linkValue = function (link, cb) {
+ var self = this
+ var done = multicb({pluck: 1, spread: true})
+ var extra
+ for (var k in link) {
+ if (knownLinkProps[k]) continue
+ if (!extra) extra = {}
+ extra[k] = link[k]
+ }
+ // TODO should check for error thrown by stringify?
+ var ref = link.link + (link.query ? '?' + qs.stringify(link.query) : '')
+ var el = h('div', [
+ link.name
+ ? h('a', {href: self.toUrl(ref)}, linkName(link))
+ : self.link1(link, done()),
+ (link.type ? ' [' + link.type + ']' : ''),
+ (link.size != null ? ' (' + self.render.formatSize(link.size) + ')' : ''),
+ extra ? self.valueTable(extra, NaN, done()) : ''
+ ])
+ done(cb)
+ return el
+}
+
RenderMsg.prototype.valueTable = function (val, depth, cb) {
var isContent = depth === 1
var self = this
@@ -1011,9 +1044,9 @@ RenderMsg.prototype.valueTable = function (val, depth, cb) {
? h('ul', val.map(function (item) {
return h('li', self.valueTable(item, depth + 1, done()))
}))
- : (keys = Object.keys(val)).sort().join() === 'link,name' && val.link && val.name
- ? h('a', {href: self.toUrl(val.link)}, linkName(val))
- : h('table.ssb-object', keys.map(function (key) {
+ : typeof val.link === 'string' && u.isRef(val.link)
+ ? self.linkValue(val, done())
+ : h('table.ssb-object', Object.keys(val).map(function (key) {
if (key === 'text') {
return h('tr',
h('td', h('strong', 'text')),