git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: f5bcb588c61e3a7eeab8ac67114e83109756f277

Files: f5bcb588c61e3a7eeab8ac67114e83109756f277 / 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