From 09cf04663fe2a772d5a06bbcf86b9014dc4f5228 Mon Sep 17 00:00:00 2001 From: cel Date: Mon, 8 Jan 2018 22:03:51 -1000 Subject: Render line comments on diffs --- lib/app.js | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'lib/app.js') diff --git a/lib/app.js b/lib/app.js index 21f45a4..9166eb2 100644 --- a/lib/app.js +++ b/lib/app.js @@ -905,3 +905,78 @@ App.prototype.expandOoo = function (opts, cb) { } } } + +App.prototype.getLineComments = function (opts, cb) { + // get line comments for a git-update message and git object id. + // line comments include message id, commit id and path + // but we have message id and git object hash. + // look up the git object hash for each line-comment + // to verify that it is for the git object file we want + var updateId = opts.obj.msg.key + var objId = opts.hash + var self = this + var lineComments = {} + pull( + self.sbot.backlinks ? self.sbot.backlinks.read({ + query: [ + {$filter: { + dest: updateId, + value: { + content: { + type: 'line-comment', + updateId: updateId, + } + } + }} + ] + }) : pull( + self.sbot.links({ + dest: updateId, + rel: 'updateId', + values: true + }), + pull.filter(function (msg) { + var c = msg && msg.value && msg.value.content + return c && c.type === 'line-comment' + && c.updateId === updateId + }) + ), + paramap(function (msg, cb) { + var c = msg.value.content + self.git.getObjectAtPath({ + msg: updateId, + obj: c.commitId, + path: c.filePath, + }, function (err, info) { + if (err) return cb(err) + cb(null, { + obj: info.obj, + hash: info.hash, + msg: msg, + }) + }) + }, 4), + pull.filter(function (info) { + return info.hash === objId + }), + pull.drain(function (info) { + lineComments[info.msg.value.content.line] = info + }, function (err) { + cb(err, lineComments) + }) + ) +} + +App.prototype.getThread = function (msg) { + return cat([ + pull.once(msg), + this.sbot.backlinks ? this.sbot.backlinks.read({ + query: [ + {$filter: {dest: msg.key}} + ] + }) : this.sbot.links({ + dest: msg.key, + values: true + }) + ]) +} -- cgit v1.2.3