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.js40
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)