Commit 9e6d7abeec492c4285f15bcf6ff689c60be4062b
invite uses hyperprogress
Dominic Tarr committed on 7/24/2016, 5:18:02 AMParent: 8cbcf91233c73cb8de180f682d84a828fdbde387
Files changed
modules/invite.js | changed |
modules/invite.js | ||
---|---|---|
@@ -3,12 +3,15 @@ | ||
3 | 3 | var ssbClient = require('ssb-client') |
4 | 4 | var id = require('../keys').id |
5 | 5 | var h = require('hyperscript') |
6 | 6 | |
7 | +var Progress = require('hyperprogress') | |
8 | + | |
7 | 9 | var plugs = require('../plugs') |
8 | 10 | var sbot_publish = plugs.first(exports.sbot_publish = []) |
9 | 11 | |
10 | 12 | |
13 | + | |
11 | 14 | exports.screen_view = function (invite) { |
12 | 15 | |
13 | 16 | //check that invite is |
14 | 17 | // ws:...~shs:key:seed |
@@ -20,16 +23,16 @@ | ||
20 | 23 | if(!/^(net|wss?)$/.test(parts[0][0])) return null |
21 | 24 | if(parts[1][0] !== 'shs') return null |
22 | 25 | if(parts[1].length !== 3) return null |
23 | 26 | |
27 | + var progress = Progress(4) | |
28 | + | |
24 | 29 | //connect to server |
25 | 30 | //request follow |
26 | 31 | //post pub announce |
27 | 32 | //post follow pub |
28 | - var progress = h('h1') | |
29 | - var status = h('pre') | |
30 | 33 | var div = h('div', |
31 | - progress, status, | |
34 | + progress, | |
32 | 35 | h('a', 'accept', {href: '#', onclick: function (ev) { |
33 | 36 | ev.preventDefault() |
34 | 37 | ev.stopPropagation() |
35 | 38 | attempt() |
@@ -37,33 +40,20 @@ | ||
37 | 40 | }}) |
38 | 41 | ) |
39 | 42 | |
40 | 43 | function attempt () { |
41 | - progress.textContent = '*' | |
42 | - status.textContent = 'connecting...' | |
43 | - | |
44 | - console.log("CONNECT", invite) | |
44 | + progress.next('connecting...') | |
45 | 45 | ssbClient(null, { |
46 | 46 | remote: invite, |
47 | 47 | manifest: { invite: {use: 'async'}, getAddress: 'async' } |
48 | 48 | }, function (err, sbot) { |
49 | - console.log("ERR?", err, sbot) | |
50 | - if(err) { | |
51 | - progress.textContent = '*!' | |
52 | - status.textContent = err.stack | |
53 | - return | |
54 | - } | |
55 | - progress.textContent = '**' | |
56 | - status.textContent = 'requesting follow...' + id | |
49 | + if(err) return progress.fail(err) | |
50 | + else progress.next('requesting follow...') | |
57 | 51 | |
58 | 52 | sbot.invite.use({feed: id}, function (err, msg) { |
59 | - if(err) { | |
60 | - progress.textContent = '**!' | |
61 | - status.textContent = err.stack | |
62 | - return | |
63 | - } | |
64 | - progress.textContent = '***' | |
65 | - status.textContent = 'following...' | |
53 | + if(err) return progres.fail(err) | |
54 | + | |
55 | + progress.next('following...') | |
66 | 56 | |
67 | 57 | //remove the seed from the shs address. |
68 | 58 | //then it's correct address. |
69 | 59 | //this should make the browser connect to this as remote. |
@@ -76,18 +66,12 @@ | ||
76 | 66 | |
77 | 67 | sbot_publish({ |
78 | 68 | type: 'contact', |
79 | 69 | contact: sbot.id, |
80 | - following: true | |
70 | + following: true, | |
81 | 71 | }, function (err) { |
82 | - if(err) { | |
83 | - progress.textContent = '***!' | |
84 | - status.textContent = err.stack | |
85 | - return | |
86 | - } | |
87 | - progress.textContent = '****' | |
88 | - status.textContent = 'READY!' | |
89 | - | |
72 | + if(err) return progress.fail(err) | |
73 | + progress.complete() | |
90 | 74 | }) |
91 | 75 | |
92 | 76 | }) |
93 | 77 | }) |
Built with git-ssb-web