aboutsummaryrefslogtreecommitdiff
path: root/lib/render-msg.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-07-26 11:57:07 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-07-26 12:03:40 -1000
commitcab781470c10d358f770475c7b25d87e29f614bb (patch)
treed4b68301107ae9a21023cbefb94dbc8cf0d1e38f /lib/render-msg.js
parent09f70e5f94777bbe5a18d2980ca221360642a970 (diff)
downloadpatchfoo-cab781470c10d358f770475c7b25d87e29f614bb.tar.gz
patchfoo-cab781470c10d358f770475c7b25d87e29f614bb.zip
Render post edits and diffs
Diffstat (limited to 'lib/render-msg.js')
-rw-r--r--lib/render-msg.js49
1 files changed, 37 insertions, 12 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js
index 08eb03e..d21f095 100644
--- a/lib/render-msg.js
+++ b/lib/render-msg.js
@@ -158,6 +158,9 @@ RenderMsg.prototype.actions = function () {
this.msg.rel ? [this.msg.rel, ' '] : '',
this.opts.withGt && this.msg.timestamp ? [
h('a', {href: '?gt=' + this.msg.timestamp}, '↓'), ' '] : '',
+ this.c.type === 'edit' ? [
+ h('a', {href: this.toUrl('/edit-diff/' + encodeURIComponent(this.msg.key)),
+ title: 'view post edit diff'}, 'diff'), ' '] : '',
this.c.type === 'gathering' ? [
h('a', {href: this.render.toUrl('/about/' + encodeURIComponent(this.msg.key))}, 'about'), ' '] : '',
/^(ssb_)?chess_/.test(this.c.type) ? [
@@ -300,6 +303,7 @@ RenderMsg.prototype.message = function (cb) {
case 'scat_message': return this.scat(cb)
case 'share': return this.share(cb)
case 'tag': return this.tag(cb)
+ case 'edit': return this.edit(cb)
default: return this.object(cb)
}
}
@@ -346,6 +350,33 @@ RenderMsg.prototype.post = function (cb) {
})
}
+RenderMsg.prototype.edit = function (cb) {
+ var self = this
+ var done = multicb({pluck: 1, spread: true})
+ if (self.c.root === self.c.branch) done()()
+ else self.link(self.c.root, done())
+ self.links(self.c.branch, done())
+ self.links(self.c.fork, done())
+ self.link(self.c.original, done())
+ if (self.c.updated === self.c.branch) done()()
+ else self.link(self.c.updated, done())
+ done(function (err, rootLink, branchLinks, forkLinks, originalLink, updatedLink) {
+ if (err) return self.wrap(u.renderError(err), cb)
+ self.wrap(h('div.ssb-post',
+ h('div', 'edit ', originalLink || ''),
+ rootLink ? h('div', h('small', h('span.symbol', '→'), ' ', rootLink)) : '',
+ updatedLink ? h('div', h('small', h('span.symbol', '  ↳'), ' ', updatedLink)) : '',
+ branchLinks.map(function (a, i) {
+ return h('div', h('small', h('span.symbol', '  ↳'), ' ', a))
+ }),
+ forkLinks.map(function (a, i) {
+ return h('div', h('small', h('span.symbol', '⑂'), ' ', a))
+ }),
+ h('blockquote.ssb-post-text', {innerHTML: self.markdown()})
+ ), cb)
+ })
+}
+
RenderMsg.prototype.vote = function (cb) {
var self = this
var v = self.c.vote || self.c.like || {}
@@ -613,7 +644,7 @@ RenderMsg.prototype.aboutRating = function (cb) {
var el = h('div', {title: text})
for (var i = 0; i < rating; i++) {
el.appendChild(h('span',
- {innerHTML: unwrapP(this.render.markdown(type) + ' ')}
+ {innerHTML: u.unwrapP(this.render.markdown(type) + ' ')}
))
}
return el
@@ -1010,7 +1041,7 @@ RenderMsg.prototype.mutualCredit = function (cb) {
? h('a', {href: self.toUrl(currency)}, currency)
: h('ins', currency),
self.c.memo ? [' for ',
- h('q', {innerHTML: unwrapP(self.render.markdown(self.c.memo))})
+ h('q', {innerHTML: u.unwrapP(self.render.markdown(self.c.memo))})
] : ''
], cb)
})
@@ -1024,14 +1055,8 @@ RenderMsg.prototype.gathering = function (cb) {
this.wrapMini('gathering', cb)
}
-function unwrapP(html) {
- return String(html).replace(/^<p>(.*)<\/p>\s*$/, function ($0, $1) {
- return $1
- })
-}
-
RenderMsg.prototype.micro = function (cb) {
- var el = h('span', {innerHTML: unwrapP(this.markdown())})
+ var el = h('span', {innerHTML: u.unwrapP(this.markdown())})
this.wrapMini(el, cb)
}
@@ -1087,7 +1112,7 @@ RenderMsg.prototype.npmPublish = function (cb) {
),
pkgDescription ? h('div',
// TODO: make mdInline use custom emojis
- h('q', {innerHTML: unwrapP(render.markdown(pkgDescription))})) : '',
+ h('q', {innerHTML: u.unwrapP(render.markdown(pkgDescription))})) : '',
prevLinks.length ? h('div', 'previous: ', prevLinks) : '',
pkgReadme && pkgReadme !== singleReadme ?
h('blockquote', {innerHTML: render.markdown(pkgReadme)}) : '',
@@ -1748,8 +1773,8 @@ RenderMsg.prototype.poll = function (cb) {
var details = self.c.pollDetails || self.c.details || {}
var choices = u.toArray(details.choices)
return self.wrap(h('div',
- h('h3', {innerHTML: unwrapP(self.render.markdown(self.c.title))}),
- h('div', {innerHTML: unwrapP(self.render.markdown(self.c.body, self.c.mentions))}),
+ h('h3', {innerHTML: u.unwrapP(self.render.markdown(self.c.title))}),
+ h('div', {innerHTML: u.unwrapP(self.render.markdown(self.c.body, self.c.mentions))}),
h('p', 'closes at: ', h('span', {
title: closeDate.toLocaleString()
}, closeDate.toString())),