Commit 439fbef15cdf6f2dfef52be98bc123702d6b9d2c
WIP ssb-suggest , minimal inclusion, starting to replace patch-suggest profile suggesting
mixmix committed on 1/17/2019, 10:48:04 PMParent: 3068af308439c6051b8c9e06bc9316b15827aa23
Files changed
about/async/suggest.js | added |
app/sync/initialise/suggestionCaches.js | changed |
config.js | changed |
server.js | changed |
about/async/suggest.js | ||
---|---|---|
@@ -1,0 +1,42 @@ | ||
1 … | +const nest = require('depnest') | |
2 … | +const { onceTrue } = require('mutant') | |
3 … | + | |
4 … | +var fallbackImageUrl = 'data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==' | |
5 … | + | |
6 … | +exports.gives = nest('about.async.suggest') | |
7 … | + | |
8 … | +exports.needs = nest({ | |
9 … | + 'blob.sync.url': 'first', | |
10 … | + 'sbot.obs.connection': 'first' | |
11 … | +}) | |
12 … | + | |
13 … | +exports.create = function (api) { | |
14 … | + return nest('about.async.suggest', suggestedProfile) | |
15 … | + | |
16 … | + // TODO rework this top API! | |
17 … | + function suggestedProfile (text, defaultIds, cb) { | |
18 … | + if (cb === undefined && typeof defaultIds === 'function') return suggestedProfile(text, [], defaultIds) | |
19 … | + | |
20 … | + onceTrue(api.sbot.obs.connection, ssb => { | |
21 … | + ssb.suggest.profile({ text, defaultIds, limit: 20 }, (err, items) => { | |
22 … | + if (err) return cb(err) | |
23 … | + | |
24 … | + cb(null, items.map(Suggestion)) | |
25 … | + }) | |
26 … | + }) | |
27 … | + | |
28 … | + return true // stop at this depject | |
29 … | + } | |
30 … | + | |
31 … | + function Suggestion (item) { | |
32 … | + return { | |
33 … | + title: item.name, | |
34 … | + id: item.id, | |
35 … | + subtitle: item.id.substring(0, 10), | |
36 … | + value: `[@${item.name}](${item.id})`, | |
37 … | + cls: item.following ? 'following' : null, | |
38 … | + image: item.image ? api.blob.sync.url(item.image) : fallbackImageUrl, | |
39 … | + showBoth: true | |
40 … | + } | |
41 … | + } | |
42 … | +} |
app/sync/initialise/suggestionCaches.js | ||
---|---|---|
@@ -11,11 +11,12 @@ | ||
11 | 11 … | return nest('app.sync.initialise', init) |
12 | 12 … | |
13 | 13 … | function init () { |
14 | 14 … | // lazy load abouts on first use, can be quite heavy during startup |
15 | - setTimeout(() => { | |
16 | - console.log('> loading @mentions cache') | |
17 | - api.about.async.suggest() | |
18 | - }, 20e3) | |
15 … | + // setTimeout(() => { | |
16 … | + // console.log('> loading @mentions cache') | |
17 … | + // api.about.async.suggest() | |
18 … | + // }, 20e3) | |
19 … | + | |
19 | 20 … | api.channel.async.suggest() |
20 | 21 … | } |
21 | 22 … | } |
config.js | ||
---|---|---|
@@ -14,9 +14,9 @@ | ||
14 | 14 … | if (config) return config |
15 | 15 … | |
16 | 16 … | console.log('LOADING config') |
17 | 17 … | config = Config(appName, opts) |
18 | - config.keys = ssbKeys.loadOrCreateSync(Path.join(config.path, 'secret')) | |
18 … | + // config.keys = ssbKeys.loadOrCreateSync(Path.join(config.path, 'secret')) | |
19 | 19 … | |
20 | 20 … | config = merge( |
21 | 21 … | config, |
22 | 22 … | Connections(config), |
server.js | ||
---|---|---|
@@ -23,8 +23,9 @@ | ||
23 | 23 … | .use(require('ssb-meme')) |
24 | 24 … | .use(require('ssb-private')) |
25 | 25 … | .use(require('ssb-query')) |
26 | 26 … | .use(require('ssb-search')) |
27 … | + .use(require('ssb-suggest')) | |
27 | 28 … | .use(require('ssb-unread')) |
28 | 29 … | .use(require('ssb-ws')) |
29 | 30 … | // .use(require('ssb-mutual')) // this is has recursion problems atm |
30 | 31 … |
Built with git-ssb-web