Files: a17cf2e975bdfd8c86fa1e1d91c50c7172ade5ff / feed / obs / recent.js
1131 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 | 'message.sync.timestamp': 'first' |
14 | }) |
15 | |
16 | exports.create = function (api) { |
17 | return nest('feed.obs.recent', function (limit) { |
18 | var stream = pull( |
19 | pullCat([ |
20 | api.sbot.pull.log({reverse: true, limit: limit || 50}), |
21 | api.sbot.pull.log({old: false}) |
22 | ]) |
23 | ) |
24 | |
25 | var result = MutantPullReduce(stream, (result, msg) => { |
26 | if (api.message.sync.timestamp(msg) && Date.now() - api.message.sync.timestamp(msg) < 24 * hr) { |
27 | result.add(msg.value.author) |
28 | } |
29 | return result |
30 | }, { |
31 | startValue: new Set(), |
32 | nextTick: true |
33 | }) |
34 | |
35 | var instance = throttle(result, 2000) |
36 | instance.sync = result.sync |
37 | |
38 | instance.has = function (value) { |
39 | return computed(instance, x => x.has(value)) |
40 | } |
41 | |
42 | return instance |
43 | }) |
44 | } |
45 |
Built with git-ssb-web