git ssb

16+

Dominic / patchbay



Commit 0034f4df49ad1e2e1d2c9f38974951ccce6ed265

improve invite processing

Dominic Tarr committed on 7/24/2016, 12:27:27 PM
Parent: 9e6d7abeec492c4285f15bcf6ff689c60be4062b

Files changed

modules/invite.jschanged
modules/invite.jsView
@@ -9,60 +9,69 @@
99 var plugs = require('../plugs')
1010 var sbot_publish = plugs.first(exports.sbot_publish = [])
1111
1212
13-
14-exports.screen_view = function (invite) {
15-
16- //check that invite is
17- // ws:...~shs:key:seed
18-
13 +//check that invite is
14 +// ws:...~shs:key:seed
15 +function parseMultiServerInvite (invite) {
1916 var parts = invite.split('~')
2017 .map(function (e) { return e.split(':') })
2118
2219 if(parts.length !== 2) return null
2320 if(!/^(net|wss?)$/.test(parts[0][0])) return null
2421 if(parts[1][0] !== 'shs') return null
2522 if(parts[1].length !== 3) return null
23 + var p2 = invite.split(':')
24 + p2.pop()
2625
26 + return {
27 + invite: invite,
28 + remote: p2.join(':'),
29 + }
30 +}
31 +
32 +exports.screen_view = function (invite) {
33 +
34 + var data = parseMultiServerInvite(invite)
35 + if(!data) return
36 +
2737 var progress = Progress(4)
2838
2939 //connect to server
3040 //request follow
3141 //post pub announce
3242 //post follow pub
33- var div = h('div',
34- progress,
35- h('a', 'accept', {href: '#', onclick: function (ev) {
36- ev.preventDefault()
37- ev.stopPropagation()
38- attempt()
39- return false
40- }})
43 + var div = h('div.column',
44 + h('div',
45 + "invite to:", h('br'),
46 + h('code', invite),
47 + h('button', 'accept', {onclick: function (ev) {
48 + attempt()
49 + }})
50 + ),
51 + progress
4152 )
4253
4354 function attempt () {
44- progress.next('connecting...')
55 + progress.reset().next('connecting...')
4556 ssbClient(null, {
4657 remote: invite,
4758 manifest: { invite: {use: 'async'}, getAddress: 'async' }
4859 }, function (err, sbot) {
4960 if(err) return progress.fail(err)
5061 else progress.next('requesting follow...')
5162
5263 sbot.invite.use({feed: id}, function (err, msg) {
53- if(err) return progres.fail(err)
64 + if(err) return progress.fail(err)
5465
5566 progress.next('following...')
56-
67 +
5768 //remove the seed from the shs address.
5869 //then it's correct address.
5970 //this should make the browser connect to this as remote.
6071 //we don't want to do this if when using this locally, though.
6172 if(process.title === 'browser') {
62- var p2 = invite.split(':')
63- p2.pop()
64- localStorage.remote = p2.join(':')
73 + localStorage.remote = data.remote
6574 }
6675
6776 sbot_publish({
6877 type: 'contact',
@@ -79,5 +88,4 @@
7988
8089 return div
8190 }
8291
83-

Built with git-ssb-web