Commit 0034f4df49ad1e2e1d2c9f38974951ccce6ed265
improve invite processing
Dominic Tarr committed on 7/24/2016, 12:27:27 PMParent: 9e6d7abeec492c4285f15bcf6ff689c60be4062b
Files changed
modules/invite.js | changed |
modules/invite.js | ||
---|---|---|
@@ -9,60 +9,69 @@ | ||
9 | 9 … | var plugs = require('../plugs') |
10 | 10 … | var sbot_publish = plugs.first(exports.sbot_publish = []) |
11 | 11 … | |
12 | 12 … | |
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) { | |
19 | 16 … | var parts = invite.split('~') |
20 | 17 … | .map(function (e) { return e.split(':') }) |
21 | 18 … | |
22 | 19 … | if(parts.length !== 2) return null |
23 | 20 … | if(!/^(net|wss?)$/.test(parts[0][0])) return null |
24 | 21 … | if(parts[1][0] !== 'shs') return null |
25 | 22 … | if(parts[1].length !== 3) return null |
23 … | + var p2 = invite.split(':') | |
24 … | + p2.pop() | |
26 | 25 … | |
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 … | + | |
27 | 37 … | var progress = Progress(4) |
28 | 38 … | |
29 | 39 … | //connect to server |
30 | 40 … | //request follow |
31 | 41 … | //post pub announce |
32 | 42 … | //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 | |
41 | 52 … | ) |
42 | 53 … | |
43 | 54 … | function attempt () { |
44 | - progress.next('connecting...') | |
55 … | + progress.reset().next('connecting...') | |
45 | 56 … | ssbClient(null, { |
46 | 57 … | remote: invite, |
47 | 58 … | manifest: { invite: {use: 'async'}, getAddress: 'async' } |
48 | 59 … | }, function (err, sbot) { |
49 | 60 … | if(err) return progress.fail(err) |
50 | 61 … | else progress.next('requesting follow...') |
51 | 62 … | |
52 | 63 … | sbot.invite.use({feed: id}, function (err, msg) { |
53 | - if(err) return progres.fail(err) | |
64 … | + if(err) return progress.fail(err) | |
54 | 65 … | |
55 | 66 … | progress.next('following...') |
56 | - | |
67 … | + | |
57 | 68 … | //remove the seed from the shs address. |
58 | 69 … | //then it's correct address. |
59 | 70 … | //this should make the browser connect to this as remote. |
60 | 71 … | //we don't want to do this if when using this locally, though. |
61 | 72 … | if(process.title === 'browser') { |
62 | - var p2 = invite.split(':') | |
63 | - p2.pop() | |
64 | - localStorage.remote = p2.join(':') | |
73 … | + localStorage.remote = data.remote | |
65 | 74 … | } |
66 | 75 … | |
67 | 76 … | sbot_publish({ |
68 | 77 … | type: 'contact', |
@@ -79,5 +88,4 @@ | ||
79 | 88 … | |
80 | 89 … | return div |
81 | 90 … | } |
82 | 91 … | |
83 | - |
Built with git-ssb-web