git ssb

16+

Dominic / patchbay



Tree: 9ae49c99c4e15aee20a0b51e586caccd37d33d1e

Files: 9ae49c99c4e15aee20a0b51e586caccd37d33d1e / modules / names.js

1039 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 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