Files: 996cb9ffec97abd3bf8391f3a15e462d01fd663d / modules / obs-recently-updated-feeds.js
964 bytesRaw
1 | var pull = require('pull-stream') |
2 | var pullCat = require('pull-cat') |
3 | var computed = require('@mmckegg/mutant/computed') |
4 | var MutantPullReduce = require('../lib/mutant-pull-reduce') |
5 | var plugs = require('patchbay/plugs') |
6 | var sbot_log = plugs.first(exports.sbot_log = []) |
7 | var throttle = require('@mmckegg/mutant/throttle') |
8 | var hr = 60 * 60 * 1000 |
9 | |
10 | exports.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