aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-01-28 23:30:51 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-01-29 00:20:15 -1000
commitb705fe62e350ac3087feb811b0390c7fd2f9a20f (patch)
treebd425a924efe2764d0f1d6bfcabe19cc20bd73aa
parent304dc21333457363ea79c035ce9115d48ecc9855 (diff)
downloadpatchfoo-b705fe62e350ac3087feb811b0390c7fd2f9a20f.tar.gz
patchfoo-b705fe62e350ac3087feb811b0390c7fd2f9a20f.zip
Move pub addresses out of profile page
-rw-r--r--lib/app.js40
-rw-r--r--lib/serve.js43
2 files changed, 71 insertions, 12 deletions
diff --git a/lib/app.js b/lib/app.js
index 3b56da7..bac3d53 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -977,6 +977,46 @@ App.prototype.getAddresses = function (id) {
)
}
+App.prototype.isPub = function (id, cb) {
+ if (!this.sbot.backlinks) {
+ return pull(
+ this.sbot.links({
+ dest: id,
+ rel: 'pub'
+ }),
+ pull.take(1),
+ pull.collect(function (err, links) {
+ if (err) return cb(err)
+ cb(null, links.length == 1)
+ })
+ )
+ }
+ return pull(
+ this.sbot.backlinks.read({
+ limit: 1,
+ query: [
+ {$filter: {
+ dest: id,
+ value: {
+ content: {
+ type: 'pub',
+ address: {
+ key: id,
+ host: {$truthy: true},
+ port: {$truthy: true},
+ }
+ }
+ }
+ }}
+ ]
+ }),
+ pull.collect(function (err, msgs) {
+ if (err) return cb(err)
+ cb(null, msgs.length == 1)
+ })
+ )
+}
+
App.prototype.getIdeaTitle = function (id, cb) {
if (!this.sbot.backlinks) return cb(null, String(id).substr(0, 8) + '…')
pull(
diff --git a/lib/serve.js b/lib/serve.js
index 810b887..61e34da 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -400,6 +400,7 @@ Serve.prototype.path = function (url) {
case '/highlight': return this.highlight(m[2])
case '/contacts': return this.contacts(m[2])
case '/about': return this.about(m[2])
+ case '/pub': return this.pub(m[2])
case '/git': return this.git(m[2])
case '/image': return this.image(m[2])
case '/npm': return this.npm(m[2])
@@ -1878,24 +1879,20 @@ Serve.prototype.wrapUserFeed = function (isScrolled, id) {
self.aboutDescription(id)
])
]),
- isScrolled ? '' : ph('tr', [
- ph('td'),
- ph('td', pull(
- self.app.getAddresses(id),
- pull.map(function (address) {
- return ph('div', [
- ph('code', address)
- ])
- })
- ))
- ]),
ph('tr', [
ph('td'),
ph('td', [
ph('a', {href: render.toUrl('/contacts/' + id)}, 'contacts'), ' ',
ph('a', {href: render.toUrl('/about/' + id)}, 'about'),
id === myId ? [' ',
- ph('a', {href: render.toUrl('/about-self')}, 'about-self')] : ''
+ ph('a', {href: render.toUrl('/about-self')}, 'about-self')] : '',
+ !isScrolled ? u.readNext(function (cb) {
+ self.app.isPub(id, function (err, isPub) {
+ if (err) return cb(err)
+ if (!isPub) return cb(null, pull.empty())
+ cb(null, ph('span', [' ', ph('a', {href: render.toUrl('/pub/' + id)}, 'pub')]))
+ })
+ }) : ''
])
]),
ph('tr', [
@@ -4126,3 +4123,25 @@ Serve.prototype.shard = function (url) {
)
})
}
+
+Serve.prototype.pub = function (path) {
+ var self = this
+ var id = String(path).substr(1)
+ try { id = decodeURIComponent(id) }
+ catch(e) {}
+ pull(
+ ph('section', [
+ ph('h3', ['Pub addresses: ', self.phIdLink(id)]),
+ pull(
+ self.app.getAddresses(id),
+ pull.map(function (address) {
+ return ph('div', [
+ ph('code', address)
+ ])
+ })
+ )
+ ]),
+ self.wrapPage('Block ' + id),
+ self.respondSink(200)
+ )
+}