git ssb

16+

Dominic / patchbay



Tree: d6467d3650ae378a0c0509253c2ab80b74c89e7b

Files: d6467d3650ae378a0c0509253c2ab80b74c89e7b / modules / names.js

1063 bytesRaw
1var h = require('hyperscript')
2var pull = require('pull-stream')
3
4function all(stream, cb) {
5 pull(stream, pull.collect(cb))
6}
7
8exports.avatar_name =
9function 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