git ssb

0+

ev / microbay



forked from Dominic / patchbay

Commit e255333d2b8e29f0eb913728c567b6d707c424bd

Early-exit notifications stream at feed's creation time

https://github.com/dominictarr/patchbay/pull/20#issuecomment-231618259
Charles Lehner committed on 7/11/2016, 12:30:00 AM
Parent: 32539087acb264ece13da43b3bdb5917218ef083

Files changed

modules/notifications.jschanged
modules/notifications.jsView
@@ -8,8 +8,9 @@
88 var message_render = plugs.first(exports.message_render = [])
99 var sbot_log = plugs.first(exports.sbot_log = [])
1010 var sbot_whoami = plugs.first(exports.sbot_whoami = [])
1111 var sbot_get = plugs.first(exports.sbot_get = [])
12+var sbot_user_feed = plugs.first(exports.sbot_user_feed = [])
1213 var message_unbox = plugs.first(exports.message_unbox = [])
1314
1415 function unbox() {
1516 return pull(
@@ -75,14 +76,26 @@
7576 }
7677 }, 4)
7778 }
7879
80+function getFirstMessage(feedId, cb) {
81+ sbot_user_feed({id: feedId, gte: 0, limit: 1})(null, cb)
82+}
83+
7984 exports.screen_view = function (path) {
8085 if(path === '/notifications') {
8186 var ids = {}
87+ var oldest
88+
8289 sbot_whoami(function (err, me) {
8390 if (err) return console.error(err)
8491 ids[me.id] = true
92+ getFirstMessage(me.id, function (err, msg) {
93+ if (err) return console.error(err)
94+ if (!oldest || msg.value.timestamp < oldest) {
95+ oldest = msg.value.timestamp
96+ }
97+ })
8598 })
8699
87100 var content = h('div.column.scroller__content')
88101 var div = h('div.column.scroller',
@@ -104,8 +117,12 @@
104117 u.next(sbot_log, {reverse: true, limit: 100, live: false}),
105118 unbox(),
106119 notifications(ids),
107120 pull.filter(),
121+ pull.take(function (msg) {
122+ // abort stream after we pass the oldest messages of our feeds
123+ return !oldest || msg.value.timestamp > oldest
124+ }),
108125 Scroller(div, content, message_render, false, false)
109126 )
110127
111128 return div

Built with git-ssb-web