diff options
Diffstat (limited to 'lib/serve.js')
-rw-r--r-- | lib/serve.js | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/lib/serve.js b/lib/serve.js index 73e209c..b688f72 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -259,6 +259,8 @@ Serve.prototype.publish = function (content, cb) { Serve.prototype.handle = function () { var m = urlIdRegex.exec(this.req.url) this.query = m[5] ? qs.parse(m[5]) : {} + this.useOoo = this.query.ooo != null ? + Boolean(this.query.ooo) : this.app.useOoo switch (m[2]) { case '%25': m[2] = '%'; m[1] = decodeURIComponent(m[1]) case '%': return this.id(m[1], m[3]) @@ -955,7 +957,7 @@ Serve.prototype.links = function (path) { Serve.prototype.rawId = function (id) { var self = this - self.app.getMsgDecrypted(id, function (err, msg) { + self.getMsgDecryptedMaybeOoo(id, function (err, msg) { if (err) return pull( pull.once(u.renderError(err).outerHTML), self.respondSink(400, {'Content-Type': ctype('html')}) @@ -1003,12 +1005,11 @@ function threadHeads(msgs, rootId) { })) } - Serve.prototype.id = function (id, path) { var self = this if (self.query.raw != null) return self.rawId(id) - this.app.getMsgDecrypted(id, function (err, rootMsg) { + this.getMsgDecryptedMaybeOoo(id, function (err, rootMsg) { if (err && err.name === 'NotFoundError') err = null, rootMsg = { key: id, value: {content: false}} if (err) return self.respond(500, err.stack || err) @@ -1029,26 +1030,31 @@ Serve.prototype.id = function (id, path) { if (!channel && c.channel) channel = c.channel }), pull.collect(function (err, links) { - if (err) return self.respond(500, err.stack || err) - pull( - pull.values(sort(links)), - self.renderThread({ - msgId: id, - }), - self.wrapMessages(), - self.wrapThread({ - recps: recps, - root: threadRootId, - post: id, - branches: threadHeads(links, threadRootId), - postBranches: threadRootId !== id && threadHeads(links, id), - channel: channel, - }), - self.wrapPage(id), - self.respondSink(200) - ) + if (err) return gotLinks(err) + if (!self.useOoo) return gotLinks(null, links) + self.app.expandOoo({msgs: links, dest: id}, gotLinks) }) ) + function gotLinks(err, links) { + if (err) return self.respond(500, err.stack || err) + pull( + pull.values(sort(links)), + self.renderThread({ + msgId: id, + }), + self.wrapMessages(), + self.wrapThread({ + recps: recps, + root: threadRootId, + post: id, + branches: threadHeads(links, threadRootId), + postBranches: threadRootId !== id && threadHeads(links, id), + channel: channel, + }), + self.wrapPage(id), + self.respondSink(200) + ) + } }) } @@ -1955,7 +1961,7 @@ Serve.prototype.gitBlob = function (rev) { self.respondSink(400) ) - self.app.getMsgDecrypted(self.query.msg, function (err, msg) { + self.getMsgDecryptedMaybeOoo(self.query.msg, function (err, msg) { if (err) return pull( pull.once(u.renderError(err).outerHTML), self.wrapPage('git object ' + rev), @@ -2769,6 +2775,11 @@ Serve.prototype.getBuiltinEmojiLink = function (name) { } } +Serve.prototype.getMsgDecryptedMaybeOoo = function (key, cb) { + if (this.useOoo) this.app.getMsgDecryptedOoo(key, cb) + else this.app.getMsgDecrypted(key, cb) +} + Serve.prototype.emojis = function (path) { var self = this var seen = {} |