Files: 417d3c1ef9e250a2e8a514b4db11c113b21dfe18 / contact / obs / relationships.js
881 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, map, computed, when } = require('mutant') |
3 | const { intersection, difference } = require('lodash') |
4 | |
5 | exports.gives = nest('contact.obs.relationships') |
6 | |
7 | exports.needs = nest({ |
8 | 'contact.obs.followers': 'first', |
9 | 'contact.obs.following': 'first', |
10 | 'keys.sync.id': 'first' |
11 | }) |
12 | |
13 | exports.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