Commit e255333d2b8e29f0eb913728c567b6d707c424bd
Early-exit notifications stream at feed's creation time
https://github.com/dominictarr/patchbay/pull/20#issuecomment-231618259Charles Lehner committed on 7/11/2016, 12:30:00 AM
Parent: 32539087acb264ece13da43b3bdb5917218ef083
Files changed
modules/notifications.js | changed |
modules/notifications.js | ||
---|---|---|
@@ -8,8 +8,9 @@ | ||
8 | 8 | var message_render = plugs.first(exports.message_render = []) |
9 | 9 | var sbot_log = plugs.first(exports.sbot_log = []) |
10 | 10 | var sbot_whoami = plugs.first(exports.sbot_whoami = []) |
11 | 11 | var sbot_get = plugs.first(exports.sbot_get = []) |
12 | +var sbot_user_feed = plugs.first(exports.sbot_user_feed = []) | |
12 | 13 | var message_unbox = plugs.first(exports.message_unbox = []) |
13 | 14 | |
14 | 15 | function unbox() { |
15 | 16 | return pull( |
@@ -75,14 +76,26 @@ | ||
75 | 76 | } |
76 | 77 | }, 4) |
77 | 78 | } |
78 | 79 | |
80 | +function getFirstMessage(feedId, cb) { | |
81 | + sbot_user_feed({id: feedId, gte: 0, limit: 1})(null, cb) | |
82 | +} | |
83 | + | |
79 | 84 | exports.screen_view = function (path) { |
80 | 85 | if(path === '/notifications') { |
81 | 86 | var ids = {} |
87 | + var oldest | |
88 | + | |
82 | 89 | sbot_whoami(function (err, me) { |
83 | 90 | if (err) return console.error(err) |
84 | 91 | 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 | + }) | |
85 | 98 | }) |
86 | 99 | |
87 | 100 | var content = h('div.column.scroller__content') |
88 | 101 | var div = h('div.column.scroller', |
@@ -104,8 +117,12 @@ | ||
104 | 117 | u.next(sbot_log, {reverse: true, limit: 100, live: false}), |
105 | 118 | unbox(), |
106 | 119 | notifications(ids), |
107 | 120 | 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 | + }), | |
108 | 125 | Scroller(div, content, message_render, false, false) |
109 | 126 | ) |
110 | 127 | |
111 | 128 | return div |
Built with git-ssb-web