git ssb

16+

Dominic / patchbay



Tree: 652ecbb4cd7581d318f8a02e163001b78d13ee25

Files: 652ecbb4cd7581d318f8a02e163001b78d13ee25 / app / page / notifications.js

2555 bytesRaw
1const nest = require('depnest')
2const { h } = require('mutant')
3const pull = require('pull-stream')
4const Scroller = require('pull-scroll')
5const next = require('pull-next-query')
6
7exports.gives = nest({
8 'app.html.menuItem': true,
9 'app.page.notifications': true
10})
11
12exports.needs = nest({
13 'app.html.filter': 'first',
14 'app.html.scroller': 'first',
15 'app.sync.goTo': 'first',
16 'feed.pull.public': 'first',
17 'keys.sync.id': 'first',
18 'message.html.render': 'first',
19 'message.sync.isBlocked': 'first',
20 'sbot.pull.stream': 'first'
21})
22
23exports.create = function (api) {
24 return nest({
25 'app.html.menuItem': menuItem,
26 'app.page.notifications': notificationsPage
27 })
28
29 function menuItem () {
30 return h('a', {
31 'ev-click': () => api.app.sync.goTo({ page: 'notifications' })
32 }, '/notifications')
33 }
34
35 function notificationsPage (location) {
36 const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw)
37 const { container, content } = api.app.html.scroller({ prepend: [ filterMenu ] })
38
39 function draw () {
40 resetFeed({ container, content })
41
42 pull(
43 pullMentions({ old: false, live: true }),
44 filterDownThrough(),
45 Scroller(container, content, api.message.html.render, true, false)
46 )
47
48 pull(
49 pullMentions({ reverse: true, live: false }),
50 filterUpThrough(),
51 Scroller(container, content, api.message.html.render, false, false)
52 )
53 }
54 draw()
55
56 container.title = '/notifications'
57 return container
58 }
59
60 // NOTE - currently this stream is know to pick up:
61 // - post mentions (public)
62 // - patchwork replies (public)
63 // - scry (public, private)
64
65 function pullMentions (opts) {
66 const query = [{
67 $filter: {
68 dest: api.keys.sync.id(),
69 timestamp: { $gt: 0 }
70 }
71 }, {
72 $filter: {
73 value: {
74 author: { $ne: api.keys.sync.id() } // not my messages!
75 // NOTE putting this in second filter might be necessary to stop index trying to use this author value
76 }
77 }
78 }]
79
80 const _opts = Object.assign({
81 query,
82 limit: 100,
83 index: 'DTA'
84 }, opts)
85
86 return api.sbot.pull.stream(server => {
87 return pull(
88 next(server.backlinks.read, _opts, ['timestamp']),
89 pull.filter(m => {
90 if (m.value.content.type !== 'post') return true
91 return !m.value.private // no private posts
92 }),
93 pull.filter(m => !api.message.sync.isBlocked(m))
94 )
95 })
96 }
97}
98

Built with git-ssb-web