modules/invite.jsView |
---|
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 | | - |
17 | | - |
18 | | - |
| 13 | + |
| 14 | + |
| 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 | |
30 | 40 | |
31 | 41 | |
32 | 42 | |
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...') |
| 56 | + |
45 | 57 | ssbClient(null, { |
46 | 58 | remote: invite, |
47 | 59 | manifest: { invite: {use: 'async'}, getAddress: 'async' } |
48 | 60 | }, function (err, sbot) { |
49 | 61 | if(err) return progress.fail(err) |
50 | | - else progress.next('requesting follow...') |
| 62 | + progress.next('requesting follow...') |
51 | 63 | |
52 | 64 | sbot.invite.use({feed: id}, function (err, msg) { |
53 | | - if(err) return progres.fail(err) |
| 65 | + if(err) return progress.fail(err) |
| 66 | + progress.next('following...') |
54 | 67 | |
55 | | - progress.next('following...') |
56 | | - |
57 | 68 | |
58 | 69 | |
59 | 70 | |
60 | 71 | |
61 | | - if(process.title === 'browser') { |
62 | | - var p2 = invite.split(':') |
63 | | - p2.pop() |
64 | | - localStorage.remote = p2.join(':') |
65 | | - } |
| 72 | + if(process.title === 'browser') |
| 73 | + localStorage.remote = data.remote |
66 | 74 | |
67 | 75 | sbot_publish({ |
68 | 76 | type: 'contact', |
69 | 77 | contact: sbot.id, |
79 | 87 | |
80 | 88 | return div |
81 | 89 | } |
82 | 90 | |
83 | | - |