Files: 1ed42bd9f36becb191c331ca40892cc3262c8e08 / modules / names.js
1058 bytesRaw
1 | var h = require('hyperscript') |
2 | var pull = require('pull-stream') |
3 | |
4 | function all(stream, cb) { |
5 | pull(stream, pull.collect(cb)) |
6 | } |
7 | |
8 | exports.avatar = |
9 | function name (id, sbot) { |
10 | var n = h('span', id.substring(0, 10)) |
11 | //choose the most popular name for this person. |
12 | //for anything like this you'll see I have used sbot.links2 |
13 | //which is the ssb-links plugin. as you'll see the query interface |
14 | //is pretty powerful! |
15 | //TODO: "most popular" name is easily gameable. |
16 | //must come up with something better than this. |
17 | /* |
18 | filter(rel: ['mentions', prefix('@')]) |
19 | .reduce(name: rel[1], value: count()) |
20 | */ |
21 | |
22 | all( |
23 | sbot.links2.read({query: [ |
24 | {$filter: {rel: ['mentions', {$prefix: '@'}], dest: id}}, |
25 | {$reduce: { name: ['rel', 1], count: {$count: true} |
26 | }} |
27 | ]}), |
28 | function (err, names) { |
29 | if(err) throw err |
30 | console.log(names) |
31 | n.textContent = names.reduce(function (max, item) { |
32 | return max.count > item.count ? max : item |
33 | }, {name: id.substring(0, 10), count: 0}).name |
34 | }) |
35 | |
36 | return n |
37 | |
38 | } |
39 | |
40 |
Built with git-ssb-web