Files: fea2881ae175c88bac926fcff65d32598742e9a1 / app / page / notifications.js
4461 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, onceTrue, throttle, Value, Array: MutantArray, map } = require('mutant') |
3 | const pull = require('pull-stream') |
4 | |
5 | exports.gives = nest('app.page.notifications') |
6 | |
7 | exports.needs = nest({ |
8 | // 'app.html.blogCard': 'first', |
9 | // 'app.html.topNav': 'first', |
10 | // 'app.html.scroller': 'first', |
11 | 'app.html.sideNav': 'first', |
12 | 'message.html.comment': 'first', |
13 | // 'blog.sync.isBlog': 'first', |
14 | // 'feed.pull.public': 'first', |
15 | // 'feed.pull.type': 'first', |
16 | // 'history.sync.push': 'first', |
17 | // 'keys.sync.id': 'first', |
18 | // 'message.sync.isBlocked': 'first', |
19 | 'sbot.obs.connection': 'first', |
20 | 'translations.sync.strings': 'first', |
21 | // 'unread.sync.isUnread': 'first' |
22 | }) |
23 | |
24 | exports.create = (api) => { |
25 | // var blogsCache = MutantArray() |
26 | |
27 | return nest('app.page.notifications', function (location) { |
28 | // location here can expected to be: { page: 'notifications'} |
29 | |
30 | var strings = api.translations.sync.strings() |
31 | |
32 | var commentsStore = MutantArray([]) |
33 | |
34 | onceTrue(api.sbot.obs.connection, server => { |
35 | pull( |
36 | server.blogStats.readAllComments(), |
37 | pull.drain(m => { |
38 | commentsStore.push(m) |
39 | }) |
40 | ) |
41 | }) |
42 | |
43 | // server.blogStats.getBlogs({ keys: true, values: false }, (err, data) => { |
44 | // if (err) throw err |
45 | |
46 | // const blogIds = data.map(d => d[1]) |
47 | |
48 | // var source = server.blogStats.read({ |
49 | // // live: true, |
50 | // gte: [ 'C', undefined, undefined ], |
51 | // lte: [ 'C~', null, null ], |
52 | // reverse: true, |
53 | // values: true, |
54 | // keys: true, |
55 | // seqs: false |
56 | // }) |
57 | // console.log(blogIds) |
58 | |
59 | // pull( |
60 | // source, |
61 | // pull.filter(result => { |
62 | // return blogIds.includes(result.key[1]) |
63 | // }), |
64 | // pull.map(result => result.value), |
65 | // pull.drain(m => { |
66 | // commentsStore.push(m) |
67 | // }) |
68 | // ) |
69 | // }) |
70 | // }) |
71 | |
72 | // var blogs = api.app.html.scroller({ |
73 | // classList: ['content'], |
74 | // prepend: api.app.html.topNav(location), |
75 | // // stream: api.feed.pull.public, |
76 | // stream: api.feed.pull.type('blog'), |
77 | // filter: () => pull( |
78 | // // pull.filter(api.blog.sync.isBlog), |
79 | // pull.filter(msg => !msg.value.content.root), // show only root messages |
80 | // pull.filter(msg => !api.message.sync.isBlocked(msg)) |
81 | // ), |
82 | // // FUTURE : if we need better perf, we can add a persistent cache. At the moment this page is fast enough though. |
83 | // // See implementation of app.html.sideNav for example |
84 | // store: blogsCache, |
85 | // updateTop: update, |
86 | // updateBottom: update, |
87 | // render |
88 | // }) |
89 | |
90 | return h('Page -notifications', [ |
91 | api.app.html.sideNav(location), |
92 | h('div.content', map( |
93 | throttle(commentsStore, 300), |
94 | msg => Comment(msg), |
95 | { |
96 | // comparer: (a, b) => a === b |
97 | } |
98 | )) |
99 | ]) |
100 | |
101 | function Comment (msg) { |
102 | return api.message.html.comment(msg) |
103 | } |
104 | }) |
105 | |
106 | /* function update (soFar, newBlog) { */ |
107 | // soFar.transaction(() => { |
108 | // const { timestamp } = newBlog.value |
109 | |
110 | // var object = newBlog // Value(newBlog) |
111 | |
112 | // const index = indexOf(soFar, (blog) => newBlog.key === resolve(blog).key) |
113 | // // if blog already in cache, not needed again |
114 | // if (index >= 0) return |
115 | |
116 | // // Orders by: time received |
117 | // const justOlderPosition = indexOf(soFar, (msg) => newBlog.timestamp > resolve(msg).timestamp) |
118 | |
119 | // // Orders by: time published BUT the messagesByType stream streams _by time received_ |
120 | // // TODO - we need an index of all blogs otherwise the scroller doesn't work... |
121 | // // const justOlderPosition = indexOf(soFar, (msg) => timestamp > resolve(msg).value.timestamp) |
122 | |
123 | // if (justOlderPosition > -1) { |
124 | // soFar.insert(object, justOlderPosition) |
125 | // } else { |
126 | // soFar.push(object) |
127 | // } |
128 | // }) |
129 | // } |
130 | |
131 | // function render (blog) { |
132 | // const { recps, channel } = blog.value.content |
133 | // var onClick |
134 | // if (channel && !recps) { onClick = (ev) => api.history.sync.push(Object.assign({}, blog, { page: 'blogShow' })) } |
135 | // return api.app.html.blogCard(blog, { onClick }) |
136 | // } |
137 | // } |
138 | |
139 | // function indexOf (array, fn) { |
140 | // for (var i = 0; i < array.getLength(); i++) { |
141 | // if (fn(array.get(i))) { |
142 | // return i |
143 | // } |
144 | // } |
145 | // return -1 |
146 | } |
147 |
Built with git-ssb-web