Commit ceb725feeb3aac110f9c519878705290803c3ce7
initial
mix irving committed on 1/31/2018, 12:30:19 AMFiles changed
.gitignore | added |
index.js | added |
package-lock.json | added |
package.json | added |
index.js | ||
---|---|---|
@@ -1,0 +1,95 @@ | ||
1 … | +const FlumeView = require('flumeview-reduce') | |
2 … | +const get = require('lodash/get') | |
3 … | +const set = require('lodash/set') | |
4 … | + | |
5 … | +const FLUME_VIEW_VERSION = 1.3 | |
6 … | + | |
7 … | +module.exports = { | |
8 … | + name: 'channels', | |
9 … | + version: require('./package.json').version, | |
10 … | + manifest: { | |
11 … | + get: 'async', | |
12 … | + stream: 'source', | |
13 … | + }, | |
14 … | + init: (server, config) => { | |
15 … | + console.log('///// CHANNELS plugin loaded /////') | |
16 … | + | |
17 … | + const view = server._flumeUse( | |
18 … | + 'channels', | |
19 … | + FlumeView(FLUME_VIEW_VERSION, reduce, map, null, initialState()) | |
20 … | + ) | |
21 … | + | |
22 … | + return { | |
23 … | + get: view.get, | |
24 … | + stream: view.stream, | |
25 … | + } | |
26 … | + } | |
27 … | +} | |
28 … | + | |
29 … | +function initialState () { | |
30 … | + return {} | |
31 … | +} | |
32 … | + | |
33 … | + | |
34 … | +function map (msg) { | |
35 … | + if (get(msg, 'value.content.type') !== 'channel') return null | |
36 … | + | |
37 … | + const author = msg.value.author | |
38 … | + const channel = get(msg, 'value.content.channel') | |
39 … | + const subscribed = get(msg, 'value.content.subscribed') | |
40 … | + | |
41 … | + if (typeof channel === undefined || typeof subscribed === undefined) { | |
42 … | + console.log('Malformed channel subscription', msg) | |
43 … | + return null | |
44 … | + } | |
45 … | + | |
46 … | + return { | |
47 … | + channel, | |
48 … | + author, | |
49 … | + subscribed | |
50 … | + } | |
51 … | +} | |
52 … | + | |
53 … | +function reduce (soFar, newSub) { | |
54 … | + process.stdout.write('c') | |
55 … | + const { channel, author, subscribed } = newSub | |
56 … | + | |
57 … | + const channelSubs = get(soFar, [channel], new Set()) | |
58 … | + if (subscribed) channelSubs.add(author) | |
59 … | + else channelSubs.delete(author) | |
60 … | + | |
61 … | + soFar[channel] = channelSubs | |
62 … | + | |
63 … | + return soFar | |
64 … | +} | |
65 … | + | |
66 … | +// state: | |
67 … | +// { | |
68 … | +// [Channel]: [ Set | |
69 … | +// FeedId | |
70 … | +// ] | |
71 … | +// } | |
72 … | + | |
73 … | + | |
74 … | +// { | |
75 … | +// 'ssb-learning': [ | |
76 … | +// '@ye14....', | |
77 … | +// '@weandre..', | |
78 … | +// ], | |
79 … | +// 'brazil': [ | |
80 … | +// '@weandre..', | |
81 … | +// ] | |
82 … | +// } | |
83 … | + | |
84 … | +// channel message: | |
85 … | +// value: { | |
86 … | +// author: FeedId, | |
87 … | +// content: { | |
88 … | +// { | |
89 … | +// type: 'channel', | |
90 … | +// channel: String, // ssb-learning | |
91 … | +// subscribed: Boolean | |
92 … | +// } | |
93 … | +// } | |
94 … | +// } | |
95 … | + |
package-lock.json | ||
---|---|---|
@@ -1,0 +1,78 @@ | ||
1 … | +{ | |
2 … | + "name": "ssb-server-channels", | |
3 … | + "version": "1.0.0", | |
4 … | + "lockfileVersion": 1, | |
5 … | + "requires": true, | |
6 … | + "dependencies": { | |
7 … | + "async-single": { | |
8 … | + "version": "1.0.5", | |
9 … | + "resolved": "https://registry.npmjs.org/async-single/-/async-single-1.0.5.tgz", | |
10 … | + "integrity": "sha1-El3QneldPqMKN4rb7QIQkhebA8k=" | |
11 … | + }, | |
12 … | + "atomic-file": { | |
13 … | + "version": "1.1.4", | |
14 … | + "resolved": "https://registry.npmjs.org/atomic-file/-/atomic-file-1.1.4.tgz", | |
15 … | + "integrity": "sha1-ZhUuOfzosrDH5fJi4KGl06s6q1E=" | |
16 … | + }, | |
17 … | + "deep-equal": { | |
18 … | + "version": "1.0.1", | |
19 … | + "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz", | |
20 … | + "integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU=" | |
21 … | + }, | |
22 … | + "flumecodec": { | |
23 … | + "version": "0.0.0", | |
24 … | + "resolved": "https://registry.npmjs.org/flumecodec/-/flumecodec-0.0.0.tgz", | |
25 … | + "integrity": "sha1-Ns4Gq+Lg4BxE3WnyoWUwWiMgZJs=", | |
26 … | + "requires": { | |
27 … | + "level-codec": "6.2.0" | |
28 … | + } | |
29 … | + }, | |
30 … | + "flumeview-reduce": { | |
31 … | + "version": "1.3.12", | |
32 … | + "resolved": "https://registry.npmjs.org/flumeview-reduce/-/flumeview-reduce-1.3.12.tgz", | |
33 … | + "integrity": "sha1-3eiAMca85rox1DgpGWN4iLzAyqE=", | |
34 … | + "requires": { | |
35 … | + "async-single": "1.0.5", | |
36 … | + "atomic-file": "1.1.4", | |
37 … | + "deep-equal": "1.0.1", | |
38 … | + "flumecodec": "0.0.0", | |
39 … | + "obv": "0.0.0", | |
40 … | + "pull-notify": "0.1.1", | |
41 … | + "pull-stream": "3.6.1" | |
42 … | + } | |
43 … | + }, | |
44 … | + "level-codec": { | |
45 … | + "version": "6.2.0", | |
46 … | + "resolved": "https://registry.npmjs.org/level-codec/-/level-codec-6.2.0.tgz", | |
47 … | + "integrity": "sha1-pLUkS7akwvcj1oodZOmAxTYn2dQ=" | |
48 … | + }, | |
49 … | + "lodash": { | |
50 … | + "version": "4.17.4", | |
51 … | + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", | |
52 … | + "integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=" | |
53 … | + }, | |
54 … | + "obv": { | |
55 … | + "version": "0.0.0", | |
56 … | + "resolved": "https://registry.npmjs.org/obv/-/obv-0.0.0.tgz", | |
57 … | + "integrity": "sha1-7eq4Ro+R1BkzYu1/kdC5bdOaecE=" | |
58 … | + }, | |
59 … | + "pull-notify": { | |
60 … | + "version": "0.1.1", | |
61 … | + "resolved": "https://registry.npmjs.org/pull-notify/-/pull-notify-0.1.1.tgz", | |
62 … | + "integrity": "sha1-b4b/ldJwuJw+vyVbYDG3Ay3JnMo=", | |
63 … | + "requires": { | |
64 … | + "pull-pushable": "2.1.2" | |
65 … | + } | |
66 … | + }, | |
67 … | + "pull-pushable": { | |
68 … | + "version": "2.1.2", | |
69 … | + "resolved": "https://registry.npmjs.org/pull-pushable/-/pull-pushable-2.1.2.tgz", | |
70 … | + "integrity": "sha1-P+Fbj37sifOXLSOLwEiQyUBabbs=" | |
71 … | + }, | |
72 … | + "pull-stream": { | |
73 … | + "version": "3.6.1", | |
74 … | + "resolved": "https://registry.npmjs.org/pull-stream/-/pull-stream-3.6.1.tgz", | |
75 … | + "integrity": "sha1-xcKuSlEkbv7rzGXAQSo9clqSzgA=" | |
76 … | + } | |
77 … | + } | |
78 … | +} |
package.json | ||
---|---|---|
@@ -1,0 +1,16 @@ | ||
1 … | +{ | |
2 … | + "name": "ssb-server-channels", | |
3 … | + "version": "1.0.0", | |
4 … | + "description": "", | |
5 … | + "main": "index.js", | |
6 … | + "scripts": { | |
7 … | + "test": "echo \"Error: no test specified\" && exit 1" | |
8 … | + }, | |
9 … | + "keywords": [], | |
10 … | + "author": "", | |
11 … | + "license": "ISC", | |
12 … | + "dependencies": { | |
13 … | + "flumeview-reduce": "^1.3.12", | |
14 … | + "lodash": "^4.17.4" | |
15 … | + } | |
16 … | +} |
Built with git-ssb-web