Files: e60e5d5babcf3ccea09fc5a26070cf5715c0fed4 / app / page / private.js
2076 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 | location, |
46 | meta: { type: 'post' }, |
47 | prepublish: meta => { |
48 | meta.recps = [id, ...(meta.mentions || [])] |
49 | .filter(m => ref.isFeed(typeof m === 'string' ? m : m.link)) |
50 | return meta |
51 | }, |
52 | placeholder: 'Write a private message. \n\n@mention users in the first message to start a private thread.'} |
53 | ) |
54 | const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw) |
55 | const { container, content } = api.app.html.scroller({ prepend: [ composer, filterMenu ] }) |
56 | |
57 | function draw () { |
58 | resetFeed({ container, content }) |
59 | |
60 | pull( |
61 | next(api.feed.pull.private, {old: false, limit: 100}, ['value', 'timestamp']), |
62 | filterDownThrough(), |
63 | Scroller(container, content, api.message.html.render, true, false) |
64 | ) |
65 | |
66 | pull( |
67 | next(api.feed.pull.private, {reverse: true, limit: 100, live: false}, ['value', 'timestamp']), |
68 | filterUpThrough(), |
69 | Scroller(container, content, api.message.html.render, false, false) |
70 | ) |
71 | } |
72 | draw() |
73 | |
74 | container.title = '/private' |
75 | return container |
76 | } |
77 | } |
78 |
Built with git-ssb-web