git ssb

16+

Dominic / patchbay



Commit ae12a05c8bad934d6e90d7b524a9a16e76ed5b98

Filter search results after u.next

Charles Lehner committed on 6/28/2016, 2:03:36 AM
Parent: 2368dc2750e7187e31f959a729f0c3d539a8e2bf

Files changed

modules/search.jschanged
sbot-api.jschanged
modules/search.jsView
@@ -4,13 +4,26 @@
44 var Scroller = require('pull-scroll')
55
66 var plugs = require('../plugs')
77 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 = [])
99
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+
1022 exports.screen_view = function (path) {
1123 if(path[0] === '?') {
1224 var query = path.substr(1)
25+ var matchesQuery = searchFilter(query)
1326
1427 var content = h('div.column.scroller__content')
1528 var div = h('div.column.scroller',
1629 {style: {'overflow':'auto'}},
@@ -19,15 +32,16 @@
1932 )
2033 )
2134
2235 pull(
23- sbot_search({query: query, old: false}),
36+ sbot_log({old: false}),
37+ pull.filter(matchesQuery),
2438 Scroller(div, content, message_render, true, false)
2539 )
2640
2741 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),
3044 Scroller(div, content, message_render, false, false)
3145 )
3246
3347 return div
sbot-api.jsView
@@ -51,25 +51,8 @@
5151 }),
5252 sbot_user_feed: rec.source(function (opts) {
5353 return sbot.createUserStream(opts)
5454 }),
55- sbot_search: rec.source(function (opts) {
56- var search = new RegExp(opts.query, 'i')
57- var limit = opts.limit || Infinity
58- delete opts.limit
59- return pull(
60- sbot.createLogStream(opts),
61- pull.filter(function (msg) {
62- var c = msg && msg.value && msg.value.content
63- return c && (
64- msg.key == opts.query ||
65- c.text && search.test(c.text) ||
66- c.name && search.test(c.name) ||
67- c.title && search.test(c.title))
68- }),
69- pull.take(limit)
70- )
71- }),
7255 sbot_get: rec.async(function (key, cb) {
7356 sbot.get(key, cb)
7457 }),
7558 sbot_publish: rec.async(function (msg, cb) {

Built with git-ssb-web