Files: 8c71e9c979626faf9b3d2a3f9293a285ba56d033 / 2_actual_friends / client.js
1291 bytesRaw
1 | const Client = require('ssb-client') |
2 | const config = require('./config') |
3 | |
4 | const map = require('lodash/map') |
5 | |
6 | Client(config.keys, config, (err, ssbServer) => { |
7 | // ssbServer (also commonly called sbot) |
8 | // a remote connection to our server |
9 | if (err) throw err |
10 | |
11 | // console.log('methods', ssbServer) |
12 | console.log('actualFriends methods:', ssbServer.actualFriends) |
13 | |
14 | ssbServer.whoami((err, data) => { |
15 | if (err) throw err |
16 | const myId = data.id |
17 | const dominicId = '@EMovhfIrFk4NihAKnRNhrfRaqIhBv1Wj8pTxJNgvCCY=.ed25519' |
18 | |
19 | ssbServer.actualFriends.get((err, view) => { |
20 | if (err) throw err |
21 | |
22 | // console.log(JSON.stringify(view[id.id], null, 2)) |
23 | |
24 | // actualFriends(view, myId) |
25 | checkFriendShip(view, myId, dominicId) |
26 | |
27 | ssbServer.close() |
28 | }) |
29 | }) |
30 | }) |
31 | |
32 | function actualFriends (view, id) { |
33 | var idData = view[id] |
34 | var orderedData = map(idData.mentions, (value, key) => { |
35 | return { key , value } |
36 | }) |
37 | .sort((a,b) => b.value < a.value ? -1 : 1) |
38 | |
39 | write(orderedData) |
40 | } |
41 | |
42 | function checkFriendShip (view, id1, id2) { |
43 | console.log(`${id1} mentions ${id2} ${view[id1].mentions[id2]} times`) |
44 | console.log(`${id2} mentions ${id1} ${view[id2].mentions[id1]} times`) |
45 | } |
46 | |
47 | function write(object) { |
48 | process.stdout.write(JSON.stringify(object, null, 2)) |
49 | } |
50 | |
51 |
Built with git-ssb-web