Files: dd6a279d35c61c3c1a36d453b6e27af326a3fc67 / app / page / public.js
2314 bytesRaw
1 | const nest = require('depnest') |
2 | const { h } = require('mutant') |
3 | const pull = require('pull-stream') |
4 | const Scroller = require('pull-scroll') |
5 | const next = require('pull-next-query') |
6 | const merge = require('lodash/merge') |
7 | |
8 | exports.gives = nest({ |
9 | 'app.html.menuItem': true, |
10 | 'app.page.public': true |
11 | }) |
12 | |
13 | exports.needs = nest({ |
14 | 'app.html.filter': 'first', |
15 | 'app.html.scroller': 'first', |
16 | 'app.sync.goTo': 'first', |
17 | // 'feed.pull.public': 'first', |
18 | 'sbot.pull.stream': 'first', |
19 | 'message.html.compose': 'first', |
20 | 'message.html.render': 'first' |
21 | }) |
22 | |
23 | exports.create = function (api) { |
24 | return nest({ |
25 | 'app.html.menuItem': menuItem, |
26 | 'app.page.public': publicPage |
27 | }) |
28 | |
29 | function menuItem () { |
30 | return h('a', { |
31 | 'ev-click': () => api.app.sync.goTo({ page: 'public' }) |
32 | }, '/public') |
33 | } |
34 | |
35 | function publicPage (location) { |
36 | const composer = api.message.html.compose({ |
37 | location, |
38 | meta: { type: 'post' }, |
39 | placeholder: 'Write a public message' |
40 | }) |
41 | const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw) |
42 | const { container, content } = api.app.html.scroller({ prepend: [composer, filterMenu] }) |
43 | |
44 | const createStream = (opts) => api.sbot.pull.stream(server => { |
45 | const _opts = merge({}, opts, { |
46 | query: [{ |
47 | $filter: { |
48 | timestamp: {$gt: 0, $lt: undefined}, |
49 | value: { |
50 | content: { recps: {$not: true} } |
51 | } |
52 | } |
53 | }], |
54 | limit: 100 |
55 | }) |
56 | |
57 | return next(server.query.read, _opts, ['timestamp']) |
58 | }) |
59 | |
60 | // TODO : build a pull-stream which has seperate state + rendering |
61 | function draw () { |
62 | resetFeed({ container, content }) |
63 | |
64 | const render = (msg) => { |
65 | // if (msg.value.content.type === 'about') debugger |
66 | return api.message.html.render(msg) |
67 | } |
68 | |
69 | // TODO - change to use ssb-query, streamed by publish time |
70 | pull( |
71 | createStream({old: false, live: true}), |
72 | filterUpThrough(), |
73 | Scroller(container, content, render, true, false) |
74 | ) |
75 | |
76 | pull( |
77 | createStream({reverse: true, live: false}), |
78 | filterDownThrough(), |
79 | Scroller(container, content, render, false, false) |
80 | ) |
81 | } |
82 | draw() |
83 | |
84 | container.title = '/public' |
85 | return container |
86 | } |
87 | } |
88 |
Built with git-ssb-web