git ssb

16+

Dominic / patchbay



Tree: 061795bee1aa4edbfd8a050dc27d10cc020a8360

Files: 061795bee1aa4edbfd8a050dc27d10cc020a8360 / app / page / notifications.js

2250 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 style: { order: 3 },
32 'ev-click': () => api.app.sync.goTo({ page: 'notifications' })
33 }, '/notifications')
34 }
35
36 function notificationsPage (location) {
37 const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw)
38 const { container, content } = api.app.html.scroller({ prepend: [ filterMenu ] })
39
40 function draw () {
41 resetFeed({ container, content })
42
43 pull(
44 pullMentions({old: false, live: true}),
45 filterDownThrough(),
46 Scroller(container, content, api.message.html.render, true, false)
47 )
48
49 pull(
50 pullMentions({reverse: true, live: false}),
51 filterUpThrough(),
52 Scroller(container, content, api.message.html.render, false, false)
53 )
54 }
55 draw()
56
57 container.title = '/notifications'
58 return container
59 }
60
61 // NOTE - this currently hits mentions AND the patchwork message replies
62 function pullMentions (opts) {
63 const query = [{
64 $filter: {
65 dest: api.keys.sync.id(),
66 timestamp: {$gt: 0},
67 value: {
68 author: {$ne: api.keys.sync.id()}, // not my messages!
69 private: {$ne: true} // not private mentions
70 }
71 }
72 }]
73
74 const _opts = Object.assign({
75 query,
76 limit: 100,
77 index: 'DTA'
78 }, opts)
79
80 return api.sbot.pull.stream(server => {
81 return pull(
82 next(server.backlinks.read, _opts, ['timestamp']),
83 pull.filter(m => !api.message.sync.isBlocked(m))
84 )
85 })
86 }
87}
88

Built with git-ssb-web