git ssb

2+

mixmix / ticktack



Tree: 140bd2aa4c9baa0075ccea378b2376a4c90cf8fc

Files: 140bd2aa4c9baa0075ccea378b2376a4c90cf8fc / contact / obs / relationships.js

881 bytesRaw
1const nest = require('depnest')
2const { h, map, computed, when } = require('mutant')
3const { intersection, difference } = require('lodash')
4
5exports.gives = nest('contact.obs.relationships')
6
7exports.needs = nest({
8 'contact.obs.followers': 'first',
9 'contact.obs.following': 'first',
10 'keys.sync.id': 'first'
11})
12
13exports.create = function (api) {
14 return nest({
15 'contact.obs.relationships': relationships
16 })
17
18 function relationships (id) {
19 var following = api.contact.obs.following(id)
20 var followers = api.contact.obs.followers(id)
21
22 return computed([following, followers], (followingRaw, followersRaw) => {
23 const friends = intersection([...followingRaw], [...followersRaw])
24 const followers = difference(followersRaw, friends)
25 const following = difference(followingRaw, friends)
26
27 return { friends, followers, following }
28 })
29 }
30}
31

Built with git-ssb-web