aboutsummaryrefslogtreecommitdiff
path: root/lib/serve.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-04-18 20:10:16 -0700
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-04-18 20:10:16 -0700
commita5ae107c74256ca7494ccecc7d94dc35638d231e (patch)
tree1a021d26a1bda95248080291bbe4c060e966de8f /lib/serve.js
parent76464ec017ccaad2d94591c08c91dd770b2f5154 (diff)
downloadpatchfoo-a5ae107c74256ca7494ccecc7d94dc35638d231e.tar.gz
patchfoo-a5ae107c74256ca7494ccecc7d94dc35638d231e.zip
Add contacts pages
Diffstat (limited to 'lib/serve.js')
-rw-r--r--lib/serve.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/serve.js b/lib/serve.js
index 4b0d58d..68eebda 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -18,6 +18,7 @@ var Busboy = require('busboy')
var mime = require('mime-types')
var ident = require('pull-identify-filetype')
var htime = require('human-time')
+var ph = require('pull-hyperscript')
module.exports = Serve
@@ -230,6 +231,7 @@ Serve.prototype.path = function (url) {
case '/links': return this.links(m[2])
case '/static': return this.static(m[2])
case '/emoji': return this.emoji(m[2])
+ case '/contacts': return this.contacts(m[2])
}
return this.respond(404, 'Not found')
}
@@ -424,6 +426,53 @@ Serve.prototype.channels = function (ext) {
)
}
+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)
+ )
+ }
+
+ function idLink(id) {
+ return pull(
+ pull.once(id),
+ pull.asyncMap(self.renderIdLink.bind(self)),
+ pull.map(u.toHTML)
+ )
+ }
+
+ pull(
+ cat([
+ ph('section', {}, [
+ ph('h3', {}, ['Contacts: ', idLink(id)]),
+ ph('h4', {}, 'Friends'),
+ renderFriendsList()(contacts.friends),
+ ph('h4', {}, 'Follows'),
+ renderFriendsList()(contacts.follows),
+ ph('h4', {}, 'Followers'),
+ renderFriendsList()(contacts.followers)
+ ])
+ ]),
+ this.wrapPage('contacts: ' + id),
+ this.respondSink(200, {
+ 'Content-Type': ctype('html')
+ })
+ )
+}
Serve.prototype.type = function (path) {
var q = this.query
@@ -892,6 +941,7 @@ var relationshipActions = [
Serve.prototype.wrapUserFeed = function (isScrolled, id) {
var self = this
var myId = self.app.sbot.id
+ var render = self.app.render
return u.hyperwrap(function (thread, cb) {
var done = multicb({pluck: 1, spread: true})
self.app.getAbout(id, done())
@@ -912,6 +962,12 @@ Serve.prototype.wrapUserFeed = function (isScrolled, id) {
about.description ? h('div',
{innerHTML: self.app.render.markdown(about.description)}) : ''
)),
+ h('tr',
+ h('td'),
+ h('td',
+ h('a', {href: render.toUrl('/contacts/' + id)}, 'contacts')
+ )
+ ),
isScrolled ? '' : [
id === myId ? '' : h('tr',
h('td'),