git ssb

0+

mixmix / ssb-testing-guide



Tree: 87f62996e714588859e2a26acb9a43e07d2db238

Files: 87f62996e714588859e2a26acb9a43e07d2db238 / intermediate / flumeview-reduce / channelV3.js

1403 bytesRaw
1const flumeView = require('flumeview-reduce')
2
3const NAME = 'channel'
4const VERSION = 3
5
6module.exports = {
7 name: NAME,
8 version: VERSION,
9 manifest: {
10 all: 'async',
11 count: 'async'
12 },
13 init: function (server, config) {
14 // Our original view
15 const view = server._flumeUse(
16 NAME,
17 flumeView(
18 VERSION,
19 (soFar, channels) => {
20 // reduce
21 channels.forEach(channel => {
22 soFar[channel] = (soFar[channel] || 0) + 1
23 })
24 return soFar
25 },
26 (msg) => {
27 // map
28 var { content } = msg.value
29 var mentions = [
30 ...content.mentions || [],
31 { link: content.channel }
32 ]
33 // Put content.channel in list, even if null / undefined
34 channels = mentions
35 // map to string
36 .map(men => men.link)
37 // remove falsey
38 .filter(Boolean)
39 // remove #
40 .map(parseChannel)
41
42 // remove duplicates and return array
43 return Array.from(new Set(channels))
44
45 function parseChannel (channel) {
46 return channel.replace('#', '')
47 }
48 },
49 null,
50 {}
51 )
52 )
53
54 return {
55 all: view.get,
56 count: (name, cb) => {
57 view.get((err, data) => {
58 cb(null, data[name])
59 })
60 }
61 }
62 }
63}
64

Built with git-ssb-web