diff options
author | cel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519> | 2020-03-25 10:57:51 -0400 |
---|---|---|
committer | cel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519> | 2020-03-28 13:55:36 -0400 |
commit | 4ee97dfaa67cc8ab77bbac574f0d05c6d60f4e37 (patch) | |
tree | 7e85d67e0e97c51f5b3d6bfa80b81ee7d61d4b56 /lib/render-msg.js | |
parent | 646e70a38f1daae390271c3ad65c4b6c0d87de5f (diff) | |
download | patchfoo-4ee97dfaa67cc8ab77bbac574f0d05c6d60f4e37.tar.gz patchfoo-4ee97dfaa67cc8ab77bbac574f0d05c6d60f4e37.zip |
Render descriptions as diffs in gathering threads
Diffstat (limited to 'lib/render-msg.js')
-rw-r--r-- | lib/render-msg.js | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js index 68ea4d7..3a55a3b 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -19,13 +19,17 @@ function RenderMsg(render, app, msg, opts) { this.isMissing = !content this.hasFullLink = this.c.type === 'chess_move' || - this.c.type === 'ssb_chess_move' + this.c.type === 'ssb_chess_move' || + (this.c.type === 'about' && this.c.about == this.value.author + && typeof this.c.description === 'string') if (typeof opts === 'boolean') opts = {raw: opts} this.opts = opts || {} this.shouldWrap = this.opts.wrap !== false var ts = this.value.timestamp this.date = ts ? new Date(ts) : null + this.thread = opts.links || [] + this.single = opts.single } RenderMsg.prototype.getMsg = function (id, cb) { @@ -645,6 +649,7 @@ var knownAboutProps = { } RenderMsg.prototype.about = function (cb) { + var self = this var keys = Object.keys(this.c).filter(function (k) { return k !== 'about' && k !== 'type' && k !== 'recps' }).sort().join() @@ -702,6 +707,15 @@ RenderMsg.prototype.about = function (cb) { var target = this.c.about var pwh = this.c.publicWebHosting + function descriptionOrDiff(cb) { + // show diff for self-description and gathering thread. + // otherwise it might require a more expensive query + var prevMsg = !self.opts.full && self.getPreviousAboutInThreadSync() + cb() + if (prevMsg) return self.render.textEditDiffTable(prevMsg, self.msg) + return h('div', {innerHTML: self.render.markdown(self.c.description)}) + } + this.wrap([ this.c.root && this.c.root !== target ? h('div', h('small', '→ ', this.link1(this.c.root, done())) @@ -731,8 +745,7 @@ RenderMsg.prototype.about = function (cb) { ]) : '', this.c.genre ? h('div', ['genre: ', h('u', u.toString(this.c.genre))]) : '', this.c.shelve ? h('div', ['shelf: ', h('u', u.toString(this.c.shelve))]) : '', - this.c.description ? h('div', - {innerHTML: this.render.markdown(this.c.description)}) : '', + this.c.description ? descriptionOrDiff(done()) : '', this.c.review ? h('blockquote', {innerHTML: this.render.markdown(this.c.review)}) : '', this.c.attendee ? h('div', @@ -763,6 +776,27 @@ RenderMsg.prototype.about = function (cb) { done(cb) } +RenderMsg.prototype.getPreviousAboutInThreadSync = function () { + var self = this + var root = this.thread[0] + if (!root) return + if (this.c.about !== root.key) { + // probably won't work + return + } + var i = this.thread.indexOf(this.msg) + var target = this.c.about + if (i === -1) return + for (var j = i-1; j >= 0; j--) { + var msg = this.thread[j] + var c = msg && msg.value && msg.value.content + if (c && c.type === 'about' && c.about === target + && typeof c.description === 'string') { + return msg + } + } +} + RenderMsg.prototype.aboutRating = function (cb) { var rating = Number(this.c.rating) var max = Number(this.c.ratingMax) |