aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-10-28 14:17:41 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-10-28 14:17:41 -1000
commit80435e39321a8a5aef016c2d73f0580ab05d6708 (patch)
tree53b775ad83a0976e5d5fc18ba5158c8b30445377 /lib
parent04ddfa4303f4622f80128dad2dc84a7a30e73f67 (diff)
downloadpatchfoo-80435e39321a8a5aef016c2d73f0580ab05d6708.tar.gz
patchfoo-80435e39321a8a5aef016c2d73f0580ab05d6708.zip
Let About info from feeds we follow take precedence
over About info from feeds we do not follow
Diffstat (limited to 'lib')
-rw-r--r--lib/about.js93
-rw-r--r--lib/app.js2
2 files changed, 54 insertions, 41 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)
- })
- )
+ )
+ })
}
diff --git a/lib/app.js b/lib/app.js
index ed936ec..fa26b25 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -50,7 +50,6 @@ function App(sbot, config) {
codeInTextareas: conf.codeInTextareas,
}
- this.about = new About(this, sbot.id)
this.msgCache = lru(100)
this.getMsg = memo({cache: this.msgCache}, getMsgWithValue, sbot)
this.getMsgOoo = memo({cache: this.msgCache}, this.getMsgOoo)
@@ -70,6 +69,7 @@ function App(sbot, config) {
this.git = new Git(this.sbot, this.config)
this.contacts = new Contacts(this.sbot)
this.follows = new Follows(this.sbot, this.contacts)
+ this.about = new About(this, sbot.id, this.follows)
this.serveSsbNpmRegistry = SsbNpmRegistry.respond(this.sbot, this.config)
this.monitorBlobWants()