diff options
-rw-r--r-- | lib/app.js | 88 |
1 files changed, 43 insertions, 45 deletions
@@ -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}), |