diff options
Diffstat (limited to 'lib/about.js')
-rw-r--r-- | lib/about.js | 93 |
1 files changed, 53 insertions, 40 deletions
diff --git a/lib/about.js b/lib/about.js index e1c6b40..4605c4b 100644 --- a/lib/about.js +++ b/lib/about.js @@ -5,9 +5,10 @@ var u = require('./util') module.exports = About -function About(app, myId) { +function About(app, myId, follows) { this.app = app this.myId = myId + this.follows = follows } About.prototype.createAboutOpStream = function (id) { @@ -78,45 +79,57 @@ function computeTopAbout(aboutByFeed) { About.prototype.get = function (dest, cb) { var self = this + var myAbout = [] var aboutByFeed = {} - pull( - cat([ - dest[0] === '%' && self.app.pullGetMsg(dest), - self.app.sbot.links({ - rel: 'about', - dest: dest, - values: true, + var aboutByFeedFollowed = {} + this.follows.getFollows(this.myId, function (err, follows) { + if (err) return cb(err) + pull( + cat([ + dest[0] === '%' && self.app.pullGetMsg(dest), + self.app.sbot.links({ + rel: 'about', + dest: dest, + values: true, + }) + ]), + self.app.unboxMessages(), + pull.drain(function (msg) { + var author = msg.value.author + var c = msg.value.content + if (!c) return + if (msg.key === dest && c.type === 'about') { + // don't describe an about message with itself + return + } + var about = author === self.myId ? myAbout : + follows[author] ? + aboutByFeedFollowed[author] || (aboutByFeedFollowed[author] = {}) : + aboutByFeed[author] || (aboutByFeed[author] = {}) + + if (c.name) about.name = c.name + if (c.title) about.title = c.title + if (c.image) { + about.image = u.linkDest(c.image) + about.imageLink = u.toLink(c.image) + } + if (c.description) about.description = c.description + if (c.publicWebHosting) about.publicWebHosting = c.publicWebHosting + }, function (err) { + if (err) return cb(err) + // bias the author's choices by giving them an extra vote + if (follows[dest]) aboutByFeedFollowed._author = aboutByFeedFollowed[dest] + else aboutByFeed._author = aboutByFeed[dest] + var about = {} + var followedAbout = computeTopAbout(aboutByFeedFollowed) + var topAbout = computeTopAbout(aboutByFeed) + for (var k in topAbout) about[k] = topAbout[k] + // prefer followed feeds' choices + for (var k in followedAbout) about[k] = followedAbout[k] + // always prefer own choices + for (var k in myAbout) about[k] = myAbout[k] + cb(null, about) }) - ]), - self.app.unboxMessages(), - pull.drain(function (msg) { - var author = msg.value.author - var c = msg.value.content - if (!c) return - if (msg.key === dest && c.type === 'about') { - // don't describe an about message with itself - return - } - var about = aboutByFeed[author] || (aboutByFeed[author] = {}) - if (c.name) about.name = c.name - if (c.title) about.title = c.title - if (c.image) { - about.image = u.linkDest(c.image) - about.imageLink = u.toLink(c.image) - } - if (c.description) about.description = c.description - if (c.publicWebHosting) about.publicWebHosting = c.publicWebHosting - }, function (err) { - if (err) return cb(err) - // bias the author's choices by giving them an extra vote - aboutByFeed._author = aboutByFeed[dest] - var about = {} - var myAbout = aboutByFeed[self.myId] || {} - var topAbout = computeTopAbout(aboutByFeed) - for (var k in topAbout) about[k] = topAbout[k] - // always prefer own choices - for (var k in myAbout) about[k] = myAbout[k] - cb(null, about) - }) - ) + ) + }) } |