Commit d89e5bb09b3a46bb3c18119673f03862020eb44c
move invite checker to own module, delay it, and only load it on the main feed
Ev Bogue committed on 6/28/2018, 11:04:52 PMParent: 20dac953590fa5c36d143ac2af6eaf37a9e19fc3
Files changed
views.js | changed |
invite.js | added |
views.js | ||
---|---|---|
@@ -19,8 +19,10 @@ | ||
19 | 19 | |
20 | 20 | var ssbKeys = require('ssb-keys') |
21 | 21 | var keys = require('./keys') |
22 | 22 | |
23 | +var checkInvite = require('./invite') | |
24 | + | |
23 | 25 | var compose = require('./compose') |
24 | 26 | |
25 | 27 | var about = function () { |
26 | 28 | var screen = document.getElementById('screen') |
@@ -387,66 +389,8 @@ | ||
387 | 389 | } else if (src == 'key') { |
388 | 390 | keyPage() |
389 | 391 | } else { |
390 | 392 | everythingStream() |
393 | + checkInvite() | |
391 | 394 | } |
392 | 395 | |
393 | - | |
394 | - function parseInvite (invite) { | |
395 | - return ref.parseInvite(invite) | |
396 | - } | |
397 | - | |
398 | - // TODO: this should really only pop up if you have no friends | |
399 | - var currentScreen = document.getElementById('screen') | |
400 | - var invitebox = h('input', {placeholder: 'Invite Code Here'}) | |
401 | - invitebox.value = config.invite | |
402 | - var invite = h('div.content', h('div.message#inviter', | |
403 | - '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:', | |
404 | - h('br'), | |
405 | - invitebox, | |
406 | - h('button', 'Accept', {onclick: function (e) { | |
407 | - var data = parseInvite(invitebox.value) | |
408 | - console.log(data) | |
409 | - e.preventDefault() | |
410 | - //sbot.gossip.connect(data.remote, function (err) { | |
411 | - | |
412 | - //}) | |
413 | - | |
414 | - client(keys, { | |
415 | - remote: data.invite, | |
416 | - caps: config.caps, | |
417 | - manifest: {invite: {use: 'async'}, getAddress: 'async'} | |
418 | - }, function (err, remotebot) { | |
419 | - if (err) throw err | |
420 | - remotebot.invite.use({feed: id}, function (_err, msg) { | |
421 | - if (msg) { | |
422 | - sbot.publish({ | |
423 | - type: 'contact', | |
424 | - contact: data.key, | |
425 | - following: true | |
426 | - }) | |
427 | - } | |
428 | - }) | |
429 | - setTimeout(function () { | |
430 | - location.hash = '#' + id | |
431 | - location.hash = '#' | |
432 | - }, 100) | |
433 | - }) | |
434 | - }}) | |
435 | - )) | |
436 | - if (currentScreen.firstChild.firstChild) { | |
437 | - currentScreen.firstChild.insertBefore(invite, currentScreen.firstChild.firstChild) | |
438 | - } else { | |
439 | - currentScreen.firstChild.appendChild(invite) | |
440 | - } | |
441 | - sbot.friends.get({dest: id}, function (err, follows) { | |
442 | - for (var i in follows) { | |
443 | - if (follows[i] === true) { | |
444 | - var getInvite = document.getElementById('inviter') | |
445 | - | |
446 | - if (getInvite) { | |
447 | - getInvite.parentNode.removeChild(getInvite) | |
448 | - } | |
449 | - } | |
450 | - } | |
451 | - }) | |
452 | 396 | } |
invite.js | ||
---|---|---|
@@ -1,0 +1,73 @@ | ||
1 | +var ref = require('ssb-ref') | |
2 | +var h = require('hyperscript') | |
3 | +var client = require('ssb-client') | |
4 | +var sbot = require('./scuttlebot') | |
5 | +var config = require('./config')() | |
6 | + | |
7 | +var keys = require('./keys') | |
8 | + | |
9 | + | |
10 | +function parseInvite (invite) { | |
11 | + return ref.parseInvite(invite) | |
12 | +} | |
13 | + | |
14 | +module.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 | +} |
Built with git-ssb-web