aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-03-13 14:15:36 -0400
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-03-13 22:11:10 -0400
commit34982291bc2e6ecdd54fcc74d09d16f6e0929db0 (patch)
tree6744ea7b6f8c295c937ca37e7e85c483ebec752c /lib
parent8804ea0353ffbfb5bc6fa82031d8eadfad6ce41a (diff)
downloadpatchfoo-34982291bc2e6ecdd54fcc74d09d16f6e0929db0.tar.gz
patchfoo-34982291bc2e6ecdd54fcc74d09d16f6e0929db0.zip
render missing thread root
Diffstat (limited to 'lib')
-rw-r--r--lib/app.js2
-rw-r--r--lib/render-msg.js21
-rw-r--r--lib/serve.js9
3 files changed, 20 insertions, 12 deletions
diff --git a/lib/app.js b/lib/app.js
index 530f10f..c4683d7 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -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) {