aboutsummaryrefslogtreecommitdiff
path: root/lib/serve.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/serve.js')
-rw-r--r--lib/serve.js108
1 files changed, 85 insertions, 23 deletions
diff --git a/lib/serve.js b/lib/serve.js
index 4fe3cd6..9296c46 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -26,16 +26,6 @@ var emojiDir = path.join(require.resolve('emoji-named-characters'), '../pngs')
var urlIdRegex = /^(?:\/+(([%&@]|%25)(?:[A-Za-z0-9\/+]|%2[Ff]|%2[Bb]){43}(?:=|%3D)\.(?:sha256|ed25519))(?:\.([^?]*))?|(\/.*?))(?:\?(.*))?$/
-function isMsgEncrypted(msg) {
- var c = msg && msg.value.content
- return typeof c === 'string'
-}
-
-function isMsgReadable(msg) {
- var c = msg && msg.value && msg.value.content
- return typeof c === 'object' && c !== null
-}
-
function ctype(name) {
switch (name && /[^.\/]*$/.exec(name)[0] || 'html') {
case 'html': return 'text/html'
@@ -250,6 +240,7 @@ Serve.prototype.path = function (url) {
case '/static': return this.static(m[2])
case '/emoji': return this.emoji(m[2])
case '/contacts': return this.contacts(m[2])
+ case '/about': return this.about(m[2])
}
return this.respond(404, 'Not found')
}
@@ -349,9 +340,9 @@ Serve.prototype.private = function (ext) {
pull(
this.app.createLogStream(opts),
- pull.filter(isMsgEncrypted),
+ pull.filter(u.isMsgEncrypted),
this.app.unboxMessages(),
- pull.filter(isMsgReadable),
+ pull.filter(u.isMsgReadable),
pull.take(limit),
this.renderThreadPaginated(opts, null, q),
this.wrapMessages(),
@@ -549,6 +540,14 @@ Serve.prototype.channels = function (ext) {
)
}
+Serve.prototype.phIdLink = function (id) {
+ return pull(
+ pull.once(id),
+ pull.asyncMap(this.renderIdLink.bind(this)),
+ pull.map(u.toHTML)
+ )
+}
+
Serve.prototype.contacts = function (path) {
var self = this
var id = String(path).substr(1)
@@ -570,18 +569,10 @@ Serve.prototype.contacts = function (path) {
)
}
- 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('h3', {}, ['Contacts: ', self.phIdLink(id)]),
ph('h4', {}, 'Friends'),
renderFriendsList()(contacts.friends),
ph('h4', {}, 'Follows'),
@@ -597,9 +588,79 @@ Serve.prototype.contacts = function (path) {
)
}
+Serve.prototype.about = function (path) {
+ var self = this
+ var id = decodeURIComponent(String(path).substr(1))
+ var abouts = self.app.createAboutStreams(id)
+ var render = self.app.render
+
+ function renderAboutOpImage(link) {
+ if (!link) return
+ if (!u.isRef(link.link)) return ph('code', {}, JSON.stringify(link))
+ return ph('img', {
+ class: 'ssb-avatar-image',
+ src: render.imageUrl(link.link),
+ alt: link.link
+ + (link.size ? ' (' + render.formatSize(link.size) + ')' : '')
+ })
+ }
+
+ function renderAboutOpValue(value) {
+ if (!value) return
+ if (u.isRef(value.link)) return self.phIdLink(value.link)
+ if (value.epoch) return new Date(value.epoch).toUTCString()
+ return ph('code', {}, JSON.stringify(value))
+ }
+
+ function renderAboutOpContent(op) {
+ if (op.prop === 'image')
+ return renderAboutOpImage(op.value)
+ if (op.prop === 'description')
+ return h('div', {innerHTML: render.markdown(op.value)}).outerHTML
+ if (op.prop === 'title')
+ return h('strong', op.value).outerHTML
+ if (op.prop === 'name')
+ return h('u', op.value).outerHTML
+ return renderAboutOpValue(op.value)
+ }
+
+ function renderAboutOp(op) {
+ return ph('tr', {}, [
+ ph('td', self.phIdLink(op.author)),
+ ph('td',
+ ph('a', {href: render.toUrl(op.id)},
+ htime(new Date(op.timestamp)))),
+ ph('td', op.prop),
+ ph('td', renderAboutOpContent(op))
+ ])
+ }
+
+ pull(
+ cat([
+ ph('section', {}, [
+ ph('h3', {}, ['About: ', self.phIdLink(id)]),
+ ph('table', {},
+ pull(abouts.scalars, pull.map(renderAboutOp))
+ ),
+ pull(
+ abouts.sets,
+ pull.map(function (op) {
+ return h('pre', JSON.stringify(op, 0, 2))
+ }),
+ pull.map(u.toHTML)
+ )
+ ])
+ ]),
+ this.wrapPage('about: ' + id),
+ this.respondSink(200, {
+ 'Content-Type': ctype('html')
+ })
+ )
+}
+
Serve.prototype.type = function (path) {
var q = this.query
- var type = path.substr(1)
+ var type = decodeURIComponent(path.substr(1))
var opts = {
reverse: !q.forwards,
lt: Number(q.lt) || Date.now(),
@@ -1096,7 +1157,8 @@ Serve.prototype.wrapUserFeed = function (isScrolled, id) {
h('tr',
h('td'),
h('td',
- h('a', {href: render.toUrl('/contacts/' + id)}, 'contacts')
+ h('a', {href: render.toUrl('/contacts/' + id)}, 'contacts'), ' ',
+ h('a', {href: render.toUrl('/about/' + id)}, 'about')
)
),
h('tr',