Files: 5149067cc270bfcbf301fd7c1db66cd15659a53f / app / page / notifications.js
2223 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 | '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 - this currently hits mentions AND the patchwork message replies |
61 | function pullMentions (opts) { |
62 | const query = [{ |
63 | $filter: { |
64 | dest: api.keys.sync.id(), |
65 | timestamp: {$gt: 0}, |
66 | value: { |
67 | author: {$ne: api.keys.sync.id()}, // not my messages! |
68 | private: {$ne: true} // not private mentions |
69 | } |
70 | } |
71 | }] |
72 | |
73 | const _opts = Object.assign({ |
74 | query, |
75 | limit: 100, |
76 | index: 'DTA' |
77 | }, opts) |
78 | |
79 | return api.sbot.pull.stream(server => { |
80 | return pull( |
81 | next(server.backlinks.read, _opts, ['timestamp']), |
82 | pull.filter(m => !api.message.sync.isBlocked(m)) |
83 | ) |
84 | }) |
85 | } |
86 | } |
87 |
Built with git-ssb-web