Commit 1a4ccb4dc20d081f7f29e659e14b850e48e14a96
fix bugs in invite codes, redirect properly
Dominic Tarr committed on 7/30/2016, 4:08:02 AMParent: e257f2546f229a035921db80e8d18ba65b25c615
Files changed
modules/invite.js | changed |
modules/invite.js | ||
---|---|---|
@@ -12,9 +12,12 @@ | ||
12 | 12 | |
13 | 13 | //check that invite is |
14 | 14 | // ws:...~shs:key:seed |
15 | 15 | function parseMultiServerInvite (invite) { |
16 | - var parts = invite.split('~') | |
16 | + var redirect = invite.split('#') | |
17 | + if(!redirect.length) return null | |
18 | + | |
19 | + var parts = redirect[0].split('~') | |
17 | 20 | .map(function (e) { return e.split(':') }) |
18 | 21 | |
19 | 22 | if(parts.length !== 2) return null |
20 | 23 | if(!/^(net|wss?)$/.test(parts[0][0])) return null |
@@ -23,10 +26,11 @@ | ||
23 | 26 | var p2 = invite.split(':') |
24 | 27 | p2.pop() |
25 | 28 | |
26 | 29 | return { |
27 | - invite: invite, | |
30 | + invite: redirect[0], | |
28 | 31 | remote: p2.join(':'), |
32 | + redirect: '#' + redirect.slice(1).join('#') | |
29 | 33 | } |
30 | 34 | } |
31 | 35 | |
32 | 36 | exports.screen_view = function (invite) { |
@@ -42,9 +46,9 @@ | ||
42 | 46 | //post follow pub |
43 | 47 | var div = h('div.column', |
44 | 48 | h('div', |
45 | 49 | "you have been invited to join:", h('br'), |
46 | - h('code', invite) | |
50 | + h('code', data.invite) | |
47 | 51 | ), |
48 | 52 | h('button', 'accept', {onclick: attempt}), |
49 | 53 | progress |
50 | 54 | ) |
@@ -52,9 +56,9 @@ | ||
52 | 56 | function attempt () { |
53 | 57 | progress.reset().next('connecting...') |
54 | 58 | |
55 | 59 | ssbClient(null, { |
56 | - remote: invite, | |
60 | + remote: data.invite, | |
57 | 61 | manifest: { invite: {use: 'async'}, getAddress: 'async' } |
58 | 62 | }, function (err, sbot) { |
59 | 63 | if(err) return progress.fail(err) |
60 | 64 | progress.next('requesting follow...') |
@@ -78,24 +82,24 @@ | ||
78 | 82 | if(err) return progress.fail(err) |
79 | 83 | progress.complete() |
80 | 84 | //check for redirect |
81 | 85 | var parts = location.hash.substring(1).split('#') |
86 | + | |
82 | 87 | //TODO: handle in a consistent way with either hashrouting |
83 | 88 | //or with tabs... |
84 | - if(parts[0] === invite) location.hash = '#' | |
89 | + if(parts[0] === data.invite) | |
90 | + location.hash = data.redirect | |
91 | + else | |
92 | + console.log("NO REDIRECT") | |
85 | 93 | }) |
86 | 94 | }) |
87 | 95 | }) |
88 | 96 | } |
89 | 97 | |
90 | 98 | // If we are in the browser, |
91 | 99 | // and do not already have a remote set, automatically trigger the invite. |
92 | - | |
93 | 100 | if(process.title == 'browser' && !localStorage.remote) attempt() |
94 | 101 | |
95 | 102 | return div |
96 | 103 | } |
97 | 104 | |
98 | 105 | |
99 | - | |
100 | - | |
101 | - |
Built with git-ssb-web