git ssb

10+

Matt McKegg / patchwork



Tree: 9a819a51f9e714d07b90b34130d7c67671c60e38

Files: 9a819a51f9e714d07b90b34130d7c67671c60e38 / modules / page / html / render / channel.js

1870 bytesRaw
1var { h, when, send } = require('mutant')
2var nest = require('depnest')
3
4exports.needs = nest({
5 'channel.obs.subscribed': 'first',
6 'message.html.compose': 'first',
7 'feed.html.rollup': 'first',
8 'feed.pull.channel': 'first',
9 'sbot.pull.log': 'first',
10 'sbot.async.publish': 'first',
11 'keys.sync.id': 'first'
12})
13
14exports.gives = nest('page.html.render')
15
16exports.create = function (api) {
17 return nest('page.html.render', function channel (path) {
18 if (path[0] !== '#') return
19
20 var channel = path.substr(1)
21 var subscribedChannels = api.channel.obs.subscribed(api.keys.sync.id())
22
23 var prepend = [
24 h('div', {className: 'PageHeading'}, [
25 h('h1', `#${channel}`),
26 h('div.meta', [
27 when(subscribedChannels.has(channel),
28 h('a.ToggleButton.-unsubscribe', {
29 'href': '#',
30 'title': 'Click to unsubscribe',
31 'ev-click': send(unsubscribe, channel)
32 }, 'Subscribed'),
33 h('a.ToggleButton.-subscribe', {
34 'href': '#',
35 'ev-click': send(subscribe, channel)
36 }, 'Subscribe')
37 )
38 ])
39 ]),
40 api.message.html.compose({
41 meta: {type: 'post', channel},
42 placeholder: 'Write a message in this channel\n\n\n\nPeople who follow you or subscribe to this channel will also see this message in their main feed.\n\nTo create a new channel, type the channel name (preceded by a #) into the search box above. e.g #cat-pics'
43 })
44 ]
45
46 return api.feed.html.rollup(api.feed.pull.channel(channel), { prepend })
47 })
48
49 function subscribe (id) {
50 api.sbot.async.publish({
51 type: 'channel',
52 channel: id,
53 subscribed: true
54 })
55 }
56
57 function unsubscribe (id) {
58 api.sbot.async.publish({
59 type: 'channel',
60 channel: id,
61 subscribed: false
62 })
63 }
64}
65

Built with git-ssb-web