From 76464ec017ccaad2d94591c08c91dd770b2f5154 Mon Sep 17 00:00:00 2001 From: cel Date: Tue, 18 Apr 2017 20:10:01 -0700 Subject: Add friends page --- lib/serve.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) 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', -- cgit v1.2.3