aboutsummaryrefslogtreecommitdiff
path: root/lib/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/app.js')
-rw-r--r--lib/app.js59
1 files changed, 35 insertions, 24 deletions
diff --git a/lib/app.js b/lib/app.js
index fbdbb8f..b554f31 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -390,15 +390,13 @@ App.prototype.createLogStream = function (opts) {
App.prototype.createFeedStream = function (opts) {
// work around opts.gt being treated as opts.gte sometimes
- var limit = Number(opts.limit)
- if (opts.gt && limit && !opts.reverse) return pull(
- this.sbot.createFeedStream(u.mergeOpts(opts, {limit: opts.limit + 1})),
+ return pull(
+ this.sbot.createFeedStream(opts),
pull.filter(function (msg) {
- return msg && msg.value.timestamp !== opts.gt
- }),
- limit && pull.take(limit)
+ var ts = msg && msg.value && msg.value.timestamp
+ return typeof ts === 'number' && ts !== opts.gt && ts !== opts.lt
+ })
)
- return this.sbot.createFeedStream(opts)
}
var stateVals = {
@@ -593,25 +591,38 @@ App.prototype.filter = function (plugin, opts, filter) {
if (plugin === this.sbot.backlinks) {
var c = filter && filter.value && filter.value.content
var filteringByType = c && c.type
- if (!filteringByType) index = 'DTS'
+ if (opts.sortByTimestamp) index = 'DTA'
+ else if (filteringByType) index = 'DTS'
}
- // work around flumeview-query not supporting $lt/$gt.
- // %FCIv0D7JQyERznC18p8Dc1KtN6SLeJAl1sR5DAIr/Ek=.sha256
+ var filterOpts = {
+ $gt: opts.gt,
+ $lt: opts.lt,
+ }
+ return plugin.read({
+ index: index,
+ reverse: opts.reverse,
+ limit: limit || undefined,
+ query: [{$filter: u.mergeOpts(filter, opts.sortByTimestamp ? {
+ value: {
+ timestamp: filterOpts
+ }
+ } : {
+ timestamp: filterOpts
+ })}]
+ })
+}
+
+App.prototype.filterMessages = function (opts) {
+ var self = this
+ var limit = Number(opts.limit)
return pull(
- plugin.read({
- index: index,
- reverse: opts.reverse,
- limit: limit ? (limit + 1) : undefined,
- query: [{$filter: u.mergeOpts(filter, {
- timestamp: {
- $gte: opts.gt,
- $lte: opts.lt,
- }
- })}]
- }),
- pull.filter(function (msg) {
- return msg && msg.timestamp !== opts.lt && msg.timestamp !== opts.gt
- }),
+ paramap(function (msg, cb) {
+ self.filterMsg(msg, opts, function (err, show) {
+ if (err) return cb(err)
+ cb(null, show ? msg : null)
+ })
+ }, 4),
+ pull.filter(Boolean),
limit && pull.take(limit)
)
}