git ssb

1+

Daan Patchwork / patchwork



Tree: 2aba282967b6a030aeb637a4592a0572ac1451b7

Files: 2aba282967b6a030aeb637a4592a0572ac1451b7 / lib / depject / feed / obs / recent.js

1145 bytesRaw
1const pull = require('pull-stream')
2const pullCat = require('pull-cat')
3const computed = require('mutant/computed')
4const MutantPullReduce = require('mutant-pull-reduce')
5const throttle = require('mutant/throttle')
6const nest = require('depnest')
7const hr = 60 * 60 * 1000
8const getTimestamp = require('../../../get-timestamp')
9
10exports.gives = nest('feed.obs.recent')
11
12exports.needs = nest({
13 'sbot.pull.log': 'first'
14})
15
16exports.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