git ssb

2+

ev / mvd



Tree: e123126e7f263e8ab6840196d1ed0666c79c1bcc

Files: e123126e7f263e8ab6840196d1ed0666c79c1bcc / invite.js

2149 bytesRaw
1var ref = require('ssb-ref')
2var h = require('hyperscript')
3var client = require('ssb-client')
4var sbot = require('./scuttlebot')
5var config = require('./config')()
6
7var keys = require('./keys')
8
9
10function parseInvite (invite) {
11 return ref.parseInvite(invite)
12}
13
14module.exports = function () {
15
16 setTimeout(function () {
17 var currentScreen = document.getElementById('screen')
18 var invitebox = h('input', {placeholder: 'Invite Code Here'})
19 invitebox.value = config.invite
20 var invite = h('div.content', h('div.message#inviter',
21 'Hey, no one follows you. Your secure-scuttlebutt feed may not replicate unless a pub follows you. Either ', h('a', {href: '#key'}, 'import your key'), ' or use a pub invite:',
22 h('br'),
23 invitebox,
24 h('button.btn', 'Accept', {onclick: function (e) {
25 var data = parseInvite(invitebox.value)
26 e.preventDefault()
27 //sbot.gossip.connect(data.remote, function (err) {
28
29 //})
30
31 client(keys, {
32 remote: data.invite,
33 caps: config.caps,
34 manifest: {invite: {use: 'async'}, getAddress: 'async'}
35 }, function (err, remotebot) {
36 if (err) throw err
37 remotebot.invite.use({feed: keys.id}, function (_err, msg) {
38 if (msg) {
39 sbot.publish({
40 type: 'contact',
41 contact: data.key,
42 following: true
43 })
44 }
45 })
46 setTimeout(function () {
47 location.hash = '#' + keys.id
48 location.hash = '#'
49 }, 100)
50 })
51 }})
52 ))
53 if (currentScreen.firstChild.firstChild) {
54 currentScreen.firstChild.insertBefore(invite, currentScreen.firstChild.firstChild)
55 } else {
56 currentScreen.firstChild.appendChild(invite)
57 }
58 sbot.friends.get({dest: keys.id}, function (err, follows) {
59 for (var i in follows) {
60 if (follows[i] === true) {
61 var getInvite = document.getElementById('inviter')
62
63 if (getInvite) {
64 getInvite.parentNode.removeChild(getInvite)
65 }
66 }
67 }
68 })
69
70
71 }, 1000)
72
73}
74

Built with git-ssb-web