Files: 59dd32b5a83df3b3e243a5bc34f33072e25a9701 / channel / async.js
878 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 | 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