Files: c31e472556bdb4d5a6a192709bcff72ce36f324a / app / page / notifications.js
2250 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 next = require('pull-next-query') |
6 | |
7 | exports.gives = nest({ |
8 | 'app.html.menuItem': true, |
9 | 'app.page.notifications': true |
10 | }) |
11 | |
12 | exports.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 | |
23 | exports.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