git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: b2886f60b5b31141643c0ea134c62b9e8e0db8e2

Files: b2886f60b5b31141643c0ea134c62b9e8e0db8e2 / modules / obs-recently-updated-feeds.js

964 bytesRaw
1var pull = require('pull-stream')
2var pullCat = require('pull-cat')
3var computed = require('@mmckegg/mutant/computed')
4var MutantPullReduce = require('../lib/mutant-pull-reduce')
5var plugs = require('patchbay/plugs')
6var sbot_log = plugs.first(exports.sbot_log = [])
7var throttle = require('@mmckegg/mutant/throttle')
8var hr = 60 * 60 * 1000
9
10exports.obs_recently_updated_feeds = function (limit) {
11 var stream = pull(
12 pullCat([
13 sbot_log({reverse: true, limit: limit || 500}),
14 sbot_log({old: false})
15 ])
16 )
17
18 var result = MutantPullReduce(stream, (result, msg) => {
19 if (msg.value.timestamp && Date.now() - msg.value.timestamp < 24 * hr) {
20 result.add(msg.value.author)
21 }
22 return result
23 }, {
24 startValue: new Set(),
25 nextTick: true
26 })
27
28 var instance = throttle(result, 2000)
29 instance.sync = result.sync
30
31 instance.has = function (value) {
32 return computed(instance, x => x.has(value))
33 }
34
35 return instance
36}
37

Built with git-ssb-web