git ssb

10+

Matt McKegg / patchwork



Tree: 6fd3ee341a376214993d0363c4c72161700b7fbc

Files: 6fd3ee341a376214993d0363c4c72161700b7fbc / modules / profile / obs / recently-updated.js

1098 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 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