Files: 07cfe9bf013a2baa61f2d075994dc78be9aa9309 / app / page / private.js
2060 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 | return nest({ |
30 | 'app.html.menuItem': menuItem, |
31 | 'app.page.private': privatePage |
32 | }) |
33 | |
34 | function menuItem () { |
35 | return h('a', { |
36 | style: { order: 2 }, |
37 | 'ev-click': () => api.app.sync.goTo({ page: 'private' }) |
38 | }, '/private') |
39 | } |
40 | |
41 | function privatePage (location) { |
42 | const id = api.keys.sync.id() |
43 | |
44 | const composer = api.message.html.compose({ |
45 | meta: { type: 'post' }, |
46 | prepublish: meta => { |
47 | meta.recps = [id, ...(meta.mentions || [])] |
48 | .filter(m => ref.isFeed(typeof m === 'string' ? m : m.link)) |
49 | return meta |
50 | }, |
51 | placeholder: 'Write a private message. \n\n@mention users in the first message to start a private thread.'} |
52 | ) |
53 | const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw) |
54 | const { container, content } = api.app.html.scroller({ prepend: [ composer, filterMenu ] }) |
55 | |
56 | function draw () { |
57 | resetFeed({ container, content }) |
58 | |
59 | pull( |
60 | next(api.feed.pull.private, {old: false, limit: 100}, ['value', 'timestamp']), |
61 | filterDownThrough(), |
62 | Scroller(container, content, api.message.html.render, true, false) |
63 | ) |
64 | |
65 | pull( |
66 | next(api.feed.pull.private, {reverse: true, limit: 100, live: false}, ['value', 'timestamp']), |
67 | filterUpThrough(), |
68 | Scroller(container, content, api.message.html.render, false, false) |
69 | ) |
70 | } |
71 | draw() |
72 | |
73 | container.title = '/private' |
74 | return container |
75 | } |
76 | } |
77 |
Built with git-ssb-web