Commit d14ff6e799b8cbfb78471c09928129a03c48ad78
share an invite and prompt for an invite when you have no friends
Ev Bogue committed on 6/28/2018, 8:17:05 PMParent: f2075a6678ad096ea4b796c5d54979f7d08ab2cf
Files changed
bin.js | changed |
config.js | changed |
config/inject.js | changed |
readme.md | changed |
scuttlebot.js | changed |
views.js | changed |
bin.js | ||
---|---|---|
@@ -5,15 +5,18 @@ | ||
5 | 5 | var open = require('opn') |
6 | 6 | var home = require('os-homedir')() |
7 | 7 | var nonPrivate = require('non-private-ip') |
8 | 8 | var muxrpcli = require('muxrpcli') |
9 | -var yargs = require('yargs').argv | |
10 | 9 | |
11 | 10 | var SEC = 1e3 |
12 | 11 | var MIN = 60*SEC |
13 | 12 | |
14 | -var config = require('./config/inject')(yargs.appname || 'ssb') | |
13 | +var network = 'ssb' | |
14 | +//var network = 'decent' | |
15 | +//var network = 'testnet' | |
15 | 16 | |
17 | +var config = require('./config/inject')(network) | |
18 | + | |
16 | 19 | config.keys = ssbKeys.loadOrCreateSync(path.join(config.path, 'secret')) |
17 | 20 | |
18 | 21 | var mvdClient = fs.readFileSync(path.join('./build/index.html')) |
19 | 22 | |
@@ -46,8 +49,11 @@ | ||
46 | 49 | sbot.ws.use(function (req, res, next) { |
47 | 50 | var send = config |
48 | 51 | delete send.keys // very important to keep this, as it removes the server keys from the config before broadcast |
49 | 52 | send.address = sbot.ws.getAddress() |
53 | + sbot.invite.create({modern: true}, function (err, cb) { | |
54 | + send.invite = cb | |
55 | + }) | |
50 | 56 | if(req.url == '/') |
51 | 57 | res.end(mvdClient) |
52 | 58 | if(req.url == '/get-config') |
53 | 59 | res.end(JSON.stringify(send)) |
config.js | ||
---|---|---|
@@ -2,19 +2,25 @@ | ||
2 | 2 | |
3 | 3 | module.exports = function () { |
4 | 4 | var host = window.location.origin |
5 | 5 | |
6 | - if (localStorage[host]) | |
7 | - var config = JSON.parse(localStorage[host]) | |
8 | - else | |
6 | + function getConfig () { | |
9 | 7 | http.get(host + '/get-config', function (res) { |
10 | 8 | res.on('data', function (data, remote) { |
11 | 9 | var config = data |
12 | 10 | localStorage[host] = config |
13 | - location.reload() | |
14 | 11 | }) |
15 | 12 | }) |
13 | + } | |
16 | 14 | |
15 | + if (localStorage[host]) { | |
16 | + var config = JSON.parse(localStorage[host]) | |
17 | + getConfig() | |
18 | + } else { | |
19 | + getConfig() | |
20 | + location.reload() | |
21 | + } | |
22 | + | |
17 | 23 | config.blobsUrl = host + '/blobs/get/' |
18 | 24 | config.emojiUrl = host + '/img/emoji/' |
19 | 25 | |
20 | 26 | if (config.ws.remote) |
config/inject.js | ||
---|---|---|
@@ -57,8 +57,9 @@ | ||
57 | 57 | name: name, |
58 | 58 | //standard stuff that probably doesn't need to change below |
59 | 59 | host: nonPrivate.v4 || '', |
60 | 60 | timeout: 0, |
61 | + allowPrivate: true, | |
61 | 62 | pub: true, |
62 | 63 | local: true, |
63 | 64 | friends: { |
64 | 65 | dunbar: 150, |
readme.md | ||
---|---|---|
@@ -20,10 +20,11 @@ | ||
20 | 20 | ``` |
21 | 21 | |
22 | 22 | mvd should launch a browser window, and comes pre-configured to use the main ssb network by default. If you already have an `.ssb` folder, mvd should 'just work'. |
23 | 23 | |
24 | -To use with decent try `npm run decent`, to launch a testnet try `npm run testnet`. | |
24 | +To use `mvd` with decent or on a testnet, uncomment the appropriote lines in `bin.js`. For some reason sbot doesn't accept arguments properly, so we gotta hard code networsk right now! | |
25 | 25 | |
26 | + | |
26 | 27 | [try it online](http://gitmx.com/) -- decent(ralized) |
27 | 28 | |
28 | 29 | ### history |
29 | 30 |
scuttlebot.js | ||
---|---|---|
@@ -85,8 +85,13 @@ | ||
85 | 85 | }), |
86 | 86 | addblob: rec.sink(function (cb) { |
87 | 87 | return sbot.blobs.add(cb) |
88 | 88 | }), |
89 | + friends: { | |
90 | + get: rec.async(function (opts, cb) { | |
91 | + sbot.friends.get(opts, cb) | |
92 | + }) | |
93 | + }, | |
89 | 94 | publish: rec.async(function (content, cb) { |
90 | 95 | if(content.recps) |
91 | 96 | content = ssbKeys.box(content, content.recps.map(function (e) { |
92 | 97 | return ref.isFeed(e) ? e : e.link |
views.js | ||
---|---|---|
@@ -6,8 +6,9 @@ | ||
6 | 6 | var stream = require('hyperloadmore/stream') |
7 | 7 | var h = require('hyperscript') |
8 | 8 | var render = require('./render') |
9 | 9 | var ref = require('ssb-ref') |
10 | +var client = require('ssb-client') | |
10 | 11 | |
11 | 12 | var Next = require('pull-next-query') |
12 | 13 | |
13 | 14 | var config = require('./config')() |
@@ -387,5 +388,65 @@ | ||
387 | 388 | keyPage() |
388 | 389 | } else { |
389 | 390 | everythingStream() |
390 | 391 | } |
392 | + | |
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 | + }) | |
391 | 452 | } |
Built with git-ssb-web