git ssb

16+

Dominic / patchbay



Commit 49322eb6bd415983d6524e48fa5447d21795f6f6

fully remove pull-next-step, remove /search fallback to linear search (ssb-search only)

mixmix committed on 8/1/2018, 11:52:24 PM
Parent: 22980df7086fb15c08c87bb6c2d59fa79296d840

Files changed

app/page/notifications.jschanged
app/page/private.jschanged
app/page/search.jschanged
app/page/notifications.jsView
@@ -1,9 +1,9 @@
11 const nest = require('depnest')
22 const { h } = require('mutant')
33 const pull = require('pull-stream')
44 const Scroller = require('pull-scroll')
5-const next = require('pull-next-step')
5 +const next = require('pull-next-query')
66
77 exports.gives = nest({
88 'app.html.menuItem': true,
99 'app.page.notifications': true
@@ -12,12 +12,13 @@
1212 exports.needs = nest({
1313 'app.html.filter': 'first',
1414 'app.html.scroller': 'first',
1515 'app.sync.goTo': 'first',
16- 'feed.pull.mentions': 'first',
1716 'feed.pull.public': 'first',
1817 'keys.sync.id': 'first',
19- 'message.html.render': 'first'
18 + 'message.html.render': 'first',
19 + 'message.sync.isBlocked': 'first',
20 + 'sbot.pull.stream': 'first'
2021 })
2122
2223 exports.create = function (api) {
2324 return nest({
@@ -32,30 +33,22 @@
3233 }, '/notifications')
3334 }
3435
3536 function notificationsPage (location) {
36- const id = api.keys.sync.id()
37-
3837 const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw)
3938 const { container, content } = api.app.html.scroller({ prepend: [ filterMenu ] })
40- const removeMyMessages = () => pull.filter(msg => msg.value.author !== id)
41- const removePrivateMessages = () => pull.filter(msg => msg.value.private !== true)
4239
4340 function draw () {
4441 resetFeed({ container, content })
4542
4643 pull(
47- next(api.feed.pull.mentions(id), {old: false, limit: 100, property: ['timestamp']}),
48- removeMyMessages(),
49- removePrivateMessages(),
44 + pullMentions({old: false, live: true}),
5045 filterDownThrough(),
5146 Scroller(container, content, api.message.html.render, true, false)
5247 )
5348
5449 pull(
55- next(api.feed.pull.mentions(id), {reverse: true, limit: 100, live: false, property: ['timestamp']}),
56- removeMyMessages(),
57- removePrivateMessages(),
50 + pullMentions({reverse: true, live: false}),
5851 filterUpThrough(),
5952 Scroller(container, content, api.message.html.render, false, false)
6053 )
6154 }
@@ -63,5 +56,33 @@
6356
6457 container.title = '/notifications'
6558 return container
6659 }
60 +
61 + // NOTE - this currently hits mentions AND the patchwork message replies
62 + function pullMentions (opts) {
63 + const query = [{
64 + $filter: {
65 + dest: api.keys.sync.id(),
66 + timestamp: {$gt: 0},
67 + value: {
68 + author: {$ne: api.keys.sync.id()}, // not my messages!
69 + private: {$ne: true} // not private mentions
70 + }
71 + }
72 + }]
73 +
74 + const _opts = Object.assign({
75 + query,
76 + limit: 100,
77 + index: 'DTA'
78 + }, opts)
79 + console.log(_opts)
80 +
81 + return api.sbot.pull.stream(server => {
82 + return pull(
83 + next(server.backlinks.read, _opts, ['timestamp']),
84 + pull.filter(m => !api.message.sync.isBlocked(m))
85 + )
86 + })
87 + }
6788 }
app/page/private.jsView
@@ -2,9 +2,9 @@
22 const { h } = require('mutant')
33 const pull = require('pull-stream')
44 const Scroller = require('pull-scroll')
55 const ref = require('ssb-ref')
6-const next = require('pull-next-step')
6 +const next = require('pull-next-query')
77
88 exports.gives = nest({
99 'app.html.menuItem': true,
1010 'app.page.private': true
@@ -56,15 +56,15 @@
5656 function draw () {
5757 resetFeed({ container, content })
5858
5959 pull(
60- next(api.feed.pull.private, {old: false, limit: 100}, ['value', 'timestamp']),
60 + pullPrivate({old: false, live: true}),
6161 filterDownThrough(),
6262 Scroller(container, content, api.message.html.render, true, false)
6363 )
6464
6565 pull(
66- next(api.feed.pull.private, {reverse: true, limit: 100, live: false}, ['value', 'timestamp']),
66 + pullPrivate({reverse: true}),
6767 filterUpThrough(),
6868 Scroller(container, content, api.message.html.render, false, false)
6969 )
7070 }
@@ -72,5 +72,23 @@
7272
7373 container.title = '/private'
7474 return container
7575 }
76 +
77 + function pullPrivate (opts) {
78 + const query = [{
79 + $filter: {
80 + timestamp: {$gt: 0},
81 + value: {
82 + content: {
83 + recps: {$truthy: true}
84 + }
85 + }
86 + }
87 + }]
88 +
89 + const _opts = Object.assign({ query, limit: 100 }, opts)
90 +
91 + return next(api.feed.pull.private, _opts, ['timestamp'])
92 + }
7693 }
94 +
app/page/search.jsView
@@ -1,8 +1,8 @@
11 const nest = require('depnest')
2-const { h, Struct, Value, when, computed } = require('mutant')
2 +const { h, Struct, Value } = require('mutant')
33 const pull = require('pull-stream')
4-const next = require('pull-next-step')
4 +const next = require('pull-next-query')
55 const Scroller = require('pull-scroll')
66 const TextNodeSearcher = require('text-node-searcher')
77
88 exports.gives = nest('app.page.search')
@@ -16,130 +16,42 @@
1616 })
1717
1818 var whitespace = /\s+/
1919
20-function andSearch (terms, inputs) {
21- for (var i = 0; i < terms.length; i++) {
22- var match = false
23- for (var j = 0; j < inputs.length; j++) {
24- if (terms[i].test(inputs[j])) match = true
25- }
26- // if a term was not matched by anything, filter this one
27- if (!match) return false
28- }
29- return true
30-}
31-
32-function searchFilter (terms) {
33- return function (msg) {
34- var c = msg && msg.value && msg.value.content
35- return c && (
36- msg.key === terms[0] ||
37- andSearch(terms.map(function (term) {
38- return new RegExp('\\b' + term + '\\b', 'i')
39- }), [c.text, c.name, c.title])
40- )
41- }
42-}
43-
44-function createOrRegExp (ary) {
45- return new RegExp(ary.map(function (e) {
46- return '\\b' + e + '\\b'
47- }).join('|'), 'i')
48-}
49-
50-function highlight (el, query) {
51- var searcher = new TextNodeSearcher({container: el})
52- searcher.query = query
53- searcher.highlight()
54- return el
55-}
56-
57-function fallback (createReader) {
58- var fallbackRead
59- return function (read) {
60- return function (abort, cb) {
61- read(abort, function next (end, data) {
62- if (end && createReader && (fallbackRead = createReader(end))) {
63- createReader = null
64- read = fallbackRead
65- read(abort, next)
66- } else {
67- cb(end, data)
68- }
69- })
70- }
71- }
72-}
73-
7420 exports.create = function (api) {
7521 return nest('app.page.search', searchPage)
7622
7723 function searchPage (location) {
7824 const query = location.query.trim()
7925
80- var queryTerms = query.split(whitespace)
81- var matchesQuery = searchFilter(queryTerms)
82-
8326 const search = Struct({
84- isLinear: Value(false),
85- linear: Struct({
86- checked: Value(0)
87- }),
8827 fulltext: Struct({
8928 isDone: Value(false)
9029 }),
9130 matches: Value(0)
9231 })
93- const hasNoFulltextMatches = computed([search.fulltext.isDone, search.matches],
94- (done, matches) => done && matches === 0)
9532
9633 const searchHeader = h('Search', [
97- h('header', h('h1', query)),
98- when(search.isLinear,
99- h('section.details', [
100- h('div.searched', ['Searched: ', search.linear.checked]),
101- h('div.matches', [search.matches, ' matches'])
102- ]),
103- h('section.details', [
104- h('div.searched'),
105- when(hasNoFulltextMatches, h('div.matches', 'No matches'))
106- ])
107- )
34 + h('header', h('h1', query))
10835 ])
109- const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw)
36 + const { filterMenu, filterDownThrough, resetFeed } = api.app.html.filter(draw)
11037 const { container, content } = api.app.html.scroller({ prepend: [searchHeader, filterMenu] })
11138
11239 function renderMsg (msg) {
11340 var el = api.message.html.render(msg)
41 + var queryTerms = query.split(whitespace)
42 +
11443 highlight(el, createOrRegExp(queryTerms))
11544 return el
11645 }
11746
11847 function draw () {
11948 resetFeed({ container, content })
12049
50 + // TODO figure out how to step on kinda orderless search results
12151 pull(
122- api.sbot.pull.log({old: false}),
123- pull.filter(matchesQuery),
124- filterUpThrough(),
125- Scroller(container, content, renderMsg, true, false)
126- )
127-
128- pull(
129- api.sbot.pull.stream(sbot => next(sbot.search.query, { query, limit: 500 })),
130- fallback((err) => {
131- if (err === true) {
132- search.fulltext.isDone.set(true)
133- } else if (/^no source/.test(err.message)) {
134- search.isLinear.set(true)
135- return pull(
136- next(api.sbot.pull.log, {reverse: true, limit: 500, live: false}),
137- pull.through(() => search.linear.checked.set(search.linear.checked() + 1)),
138- pull.filter(matchesQuery)
139- )
140- }
141- }),
52 + // api.sbot.pull.stream(sbot => next(sbot.search.query, { query, limit: 500 })),
53 + api.sbot.pull.stream(sbot => sbot.search.query({ query, limit: 500 })),
14254 filterDownThrough(),
14355 pull.through(() => search.matches.set(search.matches() + 1)),
14456 Scroller(container, content, renderMsg, false, false)
14557 )
@@ -150,4 +62,18 @@
15062 container.title = '?' + query
15163 return container
15264 }
15365 }
66 +
67 +function createOrRegExp (ary) {
68 + return new RegExp(ary.map(function (e) {
69 + return '\\b' + e + '\\b'
70 + }).join('|'), 'i')
71 +}
72 +
73 +function highlight (el, query) {
74 + var searcher = new TextNodeSearcher({container: el})
75 + searcher.query = query
76 + searcher.highlight()
77 + return el
78 +}
79 +

Built with git-ssb-web