modules/search-box.jsView |
---|
2 | 2 | var suggest = require('suggest-box') |
3 | 3 | var pull = require('pull-stream') |
4 | 4 | var plugs = require('../plugs') |
5 | 5 | var sbot_query = plugs.first(exports.sbot_query = []) |
| 6 | +var sbot_links2 = plugs.first(exports.sbot_links2 = []) |
6 | 7 | |
7 | 8 | exports.search_box = function (go) { |
8 | 9 | |
9 | 10 | var suggestBox |
37 | 38 | search.value = sigil |
38 | 39 | } |
39 | 40 | } |
40 | 41 | |
| 42 | + var suggestions = {} |
| 43 | + |
| 44 | + |
| 45 | + setTimeout(function () { |
| 46 | + suggestBox = suggest(search, suggestions) |
| 47 | + }, 10) |
| 48 | + |
41 | 49 | pull( |
42 | 50 | sbot_query({query: [ |
43 | 51 | {$filter: {value: {content: {channel: {$gt: ''}}}}}, |
44 | 52 | {$reduce: { |
47 | 55 | }} |
48 | 56 | ]}), |
49 | 57 | pull.collect(function (err, chans) { |
50 | 58 | if (err) return console.error(err) |
51 | | - var suggestions = chans.map(function (chan) { |
| 59 | + suggestions['#'] = chans.map(function (chan) { |
52 | 60 | var name = '#' + chan.channel |
53 | | - if (name) return { |
| 61 | + return { |
54 | 62 | title: name, |
55 | 63 | value: name, |
56 | 64 | subtitle: chan.posts |
57 | 65 | } |
58 | | - }).filter(Boolean) |
59 | | - suggestBox = suggest(search, {'#': suggestions}) |
| 66 | + }) |
60 | 67 | }) |
61 | 68 | ) |
62 | 69 | |
| 70 | + pull( |
| 71 | + sbot_links2({query: [ |
| 72 | + {$filter: { |
| 73 | + dest: {$prefix: '@'}, |
| 74 | + rel: ['mentions', {$gt: '@'}]} |
| 75 | + }, |
| 76 | + {$reduce: { |
| 77 | + id: 'dest', |
| 78 | + name: ['rel', 1], |
| 79 | + rank: {$count: true}} |
| 80 | + } |
| 81 | + ]}), |
| 82 | + pull.collect(function (err, links) { |
| 83 | + if (err) return console.error(err) |
| 84 | + suggestions['@'] = links.map(function (e) { |
| 85 | + return { |
| 86 | + title: e.name, |
| 87 | + value: e.id, |
| 88 | + subtitle: e.id + ' (' + e.rank + ')' |
| 89 | + } |
| 90 | + }) |
| 91 | + }) |
| 92 | + ) |
| 93 | + |
63 | 94 | return search |
64 | 95 | } |