git ssb

10+

Matt McKegg / patchwork



Tree: 6fbd24516cd1b0317b93e630e23a65807bfd51a6

Files: 6fbd24516cd1b0317b93e630e23a65807bfd51a6 / modules / page / html / render / channel.js

2852 bytesRaw
1var { h } = require('mutant')
2var nest = require('depnest')
3
4exports.needs = nest({
5 'message.html.compose': 'first',
6 'channel.sync.normalize': 'first',
7 'channel.html.subscribeToggle': 'first',
8 'feed.html.rollup': 'first',
9 'feed.html.followWarning': 'first',
10 'feed.pull.channel': 'first',
11 'sbot.pull.log': 'first',
12 'message.async.publish': 'first',
13 'keys.sync.id': 'first',
14 'intl.sync.i18n': 'first',
15 'settings.obs.get': 'first',
16 'profile.obs.contact': 'first'
17})
18
19exports.gives = nest('page.html.render')
20
21exports.create = function (api) {
22 const i18n = api.intl.sync.i18n
23 return nest('page.html.render', function channel (path) {
24 if (path[0] !== '#') return
25
26 var id = api.keys.sync.id()
27 var contact = api.profile.obs.contact(id)
28
29 var channel = api.channel.sync.normalize(path.substr(1))
30
31 var prepend = [
32 h('PageHeading', [
33 h('h1', `#${channel}`),
34 h('div.meta', [
35 api.channel.html.subscribeToggle(channel)
36 ])
37 ]),
38 api.message.html.compose({
39 meta: {type: 'post', channel},
40 placeholder: i18n('Write a message in this channel')
41 }),
42 noVisibleNewPostsWarning()
43 ]
44
45 const filters = api.settings.obs.get('filters')
46 const channelView = api.feed.html.rollup(
47 api.feed.pull.channel(channel), {
48 prepend,
49 rootFilter: checkFeedFilter,
50 displayFilter: mentionFilter,
51 bumpFilter: mentionFilter
52 })
53
54 // call reload whenever filters changes
55 filters(channelView.reload)
56
57 return channelView
58
59 function checkFeedFilter (msg) {
60 const filterObj = filters() && filters().channelView
61 if (filterObj) {
62 const msgType = msg && msg.value && msg.value.content &&
63 msg.value.content.type
64 // filter out channel subscription messages
65 if (filterObj.subscriptions && msgType === 'channel') { return false }
66 }
67 return true
68 }
69
70 function mentionFilter (msg) {
71 // filter out likes
72 if (msg.value.content.type === 'vote') return false
73 if (api.channel.sync.normalize(msg.value.content.channel) === channel) return true
74 if (Array.isArray(msg.value.content.mentions)) {
75 if (msg.value.content.mentions.some(mention => {
76 return mention && getNormalized(mention.link) === `#${channel}`
77 })) {
78 return 'channel-mention'
79 }
80 }
81 }
82
83 function getNormalized (link) {
84 if (typeof link === 'string' && link.startsWith('#')) {
85 return `#${api.channel.sync.normalize(link.slice(1))}`
86 }
87 }
88
89 function noVisibleNewPostsWarning () {
90 var warning = i18n('You may not be able to see new channel content until you follow some users or pubs.')
91 return api.feed.html.followWarning(contact.isNotFollowingAnybody, warning)
92 }
93 })
94}
95

Built with git-ssb-web