git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: abf8335c9c9187ce7b3861f372ce512d210e8a7b

Files: abf8335c9c9187ce7b3861f372ce512d210e8a7b / modules / profile / obs / recently-updated.js

1095 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.log': '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.log({reverse: true, limit: limit || 500}),
20 api.sbot.pull.log({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