git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: e56f598e317e0f73881bc6004495c39c60bccf65

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

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

Built with git-ssb-web