Files: 320daa2f36cbae74fd16574f5df28d8459c4ef10 / sbot / channels.js
852 bytesRaw
1 | var FlumeReduce = require('flumeview-reduce') |
2 | |
3 | module.exports = function (ssb, config) { |
4 | return ssb._flumeUse('patchwork-channels', FlumeReduce(1, reduce, map)) |
5 | } |
6 | |
7 | function 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 | |
24 | function 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