git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: e7b02af84a46b3c6ce2c5b9340093fa214b9600c

Files: e7b02af84a46b3c6ce2c5b9340093fa214b9600c / 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