Files: ee8e82af460b4067e37ca225319fad117e33b584 / app / page / notifications.js
4424 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, onceTrue, throttle, Value, Array: MutantArray, map, resolve } = 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 | // 'blog.sync.isBlog': 'first', |
13 | // 'feed.pull.public': 'first', |
14 | // 'feed.pull.type': 'first', |
15 | // 'history.sync.push': 'first', |
16 | // 'keys.sync.id': 'first', |
17 | // 'message.sync.isBlocked': 'first', |
18 | 'sbot.obs.connection': 'first', |
19 | 'translations.sync.strings': 'first' |
20 | // 'unread.sync.isUnread': 'first' |
21 | }) |
22 | |
23 | exports.create = (api) => { |
24 | // var blogsCache = MutantArray() |
25 | |
26 | return nest('app.page.notifications', function (location) { |
27 | // location here can expected to be: { page: 'notifications'} |
28 | |
29 | var strings = api.translations.sync.strings() |
30 | |
31 | var commentsStore = MutantArray([]) |
32 | |
33 | onceTrue(api.sbot.obs.connection, server => { |
34 | console.log('methods', server.blogStats) |
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(throttle(commentsStore, 300), comment => { |
93 | const text = comment.value.content.text |
94 | |
95 | return h('p', { style: { margin: '1rem' } }, text) |
96 | })) |
97 | ]) |
98 | }) |
99 | |
100 | /* function update (soFar, newBlog) { */ |
101 | // soFar.transaction(() => { |
102 | // const { timestamp } = newBlog.value |
103 | |
104 | // var object = newBlog // Value(newBlog) |
105 | |
106 | // const index = indexOf(soFar, (blog) => newBlog.key === resolve(blog).key) |
107 | // // if blog already in cache, not needed again |
108 | // if (index >= 0) return |
109 | |
110 | // // Orders by: time received |
111 | // const justOlderPosition = indexOf(soFar, (msg) => newBlog.timestamp > resolve(msg).timestamp) |
112 | |
113 | // // Orders by: time published BUT the messagesByType stream streams _by time received_ |
114 | // // TODO - we need an index of all blogs otherwise the scroller doesn't work... |
115 | // // const justOlderPosition = indexOf(soFar, (msg) => timestamp > resolve(msg).value.timestamp) |
116 | |
117 | // if (justOlderPosition > -1) { |
118 | // soFar.insert(object, justOlderPosition) |
119 | // } else { |
120 | // soFar.push(object) |
121 | // } |
122 | // }) |
123 | // } |
124 | |
125 | // function render (blog) { |
126 | // const { recps, channel } = blog.value.content |
127 | // var onClick |
128 | // if (channel && !recps) { onClick = (ev) => api.history.sync.push(Object.assign({}, blog, { page: 'blogShow' })) } |
129 | // return api.app.html.blogCard(blog, { onClick }) |
130 | // } |
131 | // } |
132 | |
133 | // function indexOf (array, fn) { |
134 | // for (var i = 0; i < array.getLength(); i++) { |
135 | // if (fn(array.get(i))) { |
136 | // return i |
137 | // } |
138 | // } |
139 | // return -1 |
140 | } |
141 |
Built with git-ssb-web