git ssb

10+

Matt McKegg / patchwork



Tree: 20cee95636c3adc788f738eff9c79fb6477c66d4

Files: 20cee95636c3adc788f738eff9c79fb6477c66d4 / sbot / subscriptions.js

855 bytesRaw
1var FlumeReduce = require('flumeview-reduce')
2var normalizeChannel = require('../lib/normalize-channel')
3
4module.exports = function (ssb, config) {
5 return ssb._flumeUse('patchwork-subscriptions', FlumeReduce(3, reduce, map))
6}
7
8function reduce (result, item) {
9 if (!result) result = {}
10 if (item) {
11 for (var key in item) {
12 if (!result[key] || result[key][0] < item[key][0]) {
13 result[key] = item[key]
14 }
15 }
16 }
17 return result
18}
19
20function map (msg) {
21 if (msg.value.content && msg.value.content.type === 'channel') {
22 if (typeof msg.value.content.subscribed === 'boolean') {
23 var channel = normalizeChannel(msg.value.content.channel)
24 if (channel) {
25 var key = `${msg.value.author}:${channel}`
26 return {
27 [key]: [msg.timestamp, msg.value.content.subscribed]
28 }
29 }
30 }
31 }
32}
33

Built with git-ssb-web