Files: 9ed5958b4528f84958df37e404fc8ec072d3632b / app / page / private.js
2285 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 ] }) |
54 | |
55 | function draw () { |
56 | resetFeed({ container, content }) |
57 | |
58 | pull( |
59 | pullPrivate({old: false, live: true}), |
60 | filterDownThrough(), |
61 | Scroller(container, content, api.message.html.render, true, false) |
62 | ) |
63 | |
64 | pull( |
65 | pullPrivate({reverse: true}), |
66 | filterUpThrough(), |
67 | Scroller(container, content, api.message.html.render, false, false) |
68 | ) |
69 | } |
70 | draw() |
71 | |
72 | container.title = '/private' |
73 | return container |
74 | } |
75 | |
76 | function pullPrivate (opts) { |
77 | const query = [{ |
78 | $filter: { |
79 | timestamp: {$gt: 0}, |
80 | value: { |
81 | content: { |
82 | recps: {$truthy: true} |
83 | } |
84 | } |
85 | } |
86 | }] |
87 | |
88 | const _opts = Object.assign({ query, limit: 100 }, opts) |
89 | |
90 | return next(api.feed.pull.private, _opts, ['timestamp']) |
91 | } |
92 | } |
93 |
Built with git-ssb-web