git ssb

16+

Dominic / patchbay



Commit 5a0a8b1bf0849bb367b0ce1887b089a2274b3547

Merge branch 'optimize-notif' of https://github.com/clehner/patchbay

Dominic Tarr committed on 7/11/2016, 11:30:09 PM
Parent: 7b5aad6c91e888f4a6188917716321f5f10de284
Parent: 6a04c1500ae5d062c3a688cf9677d5229a8ca9b1

Files changed

modules/notifications.jschanged
modules/notifications.jsView
@@ -3,13 +3,15 @@
33 var pull = require('pull-stream')
44 var Scroller = require('pull-scroll')
55 var paramap = require('pull-paramap')
66 var plugs = require('../plugs')
7+var cont = require('cont')
78
89 var message_render = plugs.first(exports.message_render = [])
910 var sbot_log = plugs.first(exports.sbot_log = [])
1011 var sbot_whoami = plugs.first(exports.sbot_whoami = [])
1112 var sbot_get = plugs.first(exports.sbot_get = [])
13+var sbot_user_feed = plugs.first(exports.sbot_user_feed = [])
1214 var message_unbox = plugs.first(exports.message_unbox = [])
1315
1416 function unbox() {
1517 return pull(
@@ -47,17 +49,16 @@
4749 return cb(null, msg)
4850
4951 switch (c.type) {
5052 case 'post':
51- if (c.branch)
52- return isOurMsg(c.branch, function (err, isOurs) {
53+ if (c.branch || c.root)
54+ cont.para([].concat(c.branch, c.root).map(function (id) {
55+ return function (cb) { isOurMsg(id, cb) }
56+ }))
57+ (function (err, results) {
5358 if (err) cb(err)
54- else if (isOurs) cb(null, msg)
55- else if (c.root) isOurMsg(c.root, function (err, isOurs) {
56- if (err) cb(err)
57- else if (isOurs) cb(null, msg)
58- else cb()
59- })
59+ else if (results.some(Boolean)) cb(null, msg)
60+ else cb()
6061 })
6162 else return cb()
6263
6364 case 'contact':
@@ -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