diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2018-01-10 21:28:44 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2018-01-10 21:28:44 -1000 |
commit | 5c93e1267a7951f6aadae0ac269f73de9da7f423 (patch) | |
tree | 35e5af749ee1298a8a57120684af94cc5ce6df56 /lib/render-msg.js | |
parent | 23cd085f4cf52dfdd2d00b75c2370cf34508a98a (diff) | |
parent | 964cb82322e65c807382c6a84eba0a8e21c1c70f (diff) | |
download | patchfoo-5c93e1267a7951f6aadae0ac269f73de9da7f423.tar.gz patchfoo-5c93e1267a7951f6aadae0ac269f73de9da7f423.zip |
Merge branch 'master' into layout
Diffstat (limited to 'lib/render-msg.js')
-rw-r--r-- | lib/render-msg.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js index e8830c3..cfc32c7 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -10,6 +10,7 @@ function RenderMsg(render, app, msg, opts) { this.render = render this.app = app this.msg = msg + this.serve = opts.serve this.value = msg && msg.value || {} var content = this.value.content this.c = content || {} @@ -20,6 +21,13 @@ function RenderMsg(render, app, msg, opts) { this.shouldWrap = this.opts.wrap !== false } +RenderMsg.prototype.getMsg = function (id, cb) { + if (!id) return cb() + return this.serve + ? this.serve.getMsgDecryptedMaybeOoo(id, cb) + : this.app.getMsgDecryptedOoo(id, cb) +} + RenderMsg.prototype.toUrl = function (href) { return this.render.toUrl(href) } @@ -286,6 +294,8 @@ RenderMsg.prototype.message = function (cb) { case 'talenet-idea-update': return this.ideaUpdate(cb) case 'talenet-idea-comment': case 'talenet-idea-comment_reply': return this.ideaComment(cb) + case 'about-resource': return this.aboutResource(cb) + case 'line-comment': return this.lineComment(cb) default: return this.object(cb) } } @@ -800,6 +810,7 @@ RenderMsg.prototype.valueTable = function (val, depth, cb) { case 'string': if (val[0] === '#') return cb(null, h('a', {href: self.toUrl('/channel/' + val.substr(1))}, val)) if (u.isRef(val)) return self.link1(val, cb) + if (/^ssb-blob:\/\//.test(val)) return cb(), h('a', {href: self.toUrl(val)}, val) return cb(), self.linkify(val) case 'boolean': return cb(), h('input', { @@ -1626,3 +1637,43 @@ RenderMsg.prototype.ideaComment = function (cb) { ]), cb) }) } + +RenderMsg.prototype.aboutResource = function (cb) { + var self = this + return self.wrap(h('div', + 'describes resource ', + h('a', {href: self.toUrl(self.c.about)}, self.c.name), + ':', + h('blockquote', {innerHTML: self.render.markdown(self.c.description)}) + ), cb) +} + +RenderMsg.prototype.lineComment = function (cb) { + var self = this + var done = multicb({pluck: 1, spread: true}) + self.link(self.c.repo, done()) + self.getMsg(self.c.updateId, done()) + done(function (err, repoLink, updateMsg) { + if (err) return cb(err) + return self.wrap(h('div', + h('div', h('small', '> ', + repoLink, ' ', + h('a', { + href: self.toUrl(self.c.updateId) + }, + updateMsg + ? htime(new Date(updateMsg.value.timestamp)) + : String(self.c.updateId) + ), ' ', + h('a', { + href: self.toUrl('/git/commit/' + self.c.commitId + '?msg=' + encodeURIComponent(self.c.updateId)) + }, String(self.c.commitId).substr(0, 8)), ' ', + h('a', { + href: self.toUrl('/git/line-comment/' + + encodeURIComponent(self.msg.key || JSON.stringify(self.msg))) + }, h('code', self.c.filePath + ':' + self.c.line)) + )), + self.c.text ? + h('div', {innerHTML: self.render.markdown(self.c.text)}) : ''), cb) + }) +} |