From 00885846f2c98059a4b95b2d18b4a4a8f22f7901 Mon Sep 17 00:00:00 2001 From: cel Date: Tue, 5 Dec 2017 14:33:53 -0800 Subject: List friends following feed --- lib/app.js | 5 +---- lib/render.js | 18 ++++++++++++++++ lib/serve.js | 61 +++++++++++++++++++++++++++++++------------------------ package-lock.json | 4 ++-- package.json | 2 +- 5 files changed, 57 insertions(+), 33 deletions(-) diff --git a/lib/app.js b/lib/app.js index da41459..643b317 100644 --- a/lib/app.js +++ b/lib/app.js @@ -56,6 +56,7 @@ function App(sbot, config) { this.render = new Render(this, this.opts) this.git = new Git(this) + this.contacts = new Contacts(this.sbot) this.monitorBlobWants() } @@ -464,10 +465,6 @@ App.prototype.streamMyChannels = function (id, opts) { ) } -App.prototype.createContactStreams = function (id) { - return new Contacts(this.sbot).createContactStreams(id) -} - function compareVoted(a, b) { return b.value - a.value } diff --git a/lib/render.js b/lib/render.js index ed011bb..95c8c50 100644 --- a/lib/render.js +++ b/lib/render.js @@ -562,3 +562,21 @@ Render.prototype.npmPrebuildMention = function (link, opts, cb) { ])) }) } + +Render.prototype.friendsList = function (prefix) { + prefix = prefix || '/' + var self = this + return pull( + paramap(function (id, cb) { + self.app.getAbout(id, function (err, about) { + var name = about && about.name || id.substr(0, 8) + '…' + cb(null, h('a', {href: self.toUrl(prefix + id)}, name)) + }) + }, 8), + pull.map(function (el) { + return [el, ' '] + }), + pull.flatten(), + pull.map(u.toHTML) + ) +} diff --git a/lib/serve.js b/lib/serve.js index 5b6aeff..c100f40 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -794,41 +794,29 @@ Serve.prototype.channels = function (ext) { ) } +function renderFriendsList(app) { +} + Serve.prototype.contacts = function (path) { var self = this var id = String(path).substr(1) - var contacts = self.app.createContactStreams(id) - - function renderFriendsList() { - return pull( - paramap(function (id, cb) { - self.app.getAbout(id, function (err, about) { - var name = about && about.name || id.substr(0, 8) + '…' - cb(null, h('a', {href: self.app.render.toUrl('/contacts/' + id)}, name)) - }) - }, 8), - pull.map(function (el) { - return [el, ' '] - }), - pull.flatten(), - pull.map(u.toHTML) - ) - } + var contacts = self.app.contacts.createContactStreams(id) + var render = self.app.render pull( cat([ ph('section', {}, [ ph('h3', {}, ['Contacts: ', self.phIdLink(id)]), ph('h4', {}, 'Friends'), - renderFriendsList()(contacts.friends), + render.friendsList('/contacts/')(contacts.friends), ph('h4', {}, 'Follows'), - renderFriendsList()(contacts.follows), + render.friendsList('/contacts/')(contacts.follows), ph('h4', {}, 'Followers'), - renderFriendsList()(contacts.followers), + render.friendsList('/contacts/')(contacts.followers), ph('h4', {}, 'Blocks'), - renderFriendsList()(contacts.blocks), + render.friendsList('/contacts/')(contacts.blocks), ph('h4', {}, 'Blocked by'), - renderFriendsList()(contacts.blockers) + render.friendsList('/contacts/')(contacts.blockers) ]) ]), this.wrapPage('contacts: ' + id), @@ -1537,6 +1525,21 @@ Serve.prototype.followInfo = function (id, myId) { }) } +Serve.prototype.friendInfo = function (id, myId) { + var first = false + return pull( + this.app.contacts.createFollowedFollowersStream(myId, id), + this.app.render.friendsList(), + pull.map(function (html) { + if (!first) { + first = true + return 'followed by your friends: ' + html + } + return html + }) + ) +} + Serve.prototype.wrapUserFeed = function (isScrolled, id) { var self = this var myId = self.app.sbot.id @@ -1581,10 +1584,16 @@ Serve.prototype.wrapUserFeed = function (isScrolled, id) { ]) ) ]), - isScrolled || id === myId ? '' : ph('tr', [ - ph('td'), - ph('td', {class: 'follow-info'}, self.followInfo(id, myId)) - ]) + isScrolled || id === myId ? '' : [ + ph('tr', [ + ph('td'), + ph('td', {class: 'follow-info'}, self.followInfo(id, myId)) + ]), + ph('tr', [ + ph('td'), + ph('td', self.friendInfo(id, myId)) + ]) + ] ])), thread ]) diff --git a/package-lock.json b/package-lock.json index 00a0bcb..565964a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1054,8 +1054,8 @@ } }, "ssb-contact": { - "version": "1.1.0", - "resolved": "http://localhost:8989/blobs/get/&wU1gwlBbfFf8KL1Y+gBAYi7WapYmN2fg8ODKTpvfcbM=.sha256", + "version": "1.2.0", + "resolved": "http://localhost:8989/blobs/get/&V4bNrv533a7pKfPxw7Ok92hNWBN+eCbyybmi8cGMzrM=.sha256", "requires": { "pull-defer": "0.2.2", "pull-many": "1.0.8", diff --git a/package.json b/package.json index 2dabe70..8f4f503 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "pull-reader": "^1.2.9", "pull-stream": "^3.5.0", "ssb-client": "http://localhost:8989/blobs/get/&EAaUpI+wrJM5/ly1RqZW0GAEF4PmCAmABBj7e6UIrL0=.sha256", - "ssb-contact": "^1.1.0", + "ssb-contact": "^1.2.0", "ssb-marked": "^0.7.1", "ssb-mentions": "http://localhost:8989/blobs/get/&GKwsJ3ykvOXc24wyNuWBdmnCFpQ+Ltd9ggjoOuOF/Pg=.sha256", "ssb-sort": "^1.0.0", -- cgit v1.2.3