Files: 4d7952cbd8b31e3ca6b52a6ac0b71e0be90d8231 / modules / search.js
1515 bytesRaw
1 | var h = require('hyperscript') |
2 | var u = require('../util') |
3 | var pull = require('pull-stream') |
4 | var Scroller = require('pull-scroll') |
5 | var TextNodeSearcher = require('text-node-searcher') |
6 | |
7 | var plugs = require('../plugs') |
8 | var message_render = plugs.first(exports.message_render = []) |
9 | var sbot_log = plugs.first(exports.sbot_log = []) |
10 | |
11 | function searchFilter(query) { |
12 | var search = new RegExp('\\b('+query+')\\b', 'i') |
13 | return function (msg) { |
14 | var c = msg && msg.value && msg.value.content |
15 | return c && ( |
16 | msg.key == query || |
17 | c.text && search.test(c.text) || |
18 | c.name && search.test(c.name) || |
19 | c.title && search.test(c.title)) |
20 | } |
21 | } |
22 | |
23 | exports.screen_view = function (path) { |
24 | if(path[0] === '?') { |
25 | var query = path.substr(1) |
26 | var matchesQuery = searchFilter(query) |
27 | |
28 | var content = h('div.column.scroller__content') |
29 | var div = h('div.column.scroller', |
30 | {style: {'overflow':'auto'}}, |
31 | h('div.scroller__wrapper', |
32 | content |
33 | ) |
34 | ) |
35 | |
36 | function renderMsg(msg) { |
37 | var el = message_render(msg) |
38 | var searcher = new TextNodeSearcher({container: el}) |
39 | searcher.setQuery(query) |
40 | searcher.highlight() |
41 | return el |
42 | } |
43 | |
44 | pull( |
45 | sbot_log({old: false}), |
46 | pull.filter(matchesQuery), |
47 | Scroller(div, content, renderMsg, true, false) |
48 | ) |
49 | |
50 | pull( |
51 | u.next(sbot_log, {reverse: true, limit: 500, live: false}), |
52 | pull.filter(matchesQuery), |
53 | Scroller(div, content, renderMsg, false, false) |
54 | ) |
55 | |
56 | return div |
57 | } |
58 | } |
59 |
Built with git-ssb-web