git ssb

2+

mixmix / ticktack



Commit f36223600eba650b838fdb0b9f56048e1929c831

live updating counters

mix irving committed on 11/28/2017, 3:09:47 AM
Parent: 54bc98535d090b27d8ea15dbd3f12d0f613e6dc5

Files changed

app/html/context.jschanged
app/html/context.jsView
@@ -34,21 +34,27 @@
3434 const myKey = api.keys.sync.id()
3535
3636 var nearby = api.sbot.obs.localPeers()
3737
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+ }
3847 pull(
3948 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+ )
4552
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)
5157 )
5258
5359 //TODO: calculate unread state for public threads/blogs
5460 // pull(
@@ -103,13 +109,9 @@
103109 return api.app.html.scroller({
104110 classList: [ 'level', '-one' ],
105111 prepend,
106112 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,
112114 store: recentMsgCache,
113115 updateTop: updateRecentMsgCache,
114116 updateBottom: updateRecentMsgCache,
115117 render: (msgObs) => {
@@ -260,8 +262,16 @@
260262 ]),
261263 h('div.label', { 'ev-click': goToLocation }, label)
262264 ])
263265 }
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+ }
264274 }
265275 }
266276
267277 function indexOf (array, fn) {

Built with git-ssb-web