git ssb

10+

Matt McKegg / patchwork



Tree: ee9f43c70d668ebeffd5077be5daae16dd4f47b4

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

2387 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 'channel.sync.normalize': 'first',
8 'feed.html.rollup': 'first',
9 'feed.pull.channel': 'first',
10 'sbot.pull.log': 'first',
11 'message.async.publish': 'first',
12 'keys.sync.id': 'first',
13 'intl.sync.i18n': 'first'
14})
15
16exports.gives = nest('page.html.render')
17
18exports.create = function (api) {
19 const i18n = api.intl.sync.i18n
20 return nest('page.html.render', function channel (path) {
21 if (path[0] !== '#') return
22
23 var channel = api.channel.sync.normalize(path.substr(1))
24 var subscribedChannels = api.channel.obs.subscribed(api.keys.sync.id())
25
26 var prepend = [
27 h('PageHeading', [
28 h('h1', `#${channel}`),
29 h('div.meta', [
30 when(subscribedChannels.has(channel),
31 h('a.ToggleButton.-unsubscribe', {
32 'href': '#',
33 'title': i18n('Click to unsubscribe'),
34 'ev-click': send(unsubscribe, channel)
35 }, i18n('Subscribed')),
36 h('a.ToggleButton.-subscribe', {
37 'href': '#',
38 'ev-click': send(subscribe, channel)
39 }, i18n('Subscribe'))
40 )
41 ])
42 ]),
43 api.message.html.compose({
44 meta: {type: 'post', channel},
45 placeholder: i18n('Write a message in this channel')
46 })
47 ]
48
49 return api.feed.html.rollup(api.feed.pull.channel(channel), {
50 prepend,
51 displayFilter: mentionFilter,
52 bumpFilter: mentionFilter
53 })
54
55 function mentionFilter (msg) {
56 // filter out likes
57 if (msg.value.content.type === 'vote') return false
58 if (api.channel.sync.normalize(msg.value.content.channel) === channel) return true
59 if (Array.isArray(msg.value.content.mentions)) {
60 if (msg.value.content.mentions.some(mention => {
61 return mention && api.channel.sync.normalize(mention.link) === `#${channel}`
62 })) {
63 return 'channel-mention'
64 }
65 }
66 }
67 })
68
69 function subscribe (id) {
70 // confirm
71 api.message.async.publish({
72 type: 'channel',
73 channel: id,
74 subscribed: true
75 })
76 }
77
78 function unsubscribe (id) {
79 // confirm
80 api.message.async.publish({
81 type: 'channel',
82 channel: id,
83 subscribed: false
84 })
85 }
86}
87

Built with git-ssb-web