Files: c9fd42d136f55e4d29ca6bfdf81741267177696d / channel / async.js
800 bytesRaw
1 | var nest = require('depnest') |
2 | var ref = require('ssb-ref') |
3 | |
4 | exports.needs = nest({ |
5 | 'keys.sync.id': 'first', |
6 | 'sbot.async.publish': 'first', |
7 | 'channel.obs.subscribed': 'first', |
8 | }) |
9 | |
10 | exports.gives = nest({ |
11 | 'channel.async': ['subscribe', 'unsubscribe'] |
12 | }) |
13 | |
14 | exports.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