git ssb

16+

Dominic / patchbay



Tree: 09c0a2e49ccc68a4cdc3a98da00657c1aff6158b

Files: 09c0a2e49ccc68a4cdc3a98da00657c1aff6158b / app / html / page / private.js

2021 bytesRaw
1const nest = require('depnest')
2const { h } = require('mutant')
3const pull = require('pull-stream')
4const Scroller = require('pull-scroll')
5const next = require('../../../junk/next-stepper')
6const ref = require('ssb-ref')
7
8exports.gives = nest({
9 'app.html': {
10 page: true,
11 menuItem: true
12 }
13})
14
15exports.needs = nest({
16 'app.html': {
17 filter: 'first',
18 scroller: 'first'
19 },
20 'app.sync.goTo': 'first',
21 'feed.pull.private': 'first',
22 'keys.sync.id': 'first',
23 'message.html': {
24 compose: 'first',
25 render: 'first'
26 }
27})
28
29exports.create = function (api) {
30 const route = '/private'
31
32 return nest({
33 'app.html': {
34 page: privatePage,
35 menuItem: menuItem
36 }
37 })
38
39 function menuItem () {
40 return h('a', {
41 style: { order: 2 },
42 'ev-click': () => api.app.sync.goTo(route)
43 }, route)
44 }
45
46 function privatePage (path) {
47 if (path !== route) return
48
49 const id = api.keys.sync.id()
50
51 const composer = api.message.html.compose({
52 meta: { type: 'post' },
53 prepublish: meta => {
54 meta.recps = [id, ...(meta.mentions || [])]
55 .filter(m => ref.isFeed(typeof m === 'string' ? m : m.link))
56 return meta
57 },
58 placeholder: 'Write a private message. \n\n@mention users in the first message to start a private thread.'}
59 )
60 const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw)
61 const { container, content } = api.app.html.scroller({ prepend: [ composer, filterMenu ] })
62
63 function draw () {
64 resetFeed({ container, content })
65
66 pull(
67 next(api.feed.pull.private, {old: false, limit: 100}),
68 filterDownThrough(),
69 Scroller(container, content, api.message.html.render, true, false)
70 )
71
72 pull(
73 next(api.feed.pull.private, {reverse: true, limit: 100, live: false}),
74 filterUpThrough(),
75 Scroller(container, content, api.message.html.render, false, false)
76 )
77 }
78 draw()
79
80 return container
81 }
82}
83
84

Built with git-ssb-web