From b705fe62e350ac3087feb811b0390c7fd2f9a20f Mon Sep 17 00:00:00 2001 From: cel Date: Mon, 28 Jan 2019 23:30:51 -1000 Subject: Move pub addresses out of profile page --- lib/app.js | 40 ++++++++++++++++++++++++++++++++++++++++ lib/serve.js | 43 +++++++++++++++++++++++++++++++------------ 2 files changed, 71 insertions(+), 12 deletions(-) (limited to 'lib') 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) + ) +} -- cgit v1.2.3