git ssb

4+

Dominic / scuttlebot



Commit 69b89f6f0bf0128f0a22b579bcba5157df95a37d

Allow setting a note for an invite code

cel committed on 3/30/2017, 3:38:03 PM
Parent: ae758ca835b0deec43ec864786a34e14b1cef0b3

Files changed

plugins/invite.jschanged
plugins/invite.mdchanged
test/invite.jschanged
plugins/invite.jsView
@@ -59,14 +59,18 @@
5959 })
6060 })
6161
6262 return {
63- create: valid.async(function (n, cb) {
63 + create: valid.async(function (n, note, cb) {
6464 var modern = false
6565 if(isObject(n) && n.modern) {
6666 n = 1
6767 modern = true
6868 }
69 + if(isFunction(note)) {
70 + cb = note
71 + note = null
72 + }
6973 var addr = server.getAddress()
7074 var host = ref.parseAddress(addr).host
7175 if(!config.allowPrivate && (ip.isPrivate(host) || 'localhost' === host))
7276 return cb(new Error('Server has no public ip address, '
@@ -86,8 +90,9 @@
8690 var owner = server.id
8791 codesDB.put(keyCap.id, {
8892 id: keyCap.id,
8993 total: +n,
94 + note: note,
9095 used: 0,
9196 permissions: {allow: ['invite.use', 'getAddress'], deny: null}
9297 }, function (err) {
9398 // emit the invite code: our server address, plus the key-seed
@@ -99,9 +104,9 @@
99104 addr = ref.parseAddress(addr)
100105 cb(null, [addr.host, addr.port, addr.key].join(':') + '~' + seed.toString('base64'))
101106 }
102107 })
103- }, 'number|object'),
108 + }, 'number|object', 'string?'),
104109 use: valid.async(function (req, cb) {
105110 var rpc = this
106111
107112 // fetch the code
@@ -142,9 +147,10 @@
142147 server.publish({
143148 type: 'contact',
144149 contact: req.feed,
145150 following: true,
146- pub: true
151 + pub: true,
152 + note: invite.note || undefined
147153 }, cb)
148154 })
149155 })
150156 })
plugins/invite.mdView
@@ -7,20 +7,23 @@
77
88 Create a new invite code.
99
1010 ```bash
11-create {n}
11 +create {n} [{note}]
1212 ```
1313
1414 ```js
15-create(n, cb)
15 +create(n[, note], cb)
1616 ```
1717
1818 This produces an invite-code which encodes the sbot server's address, and a keypair seed.
1919 The keypair seed is used to generate a keypair, which is then used to authenticate a connection with the sbot server.
2020 The sbot server will then grant access to the `use` call.
2121
2222 - `n` (number): How many times the invite can be used before it expires.
23 +- `note` (string): A note to associate with the invite code. The sbot server will
24 + include this note in the follow message that it creates when `use` is
25 + called.
2326
2427
2528
2629 ## accept: async
test/invite.jsView
@@ -253,7 +253,43 @@
253253
254254 })
255255
256256
257 +tape('test invite with note', function (t) {
257258
259 + var alice = createSbot({
260 + temp: 'test-invite-alice2', timeout: 100,
261 + allowPrivate: true,
262 + keys: ssbKeys.generate()
263 + })
258264
265 + var bob = createSbot({
266 + temp: 'test-invite-bob2', timeout: 100,
267 + keys: ssbKeys.generate()
268 + })
259269
270 + alice.invite.create(1, 'bob', function (err, invite) {
271 + if(err) throw err
272 + bob.invite.accept(invite, function (err) {
273 + if(err) throw err
274 +
275 + all(alice.messagesByType('contact'), function (err, ary) {
276 + t.equal(ary.length, 1)
277 +
278 + t.deepEqual({
279 + type: 'contact',
280 + contact: bob.id,
281 + following: true,
282 + pub: true,
283 + note: 'bob',
284 + }, ary[0].value.content)
285 +
286 + alice.close(true)
287 + bob.close(true)
288 + t.end()
289 + })
290 + })
291 + })
292 +})
293 +
294 +
295 +

Built with git-ssb-web