git ssb

16+

Dominic / patchbay



Tree: 37e60d1deaaf54e61e2ecd58ec79b7d4ee7dc6e1

Files: 37e60d1deaaf54e61e2ecd58ec79b7d4ee7dc6e1 / app / page / notifications.js

3028 bytesRaw
1const nest = require('depnest')
2const { h } = require('mutant')
3const pull = require('pull-stream')
4const pullMerge = require('pull-merge')
5const Scroller = require('pull-scroll')
6const next = require('pull-next-query')
7const BookNotifications = require('scuttle-book/pull/notifications')
8
9exports.gives = nest({
10 'app.html.menuItem': true,
11 'app.page.notifications': true
12})
13
14exports.needs = nest({
15 'app.html.filter': 'first',
16 'app.html.scroller': 'first',
17 'app.sync.goTo': 'first',
18 'feed.pull.public': 'first',
19 'keys.sync.id': 'first',
20 'message.html.render': 'first',
21 'message.sync.isBlocked': 'first',
22 'sbot.pull.stream': 'first'
23})
24
25exports.create = function (api) {
26 return nest({
27 'app.html.menuItem': menuItem,
28 'app.page.notifications': notificationsPage
29 })
30
31 function menuItem () {
32 return h('a', {
33 'ev-click': () => api.app.sync.goTo({ page: 'notifications' })
34 }, '/notifications')
35 }
36
37 function notificationsPage (location) {
38 const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw)
39 const { container, content } = api.app.html.scroller({ prepend: [ filterMenu ] })
40
41 function draw () {
42 resetFeed({ container, content })
43
44 pull(
45 pullMentions({ old: false, live: true }),
46 filterDownThrough(),
47 Scroller(container, content, render, true, false)
48 )
49
50 pull(
51 pullMentions({ reverse: true, live: false }),
52 filterUpThrough(),
53 Scroller(container, content, render, false, false)
54 )
55 }
56 draw()
57
58 container.title = '/notifications'
59 return container
60 }
61
62 function render (msg) {
63 return api.message.html.render(msg, { showTitle: true })
64 }
65
66 // NOTE - currently this stream is know to pick up:
67 // - post mentions (public)
68 // - patchwork replies (public)
69 // - scry (public, private)
70 // - reviews on scuttle-books you posted (public)
71
72 function pullMentions (opts) {
73 const query = [{
74 $filter: {
75 dest: api.keys.sync.id(),
76 timestamp: { $gt: 0 }
77 }
78 }, {
79 $filter: {
80 value: {
81 author: { $ne: api.keys.sync.id() } // not my messages!
82 // NOTE putting this in second filter might be necessary to stop index trying to use this author value
83 }
84 }
85 }]
86
87 const _opts = Object.assign({
88 query,
89 limit: 100,
90 index: 'DTA'
91 }, opts)
92
93 return api.sbot.pull.stream(server => {
94 const bookNotifications = BookNotifications(server)
95 return pullMerge(
96 pull(
97 next(server.backlinks.read, _opts, ['timestamp']),
98 pull.filter(m => {
99 if (m.value.content.type !== 'post') return true
100 return !m.value.private // no private posts
101 }),
102 pull.filter(m => !api.message.sync.isBlocked(m))
103 ),
104 pull(bookNotifications(api.keys.sync.id(), opts)),
105 (lhs, rhs) => {
106 return rhs.value.timestamp - lhs.value.timestamp
107 }
108 )
109 })
110 }
111}
112

Built with git-ssb-web