Files: 2aba282967b6a030aeb637a4592a0572ac1451b7 / lib / depject / feed / obs / recent.js
1145 bytesRaw
1 | const pull = require('pull-stream') |
2 | const pullCat = require('pull-cat') |
3 | const computed = require('mutant/computed') |
4 | const MutantPullReduce = require('mutant-pull-reduce') |
5 | const throttle = require('mutant/throttle') |
6 | const nest = require('depnest') |
7 | const hr = 60 * 60 * 1000 |
8 | const getTimestamp = require('../../../get-timestamp') |
9 | |
10 | exports.gives = nest('feed.obs.recent') |
11 | |
12 | exports.needs = nest({ |
13 | 'sbot.pull.log': 'first' |
14 | }) |
15 | |
16 | exports.create = function (api) { |
17 | return nest('feed.obs.recent', function (limit) { |
18 | const 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 | const result = MutantPullReduce(stream, (result, msg) => { |
26 | if (getTimestamp(msg) && Date.now() - getTimestamp(msg) < 24 * hr) { |
27 | result.add(msg.value.author) |
28 | } |
29 | return result |
30 | }, { |
31 | startValue: new Set(), |
32 | nextTick: true |
33 | }) |
34 | |
35 | const 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