modules/search.jsView |
---|
4 | 4 | var Scroller = require('pull-scroll') |
5 | 5 | |
6 | 6 | var plugs = require('../plugs') |
7 | 7 | var message_render = plugs.first(exports.message_render = []) |
8 | | -var sbot_search = plugs.first(exports.sbot_search = []) |
| 8 | +var sbot_log = plugs.first(exports.sbot_log = []) |
9 | 9 | |
| 10 | +function searchFilter(query) { |
| 11 | + var search = new RegExp(query, 'i') |
| 12 | + return function (msg) { |
| 13 | + var c = msg && msg.value && msg.value.content |
| 14 | + return c && ( |
| 15 | + msg.key == query || |
| 16 | + c.text && search.test(c.text) || |
| 17 | + c.name && search.test(c.name) || |
| 18 | + c.title && search.test(c.title)) |
| 19 | + } |
| 20 | +} |
| 21 | + |
10 | 22 | exports.screen_view = function (path) { |
11 | 23 | if(path[0] === '?') { |
12 | 24 | var query = path.substr(1) |
| 25 | + var matchesQuery = searchFilter(query) |
13 | 26 | |
14 | 27 | var content = h('div.column.scroller__content') |
15 | 28 | var div = h('div.column.scroller', |
16 | 29 | {style: {'overflow':'auto'}}, |
19 | 32 | ) |
20 | 33 | ) |
21 | 34 | |
22 | 35 | pull( |
23 | | - sbot_search({query: query, old: false}), |
| 36 | + sbot_log({old: false}), |
| 37 | + pull.filter(matchesQuery), |
24 | 38 | Scroller(div, content, message_render, true, false) |
25 | 39 | ) |
26 | 40 | |
27 | 41 | pull( |
28 | | - u.next(sbot_search, {query: query, |
29 | | - reverse: true, limit: 100, live: false}), |
| 42 | + u.next(sbot_log, {reverse: true, limit: 500, live: false}), |
| 43 | + pull.filter(matchesQuery), |
30 | 44 | Scroller(div, content, message_render, false, false) |
31 | 45 | ) |
32 | 46 | |
33 | 47 | return div |