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