git ssb

2+

mixmix / ticktack



Tree: 140bd2aa4c9baa0075ccea378b2376a4c90cf8fc

Files: 140bd2aa4c9baa0075ccea378b2376a4c90cf8fc / channel / async.js

878 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 channel = channel.replace(/^#/, '')
21 if (!channel) throw new Error('a channel must be specified')
22 api.sbot.async.publish({
23 type: 'channel',
24 channel: channel,
25 subscribed: true
26 }, cb)
27 }
28
29 function unsubscribe (channel, cb) {
30 channel = channel.replace(/^#/, '')
31 if (!channel) throw new Error('a channel must be specified')
32 api.sbot.async.publish({
33 type: 'channel',
34 channel: channel,
35 subscribed: false
36 }, cb)
37 }
38}
39

Built with git-ssb-web