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