git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: be8e636ad6ac100c2299cc221a5e35e396a1ece6

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