git ssb

2+

mixmix / ticktack



Tree: c2cb876f7ef9db11df921ff5cebd31e0d8721cd1

Files: c2cb876f7ef9db11df921ff5cebd31e0d8721cd1 / channel / async.js

800 bytesRaw
1var nest = require('depnest')
2var ref = require('ssb-ref')
3
4exports.needs = nest({
5 'keys.sync.id': 'first',
6 'sbot.async.publish': 'first',
7 'channel.obs.subscribed': 'first',
8})
9
10exports.gives = nest({
11 'channel.async': ['subscribe', 'unsubscribe']
12})
13
14exports.create = function (api) {
15 return nest({
16 'channel.async': {subscribe, unsubscribe}
17 })
18
19 function subscribe (channel, cb) {
20 if (!channel) throw new Error('a channel must be specified')
21 api.sbot.async.publish({
22 type: 'channel',
23 channel: channel,
24 subscribed: true
25 }, cb)
26 }
27
28 function unsubscribe (channel, cb) {
29 if (!channel) throw new Error('a channel must be specified')
30 api.sbot.async.publish({
31 type: 'channel',
32 channel: channel,
33 subscribed: false
34 }, cb)
35 }
36
37}
38

Built with git-ssb-web