git ssb

0+

mixmix / ssb-testing-guide



Tree: 87f62996e714588859e2a26acb9a43e07d2db238

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

971 bytesRaw
1const flumeView = require('flumeview-reduce')
2
3const NAME = 'channel'
4const VERSION = 2
5
6module.exports = {
7 name: NAME,
8 version: VERSION,
9 manifest: {
10 all: 'async'
11 },
12 init: function (server, config) {
13 const view = server._flumeUse(
14 NAME,
15 flumeView(VERSION, reduce, map, null, initialState())
16 )
17
18 return {
19 all: view.get
20 }
21 }
22}
23
24function map (msg) {
25 var content = msg.value.content
26 var channelAttribute = content.channel
27
28 var mentions = content.mentions || []
29 var mentionedChannel = mentions
30 .filter(mention => Boolean(mention.link))
31 .filter(mention => mention.link.match(/^#/))
32 .map(mention => mention.link.replace('#',''))
33 .shift()
34
35 return channelAttribute || mentionedChannel
36}
37
38// if map returns null or undefined, reduce is skipped
39function reduce (accumulator, channel) {
40 accumulator[channel] = (accumulator[channel] || 0) + 1
41 return accumulator
42}
43
44function initialState () {
45 return {}
46}
47

Built with git-ssb-web