git ssb

0+

mixmix / ssb-server-plugin-intro



Tree: 8c71e9c979626faf9b3d2a3f9293a285ba56d033

Files: 8c71e9c979626faf9b3d2a3f9293a285ba56d033 / 2_actual_friends / client.js

1291 bytesRaw
1const Client = require('ssb-client')
2const config = require('./config')
3
4const map = require('lodash/map')
5
6Client(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
32function 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
42function 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
47function write(object) {
48 process.stdout.write(JSON.stringify(object, null, 2))
49}
50
51

Built with git-ssb-web