git ssb

16+

Dominic / patchbay



Tree: f4403f27a548f4b7a08d65c2c8e8664b2594fff1

Files: f4403f27a548f4b7a08d65c2c8e8664b2594fff1 / app / html / page / private.js

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

Built with git-ssb-web