Files: 6fd3ee341a376214993d0363c4c72161700b7fbc / modules / profile / obs / recently-updated.js
1098 bytesRaw
1 | var pull = require('pull-stream') |
2 | var pullCat = require('pull-cat') |
3 | var computed = require('mutant/computed') |
4 | var MutantPullReduce = require('mutant-pull-reduce') |
5 | var throttle = require('mutant/throttle') |
6 | var nest = require('depnest') |
7 | var hr = 60 * 60 * 1000 |
8 | |
9 | exports.needs = nest({ |
10 | 'sbot.pull.feed': 'first' |
11 | }) |
12 | |
13 | exports.gives = nest('profile.obs.recentlyUpdated') |
14 | |
15 | exports.create = function (api) { |
16 | return nest('profile.obs.recentlyUpdated', function (limit) { |
17 | var stream = pull( |
18 | pullCat([ |
19 | api.sbot.pull.feed({reverse: true, limit: limit || 500}), |
20 | api.sbot.pull.feed({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