Files: 7b8459c024b593664fa22d32c9b9bcccfe02a2fa / modules / names.js
1039 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_name = |
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 | n.textContent = names.reduce(function (max, item) { |
31 | return max.count > item.count ? max : item |
32 | }, {name: id.substring(0, 10), count: 0}).name |
33 | }) |
34 | |
35 | return n |
36 | |
37 | } |
38 | |
39 | |
40 |
Built with git-ssb-web