aboutsummaryrefslogtreecommitdiff
path: root/lib/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/app.js')
-rw-r--r--lib/app.js102
1 files changed, 86 insertions, 16 deletions
diff --git a/lib/app.js b/lib/app.js
index 2483357..4abd666 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -11,7 +11,7 @@ var About = require('./about')
var Follows = require('./follows')
var Serve = require('./serve')
var Render = require('./render')
-var Git = require('./git')
+var Git = require('ssb-git')
var cat = require('pull-cat')
var proc = require('child_process')
var toPull = require('stream-to-pull-stream')
@@ -32,6 +32,7 @@ function App(sbot, config) {
this.msgFilter = conf.filter
this.showPrivates = conf.showPrivates == null ? true : conf.showPrivates
this.previewVotes = conf.previewVotes == null ? false : conf.previewVotes
+ this.previewContacts = conf.previewContacts == null ? false : conf.previewContacts
this.useOoo = conf.ooo == null ? false : conf.ooo
var base = conf.base || '/'
@@ -48,9 +49,7 @@ function App(sbot, config) {
this.about = new About(this, sbot.id)
this.msgCache = lru(100)
this.getMsg = memo({cache: this.msgCache}, getMsgWithValue, sbot)
- this.getMsgOoo = sbot.ooo
- ? memo({cache: this.msgCache}, sbot.ooo.get)
- : function (id, cb) { cb(new Error('missing ssb-ooo plugin')) }
+ this.getMsgOoo = memo({cache: this.msgCache}, this.getMsgOoo)
this.getAbout = memo({cache: this.aboutCache = lru(500)},
this._getAbout.bind(this))
this.unboxContent = memo({cache: lru(100)}, sbot.private.unbox)
@@ -64,7 +63,7 @@ function App(sbot, config) {
this.unboxMsg = this.unboxMsg.bind(this)
this.render = new Render(this, this.opts)
- this.git = new Git(this)
+ this.git = new Git(this.sbot, this.config)
this.contacts = new Contacts(this.sbot)
this.follows = new Follows(this.sbot, this.contacts)
@@ -103,7 +102,7 @@ App.prototype.error = console.error.bind(console, logPrefix)
App.prototype.unboxMsg = function (msg, cb) {
var self = this
- var c = msg.value && msg.value.content
+ var c = msg && msg.value && msg.value.content
if (typeof c !== 'string') cb(null, msg)
else self.unboxContent(c, function (err, content) {
if (err) {
@@ -185,6 +184,12 @@ App.prototype.getMsgDecrypted = function (key, cb) {
})
}
+App.prototype.getMsgOoo = function (key, cb) {
+ var ooo = this.sbot.ooo
+ if (!ooo) return cb(new Error('missing ssb-ooo plugin'))
+ ooo.get(key, cb)
+}
+
App.prototype.getMsgDecryptedOoo = function (key, cb) {
var self = this
this.getMsgOoo(key, function (err, msg) {
@@ -347,16 +352,6 @@ function getMsgWithValue(sbot, id, cb) {
})
}
-function getMsgOooWithValueCreate(sbot) {
- if (!sbot.ooo) {
- var err = new Error('missing ssb-ooo plugin')
- return function (id, cb) {
- cb(null, err)
- }
- }
- return sbot.ooo.get
-}
-
App.prototype._getAbout = function (id, cb) {
var self = this
if (!u.isRef(id)) return cb(null, {})
@@ -911,3 +906,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
+ })
+ ])
+}