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