git ssb

10+

Matt McKegg / patchwork



Tree: 0ae3757980ed868524769abdc7b07da937191e78

Files: 0ae3757980ed868524769abdc7b07da937191e78 / sbot / channels.js

852 bytesRaw
1var FlumeReduce = require('flumeview-reduce')
2
3module.exports = function (ssb, config) {
4 return ssb._flumeUse('patchwork-channels', FlumeReduce(1, reduce, map))
5}
6
7function reduce (result, item) {
8 if (!result) result = {}
9 if (item) {
10 for (var channel in item) {
11 var value = result[channel]
12 if (!value) {
13 value = result[channel] = {count: 0, timestamp: 0}
14 }
15 value.count += 1
16 if (item[channel].timestamp > value.timestamp) {
17 value.timestamp = item[channel].timestamp
18 }
19 }
20 }
21 return result
22}
23
24function map (msg) {
25 if (msg.value.content && typeof msg.value.content.channel === 'string') {
26 var channel = msg.value.content.channel
27 if (channel.length > 0 && channel.length < 30) {
28 return {
29 [channel.replace(/\s/g, '')]: {timestamp: msg.timestamp}
30 }
31 }
32 }
33}
34

Built with git-ssb-web