aboutsummaryrefslogtreecommitdiff
path: root/lib/serve.js
diff options
context:
space:
mode:
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'),