Files: 2fa730eec372caa5716f6f3d614b8f6bf59a5616 / feed / obs / recent.js
1070 bytesRaw
1 | var pull = require('pull-stream') |
2 | var pullCat = require('pull-cat') |
3 | var computed = require('mutant/computed') |
4 | var MutantPullReduce = require('mutant-pull-reduce') |
5 | var throttle = require('mutant/throttle') |
6 | var nest = require('depnest') |
7 | var hr = 60 * 60 * 1000 |
8 | |
9 | exports.gives = nest('feed.obs.recent') |
10 | |
11 | exports.needs = nest({ |
12 | 'sbot.pull.log': 'first' |
13 | }) |
14 | |
15 | exports.create = function (api) { |
16 | return nest('feed.obs.recent', function (limit) { |
17 | var stream = pull( |
18 | pullCat([ |
19 | api.sbot.pull.log({reverse: true, limit: limit || 50}), |
20 | api.sbot.pull.log({old: false}) |
21 | ]) |
22 | ) |
23 | |
24 | var result = MutantPullReduce(stream, (result, msg) => { |
25 | if (msg.value.timestamp && Date.now() - msg.value.timestamp < 24 * hr) { |
26 | result.add(msg.value.author) |
27 | } |
28 | return result |
29 | }, { |
30 | startValue: new Set(), |
31 | nextTick: true |
32 | }) |
33 | |
34 | var instance = throttle(result, 2000) |
35 | instance.sync = result.sync |
36 | |
37 | instance.has = function (value) { |
38 | return computed(instance, x => x.has(value)) |
39 | } |
40 | |
41 | return instance |
42 | }) |
43 | } |
44 |
Built with git-ssb-web