Files: c792588268e3e2efcd286ebe0d46e93b0f34bbb7 / modules / profile / obs / recently-updated.js
1172 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 | var instance = null |
17 | |
18 | return nest('profile.obs.recentlyUpdated', function () { |
19 | load() |
20 | return instance |
21 | }) |
22 | |
23 | function load () { |
24 | if (instance) return |
25 | |
26 | var stream = pull( |
27 | pullCat([ |
28 | api.sbot.pull.feed({reverse: true, limit: 4000}), |
29 | api.sbot.pull.feed({old: false}) |
30 | ]) |
31 | ) |
32 | |
33 | var result = MutantPullReduce(stream, (result, msg) => { |
34 | if (msg.value.timestamp && Date.now() - msg.value.timestamp < (7 * 24 * hr)) { |
35 | result.add(msg.value.author) |
36 | } |
37 | return result |
38 | }, { |
39 | startValue: new Set(), |
40 | nextTick: true |
41 | }) |
42 | |
43 | instance = throttle(result, 2000) |
44 | instance.sync = result.sync |
45 | |
46 | instance.has = function (value) { |
47 | return computed(instance, x => x.has(value)) |
48 | } |
49 | } |
50 | } |
51 |
Built with git-ssb-web