Commit f36223600eba650b838fdb0b9f56048e1929c831
live updating counters
mix irving committed on 11/28/2017, 3:09:47 AMParent: 54bc98535d090b27d8ea15dbd3f12d0f613e6dc5
Files changed
app/html/context.js | changed |
app/html/context.js | ||
---|---|---|
@@ -34,21 +34,27 @@ | ||
34 | 34 | const myKey = api.keys.sync.id() |
35 | 35 | |
36 | 36 | var nearby = api.sbot.obs.localPeers() |
37 | 37 | |
38 | + // Unread message counts | |
39 | + const updateUserUnreadMsgsCache = (msg) => { | |
40 | + var cache = getUserUnreadMsgsCache(msg.value.author) | |
41 | + | |
42 | + if(api.unread.sync.isUnread(msg)) | |
43 | + cache.add(msg.key) | |
44 | + else | |
45 | + cache.delete(msg.key) | |
46 | + } | |
38 | 47 | pull( |
39 | 48 | next(api.feed.pull.private, {reverse: true, limit: 1000, live: false}, ['value', 'timestamp']), |
40 | - pull.filter(msg => msg.value.content.type === 'post'), // TODO is this the best way to protect against votes? | |
41 | - pull.filter(msg => msg.value.content.recps), | |
42 | - pull.filter(msg => msg.value.author !== myKey), | |
43 | - pull.drain(msg => { | |
44 | - var cache = getUserUnreadMsgsCache(msg.value.author) | |
49 | + privateMsgFilter(), | |
50 | + pull.drain(updateUserUnreadMsgsCache) | |
51 | + ) | |
45 | 52 | |
46 | - if(api.unread.sync.isUnread(msg)) | |
47 | - cache.add(msg.key) | |
48 | - else | |
49 | - cache.delete(msg.key) | |
50 | - }) | |
53 | + pull( | |
54 | + next(api.feed.pull.private, {old: false, live: true}, ['value', 'timestamp']), | |
55 | + privateMsgFilter(), | |
56 | + pull.drain(updateUserUnreadMsgsCache) | |
51 | 57 | ) |
52 | 58 | |
53 | 59 | //TODO: calculate unread state for public threads/blogs |
54 | 60 | // pull( |
@@ -103,13 +109,9 @@ | ||
103 | 109 | return api.app.html.scroller({ |
104 | 110 | classList: [ 'level', '-one' ], |
105 | 111 | prepend, |
106 | 112 | stream: api.feed.pull.private, |
107 | - filter: () => pull( | |
108 | - pull.filter(msg => msg.value.content.type === 'post'), | |
109 | - pull.filter(msg => msg.value.author != myKey), | |
110 | - pull.filter(msg => msg.value.content.recps) | |
111 | - ), | |
113 | + filter: privateMsgFilter, | |
112 | 114 | store: recentMsgCache, |
113 | 115 | updateTop: updateRecentMsgCache, |
114 | 116 | updateBottom: updateRecentMsgCache, |
115 | 117 | render: (msgObs) => { |
@@ -260,8 +262,16 @@ | ||
260 | 262 | ]), |
261 | 263 | h('div.label', { 'ev-click': goToLocation }, label) |
262 | 264 | ]) |
263 | 265 | } |
266 | + | |
267 | + function privateMsgFilter () { | |
268 | + return pull( | |
269 | + pull.filter(msg => msg.value.content.type === 'post'), | |
270 | + pull.filter(msg => msg.value.author != myKey), | |
271 | + pull.filter(msg => msg.value.content.recps) | |
272 | + ) | |
273 | + } | |
264 | 274 | } |
265 | 275 | } |
266 | 276 | |
267 | 277 | function indexOf (array, fn) { |
Built with git-ssb-web