Files: 25c84eb21bc4e067eac8085385882db73bf9bde8 / modules / invite.js
1983 bytesRaw
1 | |
2 | var ref = require('ssb-ref') |
3 | var ssbClient = require('ssb-client') |
4 | var id = require('../keys').id |
5 | var h = require('hyperscript') |
6 | |
7 | var Progress = require('hyperprogress') |
8 | |
9 | var plugs = require('../plugs') |
10 | var sbot_publish = plugs.first(exports.sbot_publish = []) |
11 | |
12 | |
13 | |
14 | exports.screen_view = function (invite) { |
15 | |
16 | //check that invite is |
17 | // ws:...~shs:key:seed |
18 | |
19 | var parts = invite.split('~') |
20 | .map(function (e) { return e.split(':') }) |
21 | |
22 | if(parts.length !== 2) return null |
23 | if(!/^(net|wss?)$/.test(parts[0][0])) return null |
24 | if(parts[1][0] !== 'shs') return null |
25 | if(parts[1].length !== 3) return null |
26 | |
27 | var progress = Progress(4) |
28 | |
29 | //connect to server |
30 | //request follow |
31 | //post pub announce |
32 | //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 | }}) |
41 | ) |
42 | |
43 | function attempt () { |
44 | progress.next('connecting...') |
45 | ssbClient(null, { |
46 | remote: invite, |
47 | manifest: { invite: {use: 'async'}, getAddress: 'async' } |
48 | }, function (err, sbot) { |
49 | if(err) return progress.fail(err) |
50 | else progress.next('requesting follow...') |
51 | |
52 | sbot.invite.use({feed: id}, function (err, msg) { |
53 | if(err) return progres.fail(err) |
54 | |
55 | progress.next('following...') |
56 | |
57 | //remove the seed from the shs address. |
58 | //then it's correct address. |
59 | //this should make the browser connect to this as remote. |
60 | //we don't want to do this if when using this locally, though. |
61 | if(process.title === 'browser') { |
62 | var p2 = invite.split(':') |
63 | p2.pop() |
64 | localStorage.remote = p2.join(':') |
65 | } |
66 | |
67 | sbot_publish({ |
68 | type: 'contact', |
69 | contact: sbot.id, |
70 | following: true, |
71 | }, function (err) { |
72 | if(err) return progress.fail(err) |
73 | progress.complete() |
74 | }) |
75 | |
76 | }) |
77 | }) |
78 | } |
79 | |
80 | return div |
81 | } |
82 | |
83 | |
84 |
Built with git-ssb-web