Files: c4c384106bcf50acf4c0fcb3f7b842ad68f25bcb / app / page / notifications.js
2613 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, render, true, false) |
46 | ) |
47 | |
48 | pull( |
49 | pullMentions({ reverse: true, live: false }), |
50 | filterUpThrough(), |
51 | Scroller(container, content, render, false, false) |
52 | ) |
53 | } |
54 | draw() |
55 | |
56 | container.title = '/notifications' |
57 | return container |
58 | } |
59 | |
60 | function render (msg) { |
61 | return api.message.html.render(msg, { showTitle: true }) |
62 | } |
63 | |
64 | // NOTE - currently this stream is know to pick up: |
65 | // - post mentions (public) |
66 | // - patchwork replies (public) |
67 | // - scry (public, private) |
68 | |
69 | function pullMentions (opts) { |
70 | const query = [{ |
71 | $filter: { |
72 | dest: api.keys.sync.id(), |
73 | timestamp: { $gt: 0 } |
74 | } |
75 | }, { |
76 | $filter: { |
77 | value: { |
78 | author: { $ne: api.keys.sync.id() } // not my messages! |
79 | // NOTE putting this in second filter might be necessary to stop index trying to use this author value |
80 | } |
81 | } |
82 | }] |
83 | |
84 | const _opts = Object.assign({ |
85 | query, |
86 | limit: 100, |
87 | index: 'DTA' |
88 | }, opts) |
89 | |
90 | return api.sbot.pull.stream(server => { |
91 | return pull( |
92 | next(server.backlinks.read, _opts, ['timestamp']), |
93 | pull.filter(m => { |
94 | if (m.value.content.type !== 'post') return true |
95 | return !m.value.private // no private posts |
96 | }), |
97 | pull.filter(m => !api.message.sync.isBlocked(m)) |
98 | ) |
99 | }) |
100 | } |
101 | } |
102 |
Built with git-ssb-web