diff options
-rw-r--r-- | lib/app.js | 17 | ||||
-rw-r--r-- | lib/render-msg.js | 8 | ||||
-rw-r--r-- | lib/serve.js | 3 | ||||
-rw-r--r-- | lib/util.js | 12 |
4 files changed, 25 insertions, 15 deletions
@@ -43,6 +43,7 @@ function App(sbot, config) { this.previewContacts = conf.previewContacts == null ? false : conf.previewContacts this.useOoo = conf.ooo == null ? false : conf.ooo this.ssbPort = 8008 + this.portRegexp = new RegExp(':' + this.ssbPort + '$') /* var capsConfig = config.caps || {} this.userInviteCap = capsConfig.userInvite @@ -1053,17 +1054,7 @@ App.prototype.getAddresses = function (id) { ] }) ]), - pull.map(function (addr) { - var i = addr.lastIndexOf(':' + id) - if (i > -1 && addr.length === i + id.length + 1) { - return addr.substr(0, i) - } - var m = /^(?:net|onion):([^~;]*:[0-9]*)~shs:([0-9a-zA-Z/=+]{44})/.exec(addr) - if (m && id === '@' + m[2] + '.ed25519') { - return m[1] - } - return addr - }) + pull.map(u.extractHostPort.bind(this, id)) ) return pull( @@ -1487,3 +1478,7 @@ App.prototype.listDrafts = function () { }) }) } + +App.prototype.removeDefaultPort = function (addr) { + return addr.replace(this.portRegexp, '') +} diff --git a/lib/render-msg.js b/lib/render-msg.js index 357edbe..09c9e13 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -757,6 +757,8 @@ RenderMsg.prototype.pub = function (cb) { RenderMsg.prototype.address = function (cb) { var availability = this.c.availability * 100 + var addr = u.extractHostPort(this.value.author, String(this.c.address)) + addr = this.app.removeDefaultPort(addr) this.wrapMini([ 'has address', !isNaN(availability) ? [ @@ -764,7 +766,7 @@ RenderMsg.prototype.address = function (cb) { h('code', availability + '%') ] : '', ': ', - h('input', {disabled: 'disabled', value: String(this.c.address), style: 'width:100%'}), + h('input', {disabled: 'disabled', value: addr, style: 'width:100%; font:monospace'}), ], cb) } @@ -779,12 +781,14 @@ RenderMsg.prototype.pubOwnerAnnounce = function (cb) { RenderMsg.prototype.pubOwnerConfirm = function (cb) { var self = this var announcement = this.c.announcement + var addr = u.extractHostPort(this.value.author, String(this.c.address)) + addr = this.app.removeDefaultPort(addr) this.wrap([ 'confirms pub ownership announcement ', h('a', {href: this.toUrl(announcement)}, u.truncate(announcement, 10)), this.c.address ? [ '. address: ', - h('input', {disabled: 'disabled', value: String(this.c.address), style: 'width:100%'}) + h('input', {disabled: 'disabled', value: addr, style: 'width:100%; font:monospace'}) ] : '' ], cb) } diff --git a/lib/serve.js b/lib/serve.js index d92117e..a3082c6 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -4208,7 +4208,6 @@ Serve.prototype.pub = function (path) { var id = String(path).substr(1) try { id = decodeURIComponent(id) } catch(e) {} - var portRegexp = new RegExp(':' + self.app.ssbPort + '$') pull( ph('section', [ ph('h3', ['Pub addresses: ', self.phIdLink(id)]), @@ -4216,7 +4215,7 @@ Serve.prototype.pub = function (path) { self.app.getAddresses(id), pull.map(function (address) { return ph('div', [ - ph('code', address.replace(portRegexp, '')) + ph('code', self.app.removeDefaultPort(address)) ]) }) ) diff --git a/lib/util.js b/lib/util.js index 4fdbc24..731cc82 100644 --- a/lib/util.js +++ b/lib/util.js @@ -266,3 +266,15 @@ u.truncate = function (str, len) { str = String(str) return str.length > len ? str.substr(0, len) + '...' : str } + +u.extractHostPort = function (id, addr) { + var i = addr.lastIndexOf(':' + id) + if (i > -1 && addr.length === i + id.length + 1) { + return addr.substr(0, i) + } + var m = /^(?:net|onion):([^~;]*(?::[0-9]*)?)~shs:([0-9a-zA-Z/=+]{44})$/.exec(addr) + if (m && id === '@' + m[2] + '.ed25519') { + return m[1] + } + return addr +} |