git ssb

10+

Matt McKegg / patchwork



Tree: 40388d6b54ff2c0d8c314271ce81dcbd0d3797d2

Files: 40388d6b54ff2c0d8c314271ce81dcbd0d3797d2 / modules / profile / obs / recently-updated.js

1172 bytesRaw
1var pull = require('pull-stream')
2var pullCat = require('pull-cat')
3var computed = require('mutant/computed')
4var MutantPullReduce = require('mutant-pull-reduce')
5var throttle = require('mutant/throttle')
6var nest = require('depnest')
7var hr = 60 * 60 * 1000
8
9exports.needs = nest({
10 'sbot.pull.feed': 'first'
11})
12
13exports.gives = nest('profile.obs.recentlyUpdated')
14
15exports.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