git ssb

2+

mixmix / ticktack



Tree: 36aff4f6d5e62e8ff308689bdfb6baea9413881e

Files: 36aff4f6d5e62e8ff308689bdfb6baea9413881e / 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