Files: e57c5f14597311bb19cb42a5208dcf94188919ba / channel / obs.js
604 bytesRaw
1 | const nest = require('depnest') |
2 | const ref = require('ssb-ref') |
3 | const computed = require('mutant/computed') |
4 | |
5 | exports.needs = nest({ |
6 | 'keys.sync.id': 'first', |
7 | 'channel.obs.subscribed': 'first', |
8 | }) |
9 | |
10 | exports.gives = nest('channel.obs.isSubscribedTo') |
11 | |
12 | exports.create = function (api) { |
13 | return nest('channel.obs.isSubscribedTo', isSubscribedTo) |
14 | |
15 | function isSubscribedTo (channel, id) { |
16 | if (!ref.isFeed(id)) { |
17 | id = api.keys.sync.id() |
18 | } |
19 | |
20 | const { subscribed } = api.channel.obs |
21 | const myChannels = subscribed(id) |
22 | return computed([myChannels], (v) => v.has(channel)) |
23 | } |
24 | } |
25 |
Built with git-ssb-web