aboutsummaryrefslogtreecommitdiff
path: root/lib/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/app.js')
-rw-r--r--lib/app.js43
1 files changed, 43 insertions, 0 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) {