git ssb

16+

Dominic / patchbay



Commit 3369e03e90e8b441a5c23b79c41b65724a98a39e

load names from mentions or from about messages

Dominic Tarr committed on 8/1/2016, 4:42:59 AM
Parent: c4b58ba4156a3f65f0661588e6d29049c8aff68c

Files changed

modules/names.jschanged
modules/names.jsView
@@ -1,12 +1,15 @@
11 var pull = require('pull-stream')
2 +var many = require('pull-many')
3 +var mfr = require('map-filter-reduce')
24
35 function all(stream, cb) {
46 pull(stream, pull.collect(cb))
57 }
68
79 var plugs = require('../plugs')
810 var sbot_links2 = plugs.first(exports.sbot_links2 = [])
11 +var sbot_query = plugs.first(exports.sbot_query = [])
912
1013 /*
1114 filter(rel: ['mentions', prefix('@')]) | reduce(name: rel[1], value: count())
1215 */
@@ -17,20 +20,44 @@
1720 }
1821 }
1922 var map = {
2023 $map: {
21- id: 'dest', name: ['rel', 1], ts: 'ts',
24 + name: ['rel', 1],
25 + id: 'dest',
26 + ts: 'ts',
2227 }
2328 }
2429
2530 var reduce = {
2631 $reduce: {
27- id: "dest",
28- name: ["rel", 1],
32 + name: 'name',
33 + id: 'id',
2934 rank: {$count: true}
3035 }
3136 }
3237
38 +var filter2 = {
39 + $filter: {
40 + value: {
41 + content: {
42 + type: "about",
43 + name: {"$prefix": ""},
44 + about: {"$prefix": "@"} //better: match regexp.
45 + }
46 + }
47 + }
48 +}
49 +
50 +var map2 = {
51 + $map: {
52 + name: ["value", "content", "name"],
53 + id: ['value', 'content', 'about'],
54 + ts: "timestamp"
55 + }
56 +}
57 +
58 +//union with this query...
59 +
3360 var names = []
3461 function update(name) {
3562 var n = names.find(function (e) {
3663 return e.id == name.id && e.name == e.name
@@ -45,23 +72,47 @@
4572 }
4673
4774 var ready = false, waiting = []
4875
76 +var merge = {
77 + $reduce: {
78 + name: 'name',
79 + id: 'id',
80 + rank: {$sum: 'rank'},
81 + ts: {$max: 'ts'}
82 + }
83 +}
84 +
85 +function add_at(stream) {
86 + return pull(stream, pull.map(function (e) {
87 + if(!/^@/.test(e.name)) e.name = '@'+e.name
88 + return e
89 + })
90 + )
91 +}
92 +
4993 exports.connection_status = function (err) {
5094 if(!err) {
5195 pull(
52- sbot_links2({query: [filter, reduce]}),
96 + many([
97 + sbot_links2({query: [filter, map, reduce]}),
98 + add_at(sbot_query({query: [filter2, map2, reduce]}))
99 + ]),
100 + mfr.reduce(merge),
53101 pull.collect(function (err, ary) {
54- console.log(err, ary)
55102 if(!err) {
56103 names = ary
57104 ready = true
58105 while(waiting.length) waiting.shift()()
59106 }
60107 })
61108 )
62109
63- pull(sbot_links2({query: [filter, map], old: false}), pull.drain(update))
110 + pull(many([
111 + sbot_links2({query: [filter, map], old: false}),
112 + add_at(sbot_query({query: [filter2, map2], old: false}))
113 + ]),
114 + pull.drain(update))
64115 }
65116 }
66117
67118 function async(fn) {
@@ -84,4 +135,8 @@
84135 var rx = new RegExp('^'+name)
85136 return rank(names.filter(function (e) { return rx.test(e.name) }))
86137 })
87138
139 +
140 +
141 +
142 +

Built with git-ssb-web