git ssb

10+

Matt McKegg / patchwork



Tree: 1a1dfa987b784a002e626f97e18aeaf2164d1299

Files: 1a1dfa987b784a002e626f97e18aeaf2164d1299 / modules / page / html / render / channel.js

2309 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), {
47 prepend,
48 displayFilter: mentionFilter,
49 bumpFilter: mentionFilter
50 })
51
52 function mentionFilter (msg) {
53 if (msg.value.content.channel === channel) return true
54 if (Array.isArray(msg.value.content.mentions)) {
55 if (msg.value.content.mentions.some(mention => {
56 return mention && mention.link === `#${channel}`
57 })) {
58 return 'channel-mention'
59 }
60 }
61 }
62 })
63
64 function subscribe (id) {
65 // confirm
66 api.message.async.publish({
67 type: 'channel',
68 channel: id,
69 subscribed: true
70 })
71 }
72
73 function unsubscribe (id) {
74 // confirm
75 api.message.async.publish({
76 type: 'channel',
77 channel: id,
78 subscribed: false
79 })
80 }
81}
82

Built with git-ssb-web