aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/app.js43
-rw-r--r--lib/serve.js56
2 files changed, 98 insertions, 1 deletions
diff --git a/lib/app.js b/lib/app.js
index b64ec2a..6653c1d 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -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'}))
}))
] : '',