Commit e477b2791e472cca943676e0d61dc6f3255f50e8
initial
mix irving committed on 1/12/2018, 8:58:42 PMFiles changed
.gitignore | added |
index.js | added |
package-lock.json | added |
package.json | added |
index.js | ||
---|---|---|
@@ -1,0 +1,76 @@ | ||
1 … | +const flumeView = require('flumeview-reduce') | |
2 … | +const pull = require('pull-stream') | |
3 … | +const get = require('lodash/get') | |
4 … | +const mergeWith = require('lodash/mergeWith') | |
5 … | + | |
6 … | +module.exports = { | |
7 … | + name: 'actualFriends', | |
8 … | + version: '1.0.0', | |
9 … | + manifest: { | |
10 … | + get: 'async', | |
11 … | + stream: 'source' | |
12 … | + }, | |
13 … | + init: function (ssbServer, config) { | |
14 … | + console.log('*** loading actual-friends ***') | |
15 … | + | |
16 … | + const view = ssbServer._flumeUse('actualFriends', flumeView( | |
17 … | + 1.0, // version | |
18 … | + reduceData, | |
19 … | + mapToData, | |
20 … | + null, //codec | |
21 … | + initialState() | |
22 … | + )) | |
23 … | + console.log('init FlumeView', view) | |
24 … | + | |
25 … | + return { | |
26 … | + get: view.get, | |
27 … | + stream: view.stream | |
28 … | + } | |
29 … | + } | |
30 … | +} | |
31 … | + | |
32 … | +function reduceData (acc, newData) { | |
33 … | + // https://lodash.com/docs/4.17.4#mergeWith | |
34 … | + process.stdout.write('<3') | |
35 … | + return mergeWith(acc, newData, (accVal, newVal) => { | |
36 … | + if (typeof accVal === 'number') { | |
37 … | + return accVal + newVal | |
38 … | + } | |
39 … | + }) | |
40 … | +} | |
41 … | + | |
42 … | +function mapToData (msg) { | |
43 … | + // TODO - handle private message | |
44 … | + // TODO - check mentions are valid user keys | |
45 … | + | |
46 … | + const { author, content } = msg.value | |
47 … | + var mentions = get(content, 'mentions', []) //map | |
48 … | + if (!Array.isArray(mentions)) { | |
49 … | + console.log('actualFriends - weird mentions:', mentions) | |
50 … | + // e.g { '0': { link: '@hxGxqPrplLjRG2vtjQL87abX4QKqeLgCwQpS730nNwE=.ed25519', name: 'paul' } } | |
51 … | + return {} | |
52 … | + } | |
53 … | + // catches old mentions types : | |
54 … | + | |
55 … | + mentions = mentions | |
56 … | + .map(mention => typeof mention === 'object' | |
57 … | + ? mention.link | |
58 … | + : mention | |
59 … | + ) | |
60 … | + .filter(Boolean) | |
61 … | + .reduce( | |
62 … | + (acc, user) => Object.assign(acc, { [user]: 1 }), | |
63 … | + {} | |
64 … | + ) | |
65 … | + | |
66 … | + return { | |
67 … | + [author]: { | |
68 … | + mentions | |
69 … | + } | |
70 … | + } | |
71 … | +} | |
72 … | + | |
73 … | +function initialState () { | |
74 … | + return {} | |
75 … | +} | |
76 … | + |
package-lock.json | ||
---|---|---|
@@ -1,0 +1,78 @@ | ||
1 … | +{ | |
2 … | + "name": "ssb-server-actual-friends", | |
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,25 @@ | ||
1 … | +{ | |
2 … | + "name": "ssb-server-actual-friends", | |
3 … | + "version": "1.0.0", | |
4 … | + "description": "", | |
5 … | + "main": "index.js", | |
6 … | + "scripts": { | |
7 … | + "test": "echo \"Error: no test specified\" && exit 1" | |
8 … | + }, | |
9 … | + "repository": { | |
10 … | + "type": "git", | |
11 … | + "url": "git+https://github.com/mixmix/ssb-server-actual-friends.git" | |
12 … | + }, | |
13 … | + "keywords": ["scuttlebutt", "p2p"], | |
14 … | + "author": "", | |
15 … | + "license": "ISC", | |
16 … | + "bugs": { | |
17 … | + "url": "https://github.com/mixmix/ssb-server-actual-friends/issues" | |
18 … | + }, | |
19 … | + "homepage": "https://github.com/mixmix/ssb-server-actual-friends#readme", | |
20 … | + "dependencies": { | |
21 … | + "flumeview-reduce": "^1.3.12", | |
22 … | + "lodash": "^4.17.4", | |
23 … | + "pull-stream": "^3.6.1" | |
24 … | + } | |
25 … | +} |
Built with git-ssb-web