Files: c4c384106bcf50acf4c0fcb3f7b842ad68f25bcb / app / page / channels.js
2037 bytesRaw
1 | const nest = require('depnest') |
2 | const pull = require('pull-stream') |
3 | const pullMerge = require('pull-merge') |
4 | const Scroller = require('pull-scroll') |
5 | const { h } = require('mutant') |
6 | |
7 | exports.gives = nest('app.page.channels') |
8 | |
9 | exports.needs = nest({ |
10 | 'app.html.filter': 'first', |
11 | 'app.html.scroller': 'first', |
12 | 'feed.pull.channel': 'first', |
13 | 'message.html.compose': 'first', |
14 | 'message.html.render': 'first', |
15 | 'sbot.async.publish': 'first' |
16 | }) |
17 | |
18 | exports.create = function (api) { |
19 | return nest('app.page.channels', channelView) |
20 | |
21 | function channelView (location) { |
22 | const { channels } = location |
23 | if (!Array.isArray(channels)) return |
24 | |
25 | const channelNames = channels.map(c => c.substr(1)) |
26 | |
27 | const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw) |
28 | const { container, content } = api.app.html.scroller({ prepend: [filterMenu] }) |
29 | |
30 | function draw () { |
31 | resetFeed({ container, content }) |
32 | |
33 | const Source = (opts) => pull( |
34 | pullMerge( |
35 | channelNames.map(name => api.feed.pull.channel(name)(opts)), |
36 | (a, b) => { |
37 | if (opts.reverse) return (a.value.timestamp > b.value.timestamp) ? -1 : +1 |
38 | else return (a.value.timestamp < b.value.timestamp) ? -1 : +1 |
39 | } |
40 | ), |
41 | pull.unique(m => m.key) |
42 | ) |
43 | |
44 | pull( |
45 | Source({ old: false }), |
46 | filterUpThrough(), |
47 | Scroller(container, content, render, true, false) |
48 | ) |
49 | |
50 | pull( |
51 | Source({ reverse: true }), |
52 | filterDownThrough(), |
53 | Scroller(container, content, render, false, false) |
54 | ) |
55 | } |
56 | draw() |
57 | |
58 | // TODO rollups |
59 | function render (msg) { |
60 | return api.message.html.render(msg, { showTitle: true }) |
61 | } |
62 | |
63 | var page = h('Page -channels', { title: channels.join(' + ') }, [ |
64 | // filterMenu, // TODO - extract non-scroller els like filterMenu here |
65 | container |
66 | ]) |
67 | |
68 | // TODO better scroll hack for keyboard shortcuts |
69 | page.keyboardScroll = container.keyboardScroll |
70 | |
71 | return page |
72 | } |
73 | } |
74 |
Built with git-ssb-web