git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 7ceec7443b73d5a618748aaefea62cbfa9b909b7

Files: 7ceec7443b73d5a618748aaefea62cbfa9b909b7 / sbot / channels.js

1014 bytesRaw
1var FlumeReduce = require('flumeview-reduce')
2var normalizeChannel = require('../lib/normalize-channel')
3
4module.exports = function (ssb, config) {
5 return ssb._flumeUse('patchwork-channels', FlumeReduce(1, reduce, map))
6}
7
8function reduce (result, item) {
9 if (!result) result = {}
10 if (item) {
11 for (var channel in item) {
12 var value = result[channel]
13 if (!value) {
14 value = result[channel] = {count: 0, timestamp: 0}
15 }
16 value.count += 1
17
18 if (item[channel].timestamp > value.timestamp) {
19 value.timestamp = item[channel].timestamp
20 }
21 }
22 }
23 return result
24}
25
26function map (msg) {
27 if (msg.value.content) {
28 var isLike = msg.value.content.type === 'vote'
29 var isSubscription = msg.value.content.type === 'channel'
30 var channel = normalizeChannel(msg.value.content.channel)
31
32 // filter out likes and subscriptions
33 if (channel && !isLike && !isSubscription) {
34 return {
35 [channel]: {timestamp: msg.timestamp}
36 }
37 }
38 }
39}
40

Built with git-ssb-web