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