git ssb

16+

Dominic / patchbay



Tree: 6791a012f6f25d8aeb64cae36c5f8ff3b21e9132

Files: 6791a012f6f25d8aeb64cae36c5f8ff3b21e9132 / app / page / public.js

2654 bytesRaw
1const nest = require('depnest')
2const { h } = require('mutant')
3const pull = require('pull-stream')
4const pullAbortable = require('pull-abortable')
5const Scroller = require('pull-scroll')
6const next = require('pull-next-query')
7const merge = require('lodash/merge')
8
9exports.gives = nest({
10 'app.html.menuItem': true,
11 'app.page.public': true
12})
13
14exports.needs = nest({
15 'app.html.filter': 'first',
16 'app.html.scroller': 'first',
17 'app.sync.goTo': 'first',
18 // 'feed.pull.public': 'first',
19 'sbot.pull.stream': 'first',
20 'message.html.compose': 'first',
21 'message.html.render': 'first'
22})
23
24exports.create = function (api) {
25 return nest({
26 'app.html.menuItem': menuItem,
27 'app.page.public': publicPage
28 })
29
30 function menuItem () {
31 return h('a', {
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], className: 'PublicFeed' })
44
45 var abortLive = pullAbortable()
46 var abortReverse = pullAbortable()
47 const createStream = (opts) => api.sbot.pull.stream(server => {
48 const _opts = merge({}, opts, {
49 query: [{
50 $filter: {
51 timestamp: { $gt: 0, $lt: undefined },
52 value: {
53 content: { recps: { $not: true } }
54 }
55 }
56 }],
57 limit: 100
58 })
59
60 return next(server.query.read, _opts, ['timestamp'])
61 })
62
63 // TODO : build a pull-stream which has seperate state + rendering
64 function draw () {
65 resetFeed({ container, content })
66
67 const render = (msg) => {
68 // if (msg.value.content.type === 'about') debugger
69 return api.message.html.render(msg, { showTitle: true })
70 }
71
72 // TODO - change to use ssb-query, streamed by publish time
73 abortLive.abort()
74 abortLive = pullAbortable()
75 pull(
76 createStream({ old: false, live: true }),
77 abortLive,
78 filterUpThrough(),
79 Scroller(container, content, render, true, false)
80 )
81
82 abortReverse.abort()
83 abortReverse = pullAbortable()
84 pull(
85 createStream({ reverse: true, live: false }),
86 abortReverse,
87 filterDownThrough(),
88 Scroller(container, content, render, false, false)
89 )
90 }
91 draw()
92
93 container.title = '/public'
94 return container
95 }
96}
97

Built with git-ssb-web