aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-06-12 16:01:56 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-06-12 16:12:02 -1000
commit35fe45cff5223c7449614d5ae7ddc6da73d337ec (patch)
treec6b4a6d44df534e875534b6c148c5a746afa0bf4 /lib
parentdb2d73a056dc9c807827b42db337ba460dd730b2 (diff)
downloadpatchfoo-35fe45cff5223c7449614d5ae7ddc6da73d337ec.tar.gz
patchfoo-35fe45cff5223c7449614d5ae7ddc6da73d337ec.zip
Fix timestamp gt/lt handling
Diffstat (limited to 'lib')
-rw-r--r--lib/app.js88
1 files changed, 43 insertions, 45 deletions
diff --git a/lib/app.js b/lib/app.js
index eca2a9f..433a179 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -472,31 +472,42 @@ App.prototype.streamEmojis = function () {
)
}
-App.prototype.streamChannel = function (opts) {
- if (this.sbot.backlinks) return this.sbot.backlinks.read(u.mergeOpts(opts, {
- query: [{$filter: {
- dest: '#' + opts.channel,
- value: {
- content: {
- type: 'post'
+App.prototype.filter = function (plugin, opts, filter) {
+ // work around flumeview-query not supporting $lt/$gt.
+ // %FCIv0D7JQyERznC18p8Dc1KtN6SLeJAl1sR5DAIr/Ek=.sha256
+ return pull(
+ plugin.read({
+ reverse: opts.reverse,
+ limit: opts.limit && (opts.limit + 1),
+ query: [{$filter: u.mergeOpts(filter, {
+ timestamp: {
+ $gte: opts.gt,
+ $lte: opts.lt,
}
- },
- timestamp: {
- $gt: opts.gt,
- $lt: opts.lt,
- }
- }}]
- }))
-
- if (this.sbot.query) return this.sbot.query.read(u.mergeOpts(opts, {
- query: [{$filter: {
- value: {content: {channel: opts.channel}},
- timestamp: {
- $gt: opts.gt,
- $lt: opts.lt,
+ })}]
+ }),
+ pull.filter(function (msg) {
+ return msg && msg.timestamp !== opts.lt && msg.timestamp !== opts.gt
+ }),
+ opts.limit && pull.take(opts.limit)
+ )
+}
+
+App.prototype.streamChannel = function (opts) {
+ // prefer ssb-backlinks to ssb-query because it also handles hashtag mentions
+ if (this.sbot.backlinks) return this.filter(this.sbot.backlinks, opts, {
+ dest: '#' + opts.channel,
+ value: {
+ // filter by message type to work around %b+QdyLFQ21UGYwvV3AiD8FEr7mKlB8w9xx3h8WzSUb0=.sha256
+ content: {
+ type: 'post'
}
- }}]
- }))
+ }
+ })
+
+ if (this.sbot.query) return this.filter(this.sbot.query, opts, {
+ value: {content: {channel: opts.channel}},
+ })
return pull.error(new Error(
'Viewing channels/tags requires the ssb-backlinks or ssb-query plugin'))
@@ -506,32 +517,19 @@ App.prototype.streamMentions = function (opts) {
if (!this.sbot.backlinks) return pull.error(new Error(
'Viewing mentions requires the ssb-backlinks plugin'))
- if (this.sbot.backlinks) return this.sbot.backlinks.read(u.mergeOpts(opts, {
- query: [{$filter: {
- dest: this.sbot.id,
- value: {
- content: {
- type: 'post'
- }
- },
- timestamp: {
- $gt: opts.gt,
- $lt: opts.lt,
+ if (this.sbot.backlinks) return this.filter(this.sbot.backlinks, opts, {
+ dest: this.sbot.id,
+ value: {
+ // filter by message type to work around %b+QdyLFQ21UGYwvV3AiD8FEr7mKlB8w9xx3h8WzSUb0=.sha256
+ content: {
+ type: 'post'
}
- }}]
- }))
+ }
+ })
}
App.prototype.streamPrivate = function (opts) {
- if (this.sbot.private.read) return this.sbot.private.read(u.mergeOpts(opts, {
- query: [{$filter: {
- timestamp: {
- $gt: opts.gt,
- $lt: opts.lt,
- }
- }}]
- }))
-
+ if (this.sbot.private.read) return this.filter(this.sbot.private, opts, {})
return pull
this.createLogStream(u.mergeOpts(opts, {limit: null}),