diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-04-27 11:18:19 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-04-27 19:38:47 -1000 |
commit | 93db24ff8b6685f236e3f13031fb23602a4ada46 (patch) | |
tree | 70393b7ed21033d86ff4f9edb471e798f61a7d5c /lib | |
parent | 0373df4b547ca9bc2d07dab0c4d7720ee4cce69e (diff) | |
download | patchfoo-93db24ff8b6685f236e3f13031fb23602a4ada46.tar.gz patchfoo-93db24ff8b6685f236e3f13031fb23602a4ada46.zip |
Add advanced search
Diffstat (limited to 'lib')
-rw-r--r-- | lib/app.js | 43 | ||||
-rw-r--r-- | lib/serve.js | 56 |
2 files changed, 98 insertions, 1 deletions
@@ -99,6 +99,49 @@ App.prototype.search = function (opts) { return search(opts) } +App.prototype.advancedSearch = function (opts) { + return pull( + opts.dest ? + this.sbot.links({ + values: true, + dest: opts.dest, + source: opts.source || undefined, + reverse: true, + }) + : opts.source ? + this.sbot.createUserStream({ + reverse: true, + id: opts.source + }) + : + this.sbot.createFeedStream({ + reverse: true, + }), + opts.text && pull.filter(filterByText(opts.text)) + ) +} + +function forSome(each) { + return function some(obj) { + if (obj == null) return false + if (typeof obj === 'string') return each(obj) + if (Array.isArray(obj)) return obj.some(some) + if (typeof obj === 'object') + for (var k in obj) if (some(obj[k])) return true + return false + } +} + +function filterByText(str) { + if (!str) return function () { return true } + var search = new RegExp(str, 'i') + var matches = forSome(search.test.bind(search)) + return function (msg) { + var c = msg.value.content + return c && matches(c) + } +} + App.prototype.getMsgDecrypted = function (key, cb) { var self = this this.getMsg(key, function (err, msg) { diff --git a/lib/serve.js b/lib/serve.js index 9e1cbb5..d09aa0b 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -228,6 +228,7 @@ Serve.prototype.path = function (url) { case '/public': return this.public(m[2]) case '/private': return this.private(m[2]) case '/search': return this.search(m[2]) + case '/advsearch': return this.advsearch(m[2]) case '/vote': return this.vote(m[2]) case '/peers': return this.peers(m[2]) case '/channels': return this.channels(m[2]) @@ -380,6 +381,58 @@ Serve.prototype.search = function (ext) { ) } +Serve.prototype.advsearch = function (ext) { + var self = this + var q = this.query || {} + + if (q.source) q.source = u.extractFeedIds(q.source)[0] + if (q.dest) q.dest = u.extractFeedIds(q.dest)[0] + var hasQuery = q.text || q.source || q.dest + + pull( + cat([ + ph('section', {}, [ + ph('form', {action: '', method: 'get'}, [ + ph('table', [ + ph('tr', [ + ph('td', 'text'), + ph('td', ph('input', {name: 'text', placeholder: 'regex', + class: 'id-input', + value: q.text || ''})) + ]), + ph('tr', [ + ph('td', 'author'), + ph('td', ph('input', {name: 'source', placeholder: '@id', + class: 'id-input', + value: q.source || ''})) + ]), + ph('tr', [ + ph('td', 'mentions'), + ph('td', ph('input', {name: 'dest', placeholder: 'id', + class: 'id-input', + value: q.dest || ''})) + ]), + ph('tr', [ + ph('td', {colspan: 2}, [ + ph('input', {type: 'submit', value: 'search'}) + ]) + ]), + ]) + ]) + ]), + hasQuery && pull( + self.app.advancedSearch(q), + self.renderThread(), + self.wrapMessages() + ) + ]), + self.wrapPage('advanced search'), + self.respondSink(200, { + 'Content-Type': ctype(ext), + }) + ) +} + Serve.prototype.live = function (ext) { var self = this var q = self.query @@ -908,6 +961,7 @@ Serve.prototype.wrapPage = function (title, searchQ) { h('a', {href: render.toUrl('/peers')}, 'peers') , ' ', h('a', {href: render.toUrl('/channels')}, 'channels') , ' ', h('a', {href: render.toUrl('/friends')}, 'friends'), ' ', + h('a', {href: render.toUrl('/advsearch')}, 'search'), ' ', h('a', {href: render.toUrl('/live')}, 'live'), ' ', render.idLink(self.app.sbot.id, done()), ' ', h('input.search-input', {name: 'q', value: searchQ, @@ -1272,7 +1326,7 @@ Serve.prototype.composer = function (opts, cb) { h('code', '@' + mention.name), ': ', h('input', {name: 'mention_name', type: 'hidden', value: mention.name}), - h('input.mention-id-input', {name: 'mention_id', + h('input.id-input', {name: 'mention_id', value: mention.id, placeholder: 'id'})) })) ] : '', |