git ssb

16+

cel / patchfoo



Commit cab781470c10d358f770475c7b25d87e29f614bb

Render post edits and diffs

cel committed on 7/26/2018, 10:03:40 PM
Parent: 09f70e5f94777bbe5a18d2980ca221360642a970

Files changed

lib/render-msg.jschanged
lib/serve.jschanged
lib/util.jschanged
lib/render-msg.jsView
@@ -157,8 +157,11 @@
157157 h('form', {method: 'post', action: ''},
158158 this.msg.rel ? [this.msg.rel, ' '] : '',
159159 this.opts.withGt && this.msg.timestamp ? [
160160 h('a', {href: '?gt=' + this.msg.timestamp}, '↓'), ' '] : '',
161 + this.c.type === 'edit' ? [
162 + h('a', {href: this.toUrl('/edit-diff/' + encodeURIComponent(this.msg.key)),
163 + title: 'view post edit diff'}, 'diff'), ' '] : '',
161164 this.c.type === 'gathering' ? [
162165 h('a', {href: this.render.toUrl('/about/' + encodeURIComponent(this.msg.key))}, 'about'), ' '] : '',
163166 /^(ssb_)?chess_/.test(this.c.type) ? [
164167 h('a', {href: this.toUrl(this.msg.key) + '?full',
@@ -299,8 +302,9 @@
299302 case 'position': if (this.c.version === 'v1') return this.pollPosition(cb)
300303 case 'scat_message': return this.scat(cb)
301304 case 'share': return this.share(cb)
302305 case 'tag': return this.tag(cb)
306 + case 'edit': return this.edit(cb)
303307 default: return this.object(cb)
304308 }
305309 }
306310
@@ -345,8 +349,35 @@
345349 ), cb)
346350 })
347351 }
348352
353 +RenderMsg.prototype.edit = function (cb) {
354 + var self = this
355 + var done = multicb({pluck: 1, spread: true})
356 + if (self.c.root === self.c.branch) done()()
357 + else self.link(self.c.root, done())
358 + self.links(self.c.branch, done())
359 + self.links(self.c.fork, done())
360 + self.link(self.c.original, done())
361 + if (self.c.updated === self.c.branch) done()()
362 + else self.link(self.c.updated, done())
363 + done(function (err, rootLink, branchLinks, forkLinks, originalLink, updatedLink) {
364 + if (err) return self.wrap(u.renderError(err), cb)
365 + self.wrap(h('div.ssb-post',
366 + h('div', 'edit ', originalLink || ''),
367 + rootLink ? h('div', h('small', h('span.symbol', '→'), ' ', rootLink)) : '',
368 + updatedLink ? h('div', h('small', h('span.symbol', '  ↳'), ' ', updatedLink)) : '',
369 + branchLinks.map(function (a, i) {
370 + return h('div', h('small', h('span.symbol', '  ↳'), ' ', a))
371 + }),
372 + forkLinks.map(function (a, i) {
373 + return h('div', h('small', h('span.symbol', '⑂'), ' ', a))
374 + }),
375 + h('blockquote.ssb-post-text', {innerHTML: self.markdown()})
376 + ), cb)
377 + })
378 +}
379 +
349380 RenderMsg.prototype.vote = function (cb) {
350381 var self = this
351382 var v = self.c.vote || self.c.like || {}
352383 self.link(v, function (err, a) {
@@ -612,9 +643,9 @@
612643 if (rating > 5) rating = 5
613644 var el = h('div', {title: text})
614645 for (var i = 0; i < rating; i++) {
615646 el.appendChild(h('span',
616- {innerHTML: unwrapP(this.render.markdown(type) + ' ')}
647 + {innerHTML: u.unwrapP(this.render.markdown(type) + ' ')}
617648 ))
618649 }
619650 return el
620651 }
@@ -1009,9 +1040,9 @@
10091040 currency[0] === '#'
10101041 ? h('a', {href: self.toUrl(currency)}, currency)
10111042 : h('ins', currency),
10121043 self.c.memo ? [' for ',
1013- h('q', {innerHTML: unwrapP(self.render.markdown(self.c.memo))})
1044 + h('q', {innerHTML: u.unwrapP(self.render.markdown(self.c.memo))})
10141045 ] : ''
10151046 ], cb)
10161047 })
10171048 }
@@ -1023,16 +1054,10 @@
10231054 RenderMsg.prototype.gathering = function (cb) {
10241055 this.wrapMini('gathering', cb)
10251056 }
10261057
1027-function unwrapP(html) {
1028- return String(html).replace(/^<p>(.*)<\/p>\s*$/, function ($0, $1) {
1029- return $1
1030- })
1031-}
1032-
10331058 RenderMsg.prototype.micro = function (cb) {
1034- var el = h('span', {innerHTML: unwrapP(this.markdown())})
1059 + var el = h('span', {innerHTML: u.unwrapP(this.markdown())})
10351060 this.wrapMini(el, cb)
10361061 }
10371062
10381063 function hJoin(els, seperator, lastSeparator) {
@@ -1086,9 +1111,9 @@
10861111 }), ', ')
10871112 ),
10881113 pkgDescription ? h('div',
10891114 // TODO: make mdInline use custom emojis
1090- h('q', {innerHTML: unwrapP(render.markdown(pkgDescription))})) : '',
1115 + h('q', {innerHTML: u.unwrapP(render.markdown(pkgDescription))})) : '',
10911116 prevLinks.length ? h('div', 'previous: ', prevLinks) : '',
10921117 pkgReadme && pkgReadme !== singleReadme ?
10931118 h('blockquote', {innerHTML: render.markdown(pkgReadme)}) : '',
10941119 versions.map(function (version, i) {
@@ -1747,10 +1772,10 @@
17471772 var closeDate = new Date(self.c.closesAt)
17481773 var details = self.c.pollDetails || self.c.details || {}
17491774 var choices = u.toArray(details.choices)
17501775 return self.wrap(h('div',
1751- h('h3', {innerHTML: unwrapP(self.render.markdown(self.c.title))}),
1752- h('div', {innerHTML: unwrapP(self.render.markdown(self.c.body, self.c.mentions))}),
1776 + h('h3', {innerHTML: u.unwrapP(self.render.markdown(self.c.title))}),
1777 + h('div', {innerHTML: u.unwrapP(self.render.markdown(self.c.body, self.c.mentions))}),
17531778 h('p', 'closes at: ', h('span', {
17541779 title: closeDate.toLocaleString()
17551780 }, closeDate.toString())),
17561781 details.type === 'chooseOne' ? h('form', {method: 'post', action: ''},
lib/serve.jsView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 103688 bytes
New file size: 106158 bytes
lib/util.jsView
@@ -225,4 +225,11 @@
225225
226226 u.token = function () {
227227 return '__' + Math.random().toString(36).substr(2) + '__'
228228 }
229 +
230 +u.unwrapP = function(html) {
231 + return String(html).replace(/^<p>(.*)<\/p>\s*$/, function ($0, $1) {
232 + return $1
233 + })
234 +}
235 +

Built with git-ssb-web