git ssb

16+

Dominic / patchbay



Tree: 6aed4c72a3b36330eb67723b515b426ec7f5f06d

Files: 6aed4c72a3b36330eb67723b515b426ec7f5f06d / app / page / private.js

2312 bytesRaw
1const nest = require('depnest')
2const { h } = require('mutant')
3const pull = require('pull-stream')
4const Scroller = require('pull-scroll')
5const ref = require('ssb-ref')
6const next = require('pull-next-query')
7
8exports.gives = nest({
9 'app.html.menuItem': true,
10 'app.page.private': true
11})
12
13exports.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
27exports.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 style: { order: 2 },
36 'ev-click': () => api.app.sync.goTo({ page: 'private' })
37 }, '/private')
38 }
39
40 function privatePage (location) {
41 const id = api.keys.sync.id()
42
43 const composer = api.message.html.compose({
44 location,
45 meta: { type: 'post' },
46 prepublish: content => {
47 content.recps = [id, ...(content.mentions || [])]
48 .filter(m => ref.isFeed(typeof m === 'string' ? m : m.link))
49 return content
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 pullPrivate({old: false, live: true}),
61 filterDownThrough(),
62 Scroller(container, content, api.message.html.render, true, false)
63 )
64
65 pull(
66 pullPrivate({reverse: true}),
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 function pullPrivate (opts) {
78 const query = [{
79 $filter: {
80 timestamp: {$gt: 0},
81 value: {
82 content: {
83 recps: {$truthy: true}
84 }
85 }
86 }
87 }]
88
89 const _opts = Object.assign({ query, limit: 100 }, opts)
90
91 return next(api.feed.pull.private, _opts, ['timestamp'])
92 }
93}
94

Built with git-ssb-web