git ssb

3+

ev / decent



Commit 9c4fb40a5895ae6b15a97fd152cb7698b6cee509

update invite to latest

Ev Bogue committed on 8/30/2017, 4:42:59 PM
Parent: 641c937da32870fce2e530c38a158c29bde32bb9

Files changed

plugins/invite.jschanged
plugins/invite.jsView
@@ -1,4 +1,5 @@
1 +'use strict'
12 var crypto = require('crypto')
23 var ssbKeys = require('ssb-keys')
34 var toAddress = require('../lib/util').toAddress
45 var cont = require('cont')
@@ -26,8 +27,12 @@
2627 function isObject(o) {
2728 return o && 'object' === typeof o
2829 }
2930
31 +function isNumber(n) {
32 + return 'number' === typeof n && !isNaN(n)
33 +}
34 +
3035 module.exports = {
3136 name: 'invite',
3237 version: '1.0.0',
3338 manifest: mdm.manifest(apidoc),
@@ -59,14 +64,19 @@
5964 })
6065 })
6166
6267 return {
63- create: valid.async(function (n, cb) {
64- var modern = false
65- if(isObject(n) && n.modern) {
66- n = 1
67- modern = true
68 + create: valid.async(function (opts, cb) {
69 + opts = opts || {}
70 + if(isNumber(opts))
71 + opts = {uses: opts}
72 + else if(isObject(opts)) {
73 + if(opts.modern)
74 + opts.uses = 1
6875 }
76 + else if(isFunction(opts))
77 + cb = opts, opts = {}
78 +
6979 var addr = server.getAddress()
7080 var host = ref.parseAddress(addr).host
7181 if(!config.allowPrivate && (ip.isPrivate(host) || 'localhost' === host))
7282 return cb(new Error('Server has no public ip address, '
@@ -85,32 +95,35 @@
8595 // store metadata under the generated pubkey
8696 var owner = server.id
8797 codesDB.put(keyCap.id, {
8898 id: keyCap.id,
89- total: +n,
99 + total: +opts.uses || 1,
100 + note: opts.note,
90101 used: 0,
91102 permissions: {allow: ['invite.use', 'getAddress'], deny: null}
92103 }, function (err) {
93104 // emit the invite code: our server address, plus the key-seed
94105 if(err) cb(err)
95- else if(modern && server.ws && server.ws.getAddress) {
106 + else if(opts.modern && server.ws && server.ws.getAddress) {
96107 cb(null, server.ws.getAddress()+':'+seed.toString('base64'))
97108 }
98109 else {
99110 addr = ref.parseAddress(addr)
100111 cb(null, [addr.host, addr.port, addr.key].join(':') + '~' + seed.toString('base64'))
101112 }
102113 })
103- }, 'number|object'),
114 + }, 'number|object', 'string?'),
104115 use: valid.async(function (req, cb) {
105116 var rpc = this
106117
107118 // fetch the code
108119 codesDB.get(rpc.id, function(err, invite) {
109120 if(err) return cb(err)
110121
111122 // check if we're already following them
112- server.friends.all('follow', function(err, follows) {
123 + server.friends.get(function (err, follows) {
124 +// server.friends.all('follow', function(err, follows) {
125 +// if(hops[req.feed] == 1)
113126 if (follows && follows[server.id] && follows[server.id][req.feed])
114127 return cb(new Error('already following'))
115128
116129 // although we already know the current feed
@@ -142,9 +155,10 @@
142155 server.publish({
143156 type: 'contact',
144157 contact: req.feed,
145158 following: true,
146- pub: true
159 + pub: true,
160 + note: invite.note || undefined
147161 }, cb)
148162 })
149163 })
150164 })
@@ -170,8 +184,9 @@
170184
171185 opts = ref.parseAddress(ref.parseInvite(invite).remote)
172186
173187 ssbClient(null, {
188 + caps: config.caps,
174189 remote: invite,
175190 manifest: {invite: {use: 'async'}, getAddress: 'async'}
176191 }, function (err, rpc) {
177192 if(err) return cb(explain(err, 'could not connect to server'))
@@ -213,5 +228,4 @@
213228 }
214229 }
215230 }
216231
217-

Built with git-ssb-web