Files: cc390daa09626dec00f9649bd2685152e9466432 / feed / pull / channel.js
984 bytesRaw
1 | const nest = require('depnest') |
2 | const extend = require('xtend') |
3 | var pull = require('pull-stream') |
4 | |
5 | exports.gives = nest('feed.pull.channel') |
6 | exports.needs = nest({ |
7 | 'sbot.pull.backlinks': 'first', |
8 | 'message.sync.isBlocked': 'first' |
9 | }) |
10 | |
11 | exports.create = function (api) { |
12 | return nest('feed.pull.channel', function (channel) { |
13 | if (typeof channel !== 'string') throw new Error('a channel name be specified') |
14 | |
15 | return function (opts) { |
16 | // handle last item passed in as lt |
17 | var lt = (opts.lt && opts.lt.value) |
18 | ? opts.lt.value.timestamp |
19 | : opts.lt |
20 | |
21 | delete opts.lt |
22 | |
23 | var filter = { |
24 | dest: `#${channel}`, |
25 | value: { |
26 | timestamp: typeof lt === 'number' ? {$lt: lt, $gt: 0} : {$gt: 0} |
27 | } |
28 | } |
29 | |
30 | return pull( |
31 | api.sbot.pull.backlinks(extend(opts, { |
32 | query: [ |
33 | {$filter: filter} |
34 | ] |
35 | })), |
36 | pull.filter(msg => !api.message.sync.isBlocked(msg)) |
37 | ) |
38 | } |
39 | }) |
40 | } |
41 |
Built with git-ssb-web