git ssb

10+

Matt McKegg / patchwork



Tree: 149c021b55e9957ad4d75789d066cf9794507064

Files: 149c021b55e9957ad4d75789d066cf9794507064 / modules / page / html / render / channel.js

1906 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 'message.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('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, windowSize: 100 })
47 })
48
49 function subscribe (id) {
50 // confirm
51 api.message.async.publish({
52 type: 'channel',
53 channel: id,
54 subscribed: true
55 })
56 }
57
58 function unsubscribe (id) {
59 // confirm
60 api.message.async.publish({
61 type: 'channel',
62 channel: id,
63 subscribed: false
64 })
65 }
66}
67

Built with git-ssb-web