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