git ssb

0+

cel / ssb-clingy



Commit 31f416228e9b71e3d3d8d917f863f64625d5a32e

changed to work with rpc:connect - will now work with remote peers, not just local connections

Joran committed on 7/13/2019, 11:13:27 PM
Parent: 6fb1bd52eeeee6c62ab88945148ae660e8ada5af

Files changed

index.jschanged
index.jsView
@@ -5,45 +5,28 @@
55 exports.version = '1.1.0'
66 exports.manifest = {}
77
88 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
9 + api.on('rpc:connect', function (rpc, args) {
10 + console.log("connection from: ", rpc.id)
1311
14- connect(address, (err, x) => {
15- if (err) return cb(err)
12 + var our_id = api.whoami().id
13 + var connecting_id = rpc.id
1614
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)
15 + api.friends.isFollowing({source: our_id, dest: connecting_id}, (err, following) => {
16 + if (following) {
17 + console.log("already following:", connecting_id)
18 + } else {
19 + // Yay more friendssss
20 + console.log("stranger! New friend :3", connecting_id)
21 +
22 + api.publish({
23 + type: "contact",
24 + contact: connecting_id,
25 + following: true
26 + }, () => {
27 + console.log("Followed", connecting_id)
28 + })
2529 }
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- })
4730 })
4831 })
4932 }

Built with git-ssb-web