Files: 29997160555aa9df4541f65ba3ca7b58d4a8c9c4 / modules / search.js
1253 bytesRaw
1 | var h = require('hyperscript') |
2 | var u = require('../util') |
3 | var pull = require('pull-stream') |
4 | var Scroller = require('pull-scroll') |
5 | |
6 | var plugs = require('../plugs') |
7 | var message_render = plugs.first(exports.message_render = []) |
8 | var sbot_log = plugs.first(exports.sbot_log = []) |
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 | |
22 | exports.screen_view = function (path) { |
23 | if(path[0] === '?') { |
24 | var query = path.substr(1) |
25 | var matchesQuery = searchFilter(query) |
26 | |
27 | var content = h('div.column.scroller__content') |
28 | var div = h('div.column.scroller', |
29 | {style: {'overflow':'auto'}}, |
30 | h('div.scroller__wrapper', |
31 | content |
32 | ) |
33 | ) |
34 | |
35 | pull( |
36 | sbot_log({old: false}), |
37 | pull.filter(matchesQuery), |
38 | Scroller(div, content, message_render, true, false) |
39 | ) |
40 | |
41 | pull( |
42 | u.next(sbot_log, {reverse: true, limit: 500, live: false}), |
43 | pull.filter(matchesQuery), |
44 | Scroller(div, content, message_render, false, false) |
45 | ) |
46 | |
47 | return div |
48 | } |
49 | } |
50 |
Built with git-ssb-web