git ssb

16+

Dominic / patchbay



Tree: ddabf06774e3c5a4d1e76831bc096791b8795042

Files: ddabf06774e3c5a4d1e76831bc096791b8795042 / app / page / notifications.js

2409 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 value: {
71 author: { $ne: api.keys.sync.id() } // not my messages!
72 }
73 }
74 }]
75
76 const _opts = Object.assign({
77 query,
78 limit: 100,
79 index: 'DTA'
80 }, opts)
81
82 return api.sbot.pull.stream(server => {
83 return pull(
84 next(server.backlinks.read, _opts, ['timestamp']),
85 pull.filter(m => {
86 if (m.value.content.type !== 'post') return true
87 return !m.value.private // no private posts
88 }),
89 pull.filter(m => !api.message.sync.isBlocked(m))
90 )
91 })
92 }
93}
94

Built with git-ssb-web