Commit 8d24992d7fd612c951a9717b66eb1409a79213e4
Merge pull request #1 from sbillig/master
Use api.connect.hook instead of api.auth.hookJoran Kikke authored on 7/12/2019, 7:04:43 AM
GitHub committed on 7/12/2019, 7:04:43 AM
Parent: 147f6dfd9b9168b1946865ecf7355798c23e5283
Parent: 72eff71df9425b88c149c74c3b98af994b97d7ef
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -1,38 +1,49 @@ | ||
1 | 1 … | // Clingy Plugin |
2 | 2 … | // |
3 | 3 … | // Will follow any connecting id unless already following |
4 | 4 … | exports.name = 'clingy' |
5 | -exports.version = '1.0.4' | |
5 … | +exports.version = '1.1.0' | |
6 | 6 … | exports.manifest = {} |
7 | 7 … | |
8 | -exports.init = function (api, opts) { | |
9 | - api.auth.hook(function (fn, args) { | |
10 | - var connecting_id = args[0] | |
11 | - var our_id = api.whoami().id | |
12 | - var cb = args[1] | |
8 … | +exports.init = (api, opts) => { | |
9 … | + api.connect.hook((connect, args) => { | |
10 … | + const address = args[0] | |
11 … | + const cb = args[1] | |
12 … | + const our_id = api.whoami().id | |
13 | 13 … | |
14 | - api.friends.isFollowing({source: our_id, dest: connecting_id}, function(err, following) | |
15 | - { | |
16 | - if(following) | |
17 | - { | |
18 | - console.log("already following:", connecting_id) | |
19 | - cb(null, {allow: null, deny: null}) | |
20 | - } | |
21 | - else | |
22 | - { | |
23 | - // Yay more friendssss | |
24 | - console.log("stranger! New friend :3", connecting_id) | |
25 | - | |
26 | - api.publish({ | |
27 | - type: "contact", | |
28 | - contact: connecting_id, | |
29 | - following: true | |
30 | - }, function(){ | |
31 | - console.log("Followed", connecting_id) | |
32 | - | |
33 | - cb(null, {allow: null, deny: null}) | |
34 | - }) | |
35 | - } | |
36 | - }) | |
14 … | + connect(address, (err, x) => { | |
15 … | + if (err) return cb(err) | |
16 … | + | |
17 … | + const p = api.multiserver.parse(address) | |
18 … | + if (!Array.isArray(p) | |
19 … | + || p.length < 1 | |
20 … | + || p[0].length < 2 | |
21 … | + || !("key" in p[0][1])) | |
22 … | + { | |
23 … | + console.log("unexpected result when parsing address:", address, " result:", p) | |
24 … | + return cb(null, x) | |
25 … | + } | |
26 … | + | |
27 … | + const connecting_id = '@' + p[0][1].key.toString('base64') + '.ed25519' | |
28 … | + | |
29 … | + api.friends.isFollowing({source: our_id, dest: connecting_id}, (err, following) => { | |
30 … | + if (following) { | |
31 … | + console.log("already following:", connecting_id) | |
32 … | + cb(null, x) | |
33 … | + } else { | |
34 … | + // Yay more friendssss | |
35 … | + console.log("stranger! New friend :3", connecting_id) | |
36 … | + | |
37 … | + api.publish({ | |
38 … | + type: "contact", | |
39 … | + contact: connecting_id, | |
40 … | + following: true | |
41 … | + }, () => { | |
42 … | + console.log("Followed", connecting_id) | |
43 … | + cb(null, x) | |
44 … | + }) | |
45 … | + } | |
46 … | + }) | |
47 … | + }) | |
37 | 48 … | }) |
38 | 49 … | } |
Built with git-ssb-web