git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

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 PM
Parent: f2075a6678ad096ea4b796c5d54979f7d08ab2cf

Files changed

bin.jschanged
config.jschanged
config/inject.jschanged
readme.mdchanged
scuttlebot.jschanged
views.jschanged
bin.jsView
@@ -5,15 +5,18 @@
55 var open = require('opn')
66 var home = require('os-homedir')()
77 var nonPrivate = require('non-private-ip')
88 var muxrpcli = require('muxrpcli')
9-var yargs = require('yargs').argv
109
1110 var SEC = 1e3
1211 var MIN = 60*SEC
1312
14-var config = require('./config/inject')(yargs.appname || 'ssb')
13+var network = 'ssb'
14+//var network = 'decent'
15+//var network = 'testnet'
1516
17+var config = require('./config/inject')(network)
18+
1619 config.keys = ssbKeys.loadOrCreateSync(path.join(config.path, 'secret'))
1720
1821 var mvdClient = fs.readFileSync(path.join('./build/index.html'))
1922
@@ -46,8 +49,11 @@
4649 sbot.ws.use(function (req, res, next) {
4750 var send = config
4851 delete send.keys // very important to keep this, as it removes the server keys from the config before broadcast
4952 send.address = sbot.ws.getAddress()
53+ sbot.invite.create({modern: true}, function (err, cb) {
54+ send.invite = cb
55+ })
5056 if(req.url == '/')
5157 res.end(mvdClient)
5258 if(req.url == '/get-config')
5359 res.end(JSON.stringify(send))
config.jsView
@@ -2,19 +2,25 @@
22
33 module.exports = function () {
44 var host = window.location.origin
55
6- if (localStorage[host])
7- var config = JSON.parse(localStorage[host])
8- else
6+ function getConfig () {
97 http.get(host + '/get-config', function (res) {
108 res.on('data', function (data, remote) {
119 var config = data
1210 localStorage[host] = config
13- location.reload()
1411 })
1512 })
13+ }
1614
15+ if (localStorage[host]) {
16+ var config = JSON.parse(localStorage[host])
17+ getConfig()
18+ } else {
19+ getConfig()
20+ location.reload()
21+ }
22+
1723 config.blobsUrl = host + '/blobs/get/'
1824 config.emojiUrl = host + '/img/emoji/'
1925
2026 if (config.ws.remote)
config/inject.jsView
@@ -57,8 +57,9 @@
5757 name: name,
5858 //standard stuff that probably doesn't need to change below
5959 host: nonPrivate.v4 || '',
6060 timeout: 0,
61+ allowPrivate: true,
6162 pub: true,
6263 local: true,
6364 friends: {
6465 dunbar: 150,
readme.mdView
@@ -20,10 +20,11 @@
2020 ```
2121
2222 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'.
2323
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!
2525
26+
2627 [try it online](http://gitmx.com/) -- decent(ralized)
2728
2829 ### history
2930
scuttlebot.jsView
@@ -85,8 +85,13 @@
8585 }),
8686 addblob: rec.sink(function (cb) {
8787 return sbot.blobs.add(cb)
8888 }),
89+ friends: {
90+ get: rec.async(function (opts, cb) {
91+ sbot.friends.get(opts, cb)
92+ })
93+ },
8994 publish: rec.async(function (content, cb) {
9095 if(content.recps)
9196 content = ssbKeys.box(content, content.recps.map(function (e) {
9297 return ref.isFeed(e) ? e : e.link
views.jsView
@@ -6,8 +6,9 @@
66 var stream = require('hyperloadmore/stream')
77 var h = require('hyperscript')
88 var render = require('./render')
99 var ref = require('ssb-ref')
10+var client = require('ssb-client')
1011
1112 var Next = require('pull-next-query')
1213
1314 var config = require('./config')()
@@ -387,5 +388,65 @@
387388 keyPage()
388389 } else {
389390 everythingStream()
390391 }
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+ })
391452 }

Built with git-ssb-web