Files: 47f9ac92e1cabfef73b71fea878e805a70994e87 / router / html / page / private.js
1703 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 | 'router.html': { |
10 | page: true, |
11 | simpleRoute: true |
12 | } |
13 | }) |
14 | |
15 | exports.needs = nest({ |
16 | 'feed.pull.private': 'first', |
17 | 'keys.sync.id': 'first', |
18 | 'main.html.scroller': 'first', |
19 | 'message.html': { |
20 | compose: 'first', |
21 | render: 'first' |
22 | } |
23 | }) |
24 | |
25 | exports.create = function (api) { |
26 | const route = '/private' |
27 | |
28 | return nest({ |
29 | 'router.html': { |
30 | page: privatePage, |
31 | simpleRoute: menuItem |
32 | } |
33 | }) |
34 | |
35 | function menuItem (handleClick) { |
36 | return h('a', { |
37 | style: { order: 2 }, |
38 | 'ev-click': () => handleClick(route) |
39 | }, route) |
40 | } |
41 | |
42 | function privatePage (path) { |
43 | if (path !== route) return |
44 | |
45 | const id = api.keys.sync.id() |
46 | |
47 | const composer = api.message.html.compose({ |
48 | meta: { type: 'post' }, |
49 | prepublish: meta => { |
50 | meta.recps = [id, ...meta.mentions] |
51 | .filter(m => ref.isFeed(typeof m === 'string' ? m : m.link)) |
52 | return meta |
53 | }, |
54 | placeholder: 'Write a private message. \n\n@mention users in the first message to start a private thread.'} |
55 | ) |
56 | const { container, content } = api.main.html.scroller({ prepend: composer }) |
57 | |
58 | pull( |
59 | next(api.feed.pull.private, {old: false, limit: 100}), |
60 | Scroller(container, content, api.message.html.render, true, false) |
61 | ) |
62 | |
63 | pull( |
64 | next(api.feed.pull.private, {reverse: true, limit: 100, live: false}), |
65 | Scroller(container, content, api.message.html.render, false, false) |
66 | ) |
67 | |
68 | return container |
69 | } |
70 | } |
71 | |
72 |
Built with git-ssb-web