git ssb

10+

Matt McKegg / patchwork



Tree: 43326622502c853b045d9b3f486b1631c8a5e93a

Files: 43326622502c853b045d9b3f486b1631c8a5e93a / sbot / subscriptions.js

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

Built with git-ssb-web