diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-04-18 20:10:01 -0700 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-04-18 20:10:01 -0700 |
commit | 76464ec017ccaad2d94591c08c91dd770b2f5154 (patch) | |
tree | b482644e3755897ef0a80bd2d9b8a93ac2e8ee64 /lib/serve.js | |
parent | eafabeace539c170554940859f678cbdea8db8cd (diff) | |
download | patchfoo-76464ec017ccaad2d94591c08c91dd770b2f5154.tar.gz patchfoo-76464ec017ccaad2d94591c08c91dd770b2f5154.zip |
Add friends page
Diffstat (limited to 'lib/serve.js')
-rw-r--r-- | lib/serve.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/serve.js b/lib/serve.js index b87f304..4b0d58d 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -222,6 +222,7 @@ Serve.prototype.path = function (url) { case '/vote': return this.vote(m[2]) case '/peers': return this.peers(m[2]) case '/channels': return this.channels(m[2]) + case '/friends': return this.friends(m[2]) } m = /^(\/?[^\/]*)(\/.*)?$/.exec(url) switch (m[1]) { @@ -811,6 +812,7 @@ Serve.prototype.wrapPage = function (title, searchQ) { h('a', {href: render.toUrl('/private')}, 'private') , ' ', h('a', {href: render.toUrl('/peers')}, 'peers') , ' ', h('a', {href: render.toUrl('/channels')}, 'channels') , ' ', + h('a', {href: render.toUrl('/friends')}, 'friends'), ' ', render.idLink(self.app.sbot.id, done()), ' ', h('input.search-input', {name: 'q', value: searchQ, placeholder: 'search'}) @@ -829,6 +831,50 @@ Serve.prototype.wrapPage = function (title, searchQ) { ) } +Serve.prototype.renderIdLink = function (id, cb) { + var render = this.app.render + var el = render.idLink(id, function (err) { + if (err || !el) { + el = h('a', {href: render.toUrl(id)}, id) + } + cb(null, el) + }) +} + +Serve.prototype.friends = function (path) { + var self = this + pull( + self.app.sbot.friends.createFriendStream({hops: 1}), + self.renderFriends(), + pull.map(function (el) { + return [el, ' '] + }), + pull.map(u.toHTML), + u.hyperwrap(function (items, cb) { + cb(null, [ + h('section', + h('h3', 'Friends') + ), + h('section', items) + ]) + }), + this.wrapPage('friends'), + this.respondSink(200, { + 'Content-Type': ctype('html') + }) + ) +} + +Serve.prototype.renderFriends = function () { + var self = this + return paramap(function (id, cb) { + self.renderIdLink(id, function (err, el) { + if (err) el = u.renderError(err, ext) + cb(null, el) + }) + }, 8) +} + var relationships = [ '', 'followed', |