git ssb

16+

Dominic / patchbay



Tree: bb0546def2cf16647b0188303625848b8908a5e7

Files: bb0546def2cf16647b0188303625848b8908a5e7 / app / page / channel.js

1916 bytesRaw
1const nest = require('depnest')
2const pull = require('pull-stream')
3const Scroller = require('pull-scroll')
4const { h } = require('mutant')
5
6exports.gives = nest('app.page.channel')
7
8exports.needs = nest({
9 'app.html.filter': 'first',
10 'app.html.scroller': 'first',
11 'feed.pull.channel': 'first',
12 'message.html.compose': 'first',
13 'message.html.render': 'first',
14 'channel.obs.subscribed': 'first',
15 'keys.sync.id': 'first',
16 'sbot.async.publish': 'first'
17})
18
19exports.create = function (api) {
20 return nest('app.page.channel', channelView)
21
22 function channelView (location) {
23 const { channel } = location
24
25 const channelName = channel.substr(1)
26
27 var subscribed = api.channel.obs.subscribed(api.keys.sync.id())
28
29 function subscribeToChannel() {
30 api.sbot.async.publish({
31 type: 'channel',
32 channel: channelName,
33 subscribed: true
34 })
35 }
36
37 const channelHeader = h('header', [channel, h('span', subscribed.has(channelName)() ? ' is subscribed' : h('button', { 'ev-click': subscribeToChannel }, 'Subscribe'))])
38
39 const composer = api.message.html.compose({ meta: { type: 'post', channel: channelName } })
40 const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw)
41 const { container, content } = api.app.html.scroller({ prepend: [composer, filterMenu, channelHeader] })
42
43 function draw () {
44 resetFeed({ container, content })
45
46 const openChannelSource = api.feed.pull.channel(channelName)
47
48 pull(
49 openChannelSource({old: false}),
50 filterUpThrough(),
51 Scroller(container, content, api.message.html.render, true, false)
52 )
53
54 pull(
55 openChannelSource({reverse: true}),
56 filterDownThrough(),
57 Scroller(container, content, api.message.html.render, false, false)
58 )
59 }
60 draw()
61
62 container.title = channel
63 return container
64 }
65}
66

Built with git-ssb-web