-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
43 lines (37 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var pull = require("pull-stream")
var checkedList = []
var waitingTime = 3000
function isChecked(key) {
if (checkedList[key] && checkedList[key] > Date.now()) return true
checkedList[key] = Date.now() + waitingTime
return false
}
module.exports = {
name: "promiscuous",
version: "1.0.1",
manifest: {},
init: (api) => {
if (!api.conn) throw new Error('ssb-promiscuous needs ssb-conn to be installed')
if (!api.friends) throw new Error('ssb-promiscuous needs ssb-friends to be installed')
pull(
api.conn.stagedPeers(),
pull.flatten(),
pull.drain(([addr, data]) => {
if (isChecked(data)) return
api.friends.isFollowing({ source: api.id, dest: data.key }, (err, value) => {
if (err) return console.error(err)
if (value === true) return
follow(data.key)
})
})
)
return {}
function follow(feedId, cb = console.log) {
api.publish({
type: 'contact',
contact: feedId,
following: true
}, cb)
}
}
}