git ssb

7+

dinoworm ๐Ÿ› / patchcore



Tree: 7e1f67391c61eada0ba43cb809a353c048a5f097

Files: 7e1f67391c61eada0ba43cb809a353c048a5f097 / feed / obs / recent.js

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