git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: abf8335c9c9187ce7b3861f372ce512d210e8a7b

Files: abf8335c9c9187ce7b3861f372ce512d210e8a7b / modules / page / html / render / channel.js

2159 bytesRaw
1var { h, when, send } = require('mutant')
2var pull = require('pull-stream')
3var nest = require('depnest')
4
5exports.needs = nest({
6 'channel.obs.subscribed': 'first',
7 'feed.html.rollup': 'first',
8 'sbot.pull.log': 'first',
9 'sbot.async.publish': 'first',
10 'keys.sync.id': 'first'
11})
12
13exports.gives = nest('page.html.render')
14
15exports.create = function (api) {
16 return nest('page.html.render', function channel (path) {
17 if (path[0] !== '#') return
18
19 var channel = path.substr(1)
20 var subscribedChannels = api.channel.obs.subscribed(api.keys.sync.id())
21
22 var prepend = [
23 h('div', {className: 'PageHeading'}, [
24 h('h1', `#${channel}`),
25 h('div.meta', [
26 when(subscribedChannels.has(channel),
27 h('a.ToggleButton.-unsubscribe', {
28 'href': '#',
29 'title': 'Click to unsubscribe',
30 'ev-click': send(unsubscribe, channel)
31 }, 'Subscribed'),
32 h('a.ToggleButton.-subscribe', {
33 'href': '#',
34 'ev-click': send(subscribe, channel)
35 }, 'Subscribe')
36 )
37 ])
38 ]),
39 //api.message.html.compose({type: 'post', channel: channel}, {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'})
40 ]
41
42 return api.feed.html.rollup((opts) => {
43 return pull(
44 api.sbot.pull.log(opts),
45 pull.map(matchesChannel)
46 )
47 }, { prepend })
48
49 // scoped
50
51 function matchesChannel (msg) {
52 if (msg.sync) return
53 var c = msg && msg.value && msg.value.content
54 if (c && c.channel === channel) {
55 return msg
56 } else {
57 return {timestamp: msg.timestamp}
58 }
59 }
60 })
61
62 function subscribe (id) {
63 api.sbot.async.publish({
64 type: 'channel',
65 channel: id,
66 subscribed: true
67 })
68 }
69
70 function unsubscribe (id) {
71 api.sbot.async.publish({
72 type: 'channel',
73 channel: id,
74 subscribed: false
75 })
76 }
77}
78

Built with git-ssb-web