diff options
-rw-r--r-- | lib/app.js | 2 | ||||
-rw-r--r-- | lib/render-msg.js | 21 | ||||
-rw-r--r-- | lib/serve.js | 9 |
3 files changed, 20 insertions, 12 deletions
@@ -55,7 +55,7 @@ App.prototype.error = console.error.bind(console, logPrefix) App.prototype.unboxMsg = function (msg, cb) { var self = this - var c = msg.value.content + var c = msg.value && msg.value.content if (typeof c !== 'string') cb(null, msg) else self.unboxContent(c, function (err, content) { if (err) { diff --git a/lib/render-msg.js b/lib/render-msg.js index 23e236f..703f5cd 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -10,10 +10,12 @@ function RenderMsg(render, app, msg, opts) { this.render = render this.app = app this.msg = msg + this.value = msg && msg.value || {} + var content = this.value.content + this.c = content || {} + this.isMissing = !content var opts = opts || {} this.shouldWrap = opts.wrap !== false - - this.c = msg.value.content || {} } RenderMsg.prototype.toUrl = function (href) { @@ -125,13 +127,13 @@ RenderMsg.prototype.wrap = function (content, cb) { RenderMsg.prototype.wrapMini = function (content, cb) { if (!this.shouldWrap) return cb(null, content) - var date = new Date(this.msg.value.timestamp) + var date = new Date(this.value.timestamp) var self = this var channel = this.c.channel ? '#' + this.c.channel : '' var done = multicb({pluck: 1, spread: true}) done()(null, h('tr.msg-row', h('td.msg-left', - this.render.idLink(this.msg.value.author, done()), ' ', + this.render.idLink(this.value.author, done()), ' ', this.recpsLine(done()), channel ? [h('a', {href: this.toUrl(channel)}, channel), ' '] : ''), h('td.msg-main', @@ -154,8 +156,8 @@ RenderMsg.prototype.wrapMini = function (content, cb) { } RenderMsg.prototype.recpsLine = function (cb) { - if (!this.msg.value.private) return cb(), '' - var author = this.msg.value.author + if (!this.value.private) return cb(), '' + var author = this.value.author var recpsNotSelf = u.toArray(this.c.recps).filter(function (link) { return u.linkDest(link) !== author }) @@ -163,7 +165,7 @@ RenderMsg.prototype.recpsLine = function (cb) { } RenderMsg.prototype.recpsIds = function () { - return this.msg.value.private + return this.value.private ? u.toArray(this.c.recps).map(u.linkDest) : [] } @@ -181,6 +183,7 @@ RenderMsg.prototype.voteFormInner = function (expression) { RenderMsg.prototype.message = function (raw, cb) { if (raw) return this.raw(cb) if (typeof this.c === 'string') return this.encrypted(cb) + if (this.isMissing) return this.missing(cb) switch (this.c.type) { case 'post': return this.post(cb) case 'ferment/like': @@ -458,6 +461,10 @@ RenderMsg.prototype.object = function (cb) { this.wrapMini(h('pre', this.c.type), cb) } +RenderMsg.prototype.missing = function (cb) { + this.wrapMini(h('code', 'MISSING'), cb) +} + RenderMsg.prototype.issues = function (cb) { var self = this var done = multicb({pluck: 1, spread: true}) diff --git a/lib/serve.js b/lib/serve.js index 504c633..62aa86f 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -395,7 +395,7 @@ Serve.prototype.channel = function (channel) { function threadHeads(msgs, rootId) { return sort.heads(msgs.filter(function (msg) { - var c = msg.value.content + var c = msg.value && msg.value.content return (c && c.root === rootId) || msg.key === rootId })) @@ -407,14 +407,15 @@ Serve.prototype.id = function (id, ext) { if (self.query.raw != null) return self.rawId(id) this.app.getMsgDecrypted(id, function (err, rootMsg) { - var rootContent = rootMsg && rootMsg.value.content - var getRoot = err ? pull.error(err) : pull.once(rootMsg) + if (err && err.name === 'NotFoundError') err = null, rootMsg = {key: id} + if (err) return self.respond(500, err.stack || err) + var rootContent = rootMsg && rootMsg.value && rootMsg.value.content var recps = rootContent && rootContent.recps var threadRootId = rootContent && rootContent.root || id var channel = rootContent && rootContent.channel pull( - cat([getRoot, self.app.sbot.links({dest: id, values: true})]), + cat([pull.once(rootMsg), self.app.sbot.links({dest: id, values: true})]), pull.unique('key'), paramap(self.app.unboxMsg, 4), pull.collect(function (err, links) { |