Files: 51c3cb517158a84ae9fcebc5d1a2fe8f7e8cc9da / app / page / public.js
2388 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 | server.query.explain(_opts, console.log) |
59 | return next(server.query.read, _opts, ['timestamp']) |
60 | }) |
61 | |
62 | // TODO : build a pull-stream which has seperate state + rendering |
63 | function draw () { |
64 | resetFeed({ container, content }) |
65 | |
66 | const render = (msg) => { |
67 | // if (msg.value.content.type === 'about') debugger |
68 | return api.message.html.render(msg) |
69 | } |
70 | |
71 | // TODO - change to use ssb-query, streamed by publish time |
72 | pull( |
73 | createStream({old: false, live: true}), |
74 | filterUpThrough(), |
75 | Scroller(container, content, render, true, false) |
76 | ) |
77 | |
78 | pull( |
79 | createStream({reverse: true, live: false}), |
80 | filterDownThrough(), |
81 | Scroller(container, content, render, false, false) |
82 | ) |
83 | } |
84 | draw() |
85 | |
86 | container.title = '/public' |
87 | return container |
88 | } |
89 | } |
90 |
Built with git-ssb-web