git ssb

16+

Dominic / patchbay



Tree: 2dfb00d8c797f2654d1f473cb0bee782ecf9c81d

Files: 2dfb00d8c797f2654d1f473cb0bee782ecf9c81d / modules / names.js

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

Built with git-ssb-web