Files: 82d822ecee3bb75d95896d138696e9213437d36f / app / html / page / private.js
2021 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('../../../junk/next-stepper') |
6 | const ref = require('ssb-ref') |
7 | |
8 | exports.gives = nest({ |
9 | 'app.html': { |
10 | page: true, |
11 | menuItem: true |
12 | } |
13 | }) |
14 | |
15 | exports.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 | |
29 | exports.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