Files: 399b1970504b9830b9a27953057861e8a6ebfd9b / modules / channel / html / subscribe-toggle.js
1209 bytesRaw
1 | var nest = require('depnest') |
2 | var { h, when, send } = require('mutant') |
3 | |
4 | exports.gives = nest('channel.html.subscribeToggle') |
5 | exports.needs = nest({ |
6 | 'intl.sync.i18n': 'first', |
7 | 'keys.sync.id': 'first', |
8 | 'message.async.publish': 'first', |
9 | 'channel.obs.subscribed': 'first' |
10 | }) |
11 | |
12 | exports.create = function (api) { |
13 | var i18n = api.intl.sync.i18n |
14 | return nest('channel.html.subscribeToggle', function (channel, opts) { |
15 | var yourId = api.keys.sync.id() |
16 | var subscribedChannels = api.channel.obs.subscribed(yourId) |
17 | |
18 | return when(subscribedChannels.has(channel), |
19 | h('a.ToggleButton.-unsubscribe', { |
20 | 'href': '#', |
21 | 'title': i18n('Click to unsubscribe'), |
22 | 'ev-click': send(unsubscribe, channel) |
23 | }, i18n('Subscribed')), |
24 | h('a.ToggleButton.-subscribe', { |
25 | 'href': '#', |
26 | 'ev-click': send(subscribe, channel) |
27 | }, i18n('Subscribe')) |
28 | ) |
29 | }) |
30 | |
31 | function subscribe (id) { |
32 | // confirm |
33 | api.message.async.publish({ |
34 | type: 'channel', |
35 | channel: id, |
36 | subscribed: true |
37 | }) |
38 | } |
39 | |
40 | function unsubscribe (id) { |
41 | // confirm |
42 | api.message.async.publish({ |
43 | type: 'channel', |
44 | channel: id, |
45 | subscribed: false |
46 | }) |
47 | } |
48 | } |
49 |
Built with git-ssb-web