git ssb

2+

mixmix / ticktack



Tree: da0d5db6f185c041ae3e2ad7e73872e6d58c37cd

Files: da0d5db6f185c041ae3e2ad7e73872e6d58c37cd / channel / obs.js

813 bytesRaw
1const nest = require('depnest')
2const ref = require('ssb-ref')
3const computed = require('mutant/computed')
4
5exports.needs = nest({
6 'keys.sync.id': 'first',
7 'channel.obs.subscribed': 'first',
8})
9
10exports.gives = nest('channel.obs.isSubscribedTo')
11
12exports.create = function (api) {
13 var subscriptions = {}
14 var myId
15
16 return nest('channel.obs.isSubscribedTo', isSubscribedTo)
17
18 function isSubscribedTo (channel, id) {
19 if (!ref.isFeed(id)) {
20 id = getMyId()
21 }
22
23 return computed(getSubscriptions(id), (v) => v.has(channel))
24 }
25
26 //cache getters
27
28 function getMyId () {
29 if (!myId) myId = api.keys.sync.id()
30 return myId
31 }
32
33 function getSubscriptions (id) {
34 if (!subscriptions[id]) subscriptions[id] = api.channel.obs.subscribed(id)
35 return subscriptions[id]
36 }
37}
38
39

Built with git-ssb-web