Files: f1d78b0cacae073b8824fe4935bee0fa93eaad36 / app / page / public.js
2341 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 | style: { order: 1 }, |
32 | 'ev-click': () => api.app.sync.goTo({ page: 'public' }) |
33 | }, '/public') |
34 | } |
35 | |
36 | function publicPage (location) { |
37 | const composer = api.message.html.compose({ |
38 | location, |
39 | meta: { type: 'post' }, |
40 | placeholder: 'Write a public message' |
41 | }) |
42 | const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw) |
43 | const { container, content } = api.app.html.scroller({ prepend: [composer, filterMenu] }) |
44 | |
45 | const createStream = (opts) => api.sbot.pull.stream(server => { |
46 | const _opts = merge({}, opts, { |
47 | query: [{ |
48 | $filter: { |
49 | timestamp: {$gt: 0, $lt: undefined}, |
50 | value: { |
51 | content: { recps: {$not: true} } |
52 | } |
53 | } |
54 | }], |
55 | limit: 100 |
56 | }) |
57 | |
58 | return next(server.query.read, _opts, ['timestamp']) |
59 | }) |
60 | |
61 | // TODO : build a pull-stream which has seperate state + rendering |
62 | function draw () { |
63 | resetFeed({ container, content }) |
64 | |
65 | const render = (msg) => { |
66 | // if (msg.value.content.type === 'about') debugger |
67 | return api.message.html.render(msg) |
68 | } |
69 | |
70 | // TODO - change to use ssb-query, streamed by publish time |
71 | pull( |
72 | createStream({old: false, live: true}), |
73 | filterUpThrough(), |
74 | Scroller(container, content, render, true, false) |
75 | ) |
76 | |
77 | pull( |
78 | createStream({reverse: true, live: false}), |
79 | filterDownThrough(), |
80 | Scroller(container, content, render, false, false) |
81 | ) |
82 | } |
83 | draw() |
84 | |
85 | container.title = '/public' |
86 | return container |
87 | } |
88 | } |
89 |
Built with git-ssb-web