diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2018-01-09 19:47:33 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2018-01-09 19:48:04 -1000 |
commit | 074639bcbf2859a2973d0d3857eafe2fe9dd45a0 (patch) | |
tree | b9cf7ec7cdb50522fcbd4849801eb41c1d7aca80 /lib/serve.js | |
parent | 3c8e69899bcd403ed82bee2599bdd592150e5956 (diff) | |
download | patchfoo-074639bcbf2859a2973d0d3857eafe2fe9dd45a0.tar.gz patchfoo-074639bcbf2859a2973d0d3857eafe2fe9dd45a0.zip |
Include composer in line comment threads
Diffstat (limited to 'lib/serve.js')
-rw-r--r-- | lib/serve.js | 130 |
1 files changed, 76 insertions, 54 deletions
diff --git a/lib/serve.js b/lib/serve.js index 6e3b451..aaf558f 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -1016,57 +1016,71 @@ function threadHeads(msgs, rootId) { })) } -Serve.prototype.id = function (id, path) { +Serve.prototype.streamThreadWithComposer = function (opts) { var self = this - if (self.query.raw != null) return self.rawId(id) - - 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) - var rootContent = rootMsg && rootMsg.value && rootMsg.value.content - var recps = rootContent && rootContent.recps - || (rootMsg.value.private - ? [rootMsg.value.author, self.app.sbot.id].filter(uniques()) - : undefined) - var threadRootId = rootContent && rootContent.root || id - var channel + var id = opts.root + return ph('table', {class: 'ssb-msgs'}, u.readNext(next)) + function next(cb) { + self.getMsgDecryptedMaybeOoo(id, function (err, rootMsg) { + if (err && err.name === 'NotFoundError') err = null, rootMsg = { + key: id, value: {content: false}} + if (err) return cb(new Error(err.stack)) + if (!rootMsg) { + console.log('id', id, 'opts', opts) + } + var rootContent = rootMsg && rootMsg.value && rootMsg.value.content + var recps = rootContent && rootContent.recps + || (rootMsg.value.private + ? [rootMsg.value.author, self.app.sbot.id].filter(uniques()) + : undefined) + var threadRootId = rootContent && rootContent.root || id + var channel = opts.channel - pull( - cat([pull.once(rootMsg), self.app.sbot.links({dest: id, values: true})]), - pull.unique('key'), - self.app.unboxMessages(), - pull.through(function (msg) { - var c = msg && msg.value.content - if (!channel && c.channel) channel = c.channel - }), - pull.collect(function (err, links) { - 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, + cat([pull.once(rootMsg), self.app.sbot.links({dest: id, values: true})]), + pull.unique('key'), + self.app.unboxMessages(), + pull.through(function (msg) { + var c = msg && msg.value.content + if (!channel && c.channel) channel = c.channel }), - self.wrapPage(id), - self.respondSink(200) + pull.collect(function (err, links) { + 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 cb(new Error(err.stack)) + cb(null, 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), + placeholder: opts.placeholder, + channel: channel, + }) + )) + } + }) + } +} + +Serve.prototype.id = function (id, path) { + var self = this + if (self.query.raw != null) return self.rawId(id) + pull( + self.streamThreadWithComposer({root: id}), + self.wrapPage(id), + self.respondSink(200) + ) } Serve.prototype.userFeed = function (id, path) { @@ -2202,7 +2216,7 @@ Serve.prototype.gitDiffTable = function (diff, lineComments, lineCommentInfo) { (lineComments[newLineNum] ? ph('tr', ph('td', {colspan: 4}, - self.renderLineCommentThread(lineComments[newLineNum]) + self.renderLineCommentThread(lineComments[newLineNum], id) ) ) : newLineNum && lineCommentInfo && self.query.comment === id ? @@ -2229,12 +2243,12 @@ Serve.prototype.gitDiffTable = function (diff, lineComments, lineCommentInfo) { ) } -Serve.prototype.renderLineCommentThread = function (lineComment) { - var self = this - return ph('table', {class: 'ssb-msgs'}, pull( - this.app.getThread(lineComment.msg), - self.renderThread() - )) +Serve.prototype.renderLineCommentThread = function (lineComment, id) { + return this.streamThreadWithComposer({ + root: lineComment.msg.key, + id: id, + placeholder: 'reply to line comment thread' + }) } Serve.prototype.renderLineCommentForm = function (opts) { @@ -2308,6 +2322,13 @@ Serve.prototype.gitLineComment = function (path) { + '#' + file.hash[1] + '-' + c.line } var url = self.app.render.toUrl(path) + /* + return pull( + ph('a', {href: url}, path), + self.wrapPage(id), + self.respondSink(200) + ) + */ self.redirect(url) }) } @@ -2712,7 +2733,8 @@ Serve.prototype.wrapThread = function (opts) { self.app.render.prepareLinks(opts.recps, function (err, recps) { if (err) return cb(er) self.composer({ - placeholder: recps ? 'private reply' : 'reply', + placeholder: opts.placeholder + || (recps ? 'private reply' : 'reply'), id: 'reply', root: opts.root, post: opts.post, |