Commit 5a0a8b1bf0849bb367b0ce1887b089a2274b3547
Merge branch 'optimize-notif' of https://github.com/clehner/patchbay
Dominic Tarr committed on 7/11/2016, 11:30:09 PMParent: 7b5aad6c91e888f4a6188917716321f5f10de284
Parent: 6a04c1500ae5d062c3a688cf9677d5229a8ca9b1
Files changed
modules/notifications.js | changed |
modules/notifications.js | ||
---|---|---|
@@ -3,13 +3,15 @@ | ||
3 | 3 | var pull = require('pull-stream') |
4 | 4 | var Scroller = require('pull-scroll') |
5 | 5 | var paramap = require('pull-paramap') |
6 | 6 | var plugs = require('../plugs') |
7 | +var cont = require('cont') | |
7 | 8 | |
8 | 9 | var message_render = plugs.first(exports.message_render = []) |
9 | 10 | var sbot_log = plugs.first(exports.sbot_log = []) |
10 | 11 | var sbot_whoami = plugs.first(exports.sbot_whoami = []) |
11 | 12 | var sbot_get = plugs.first(exports.sbot_get = []) |
13 | +var sbot_user_feed = plugs.first(exports.sbot_user_feed = []) | |
12 | 14 | var message_unbox = plugs.first(exports.message_unbox = []) |
13 | 15 | |
14 | 16 | function unbox() { |
15 | 17 | return pull( |
@@ -47,17 +49,16 @@ | ||
47 | 49 | return cb(null, msg) |
48 | 50 | |
49 | 51 | switch (c.type) { |
50 | 52 | 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) { | |
53 | 58 | 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() | |
60 | 61 | }) |
61 | 62 | else return cb() |
62 | 63 | |
63 | 64 | case 'contact': |
@@ -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