git ssb

16+

Dominic / patchbay



Commit 439fbef15cdf6f2dfef52be98bc123702d6b9d2c

WIP ssb-suggest , minimal inclusion, starting to replace patch-suggest profile suggesting

mixmix committed on 1/17/2019, 10:48:04 PM
Parent: 3068af308439c6051b8c9e06bc9316b15827aa23

Files changed

about/async/suggest.jsadded
app/sync/initialise/suggestionCaches.jschanged
config.jschanged
server.jschanged
about/async/suggest.jsView
@@ -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.jsView
@@ -11,11 +11,12 @@
1111 return nest('app.sync.initialise', init)
1212
1313 function init () {
1414 // 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 +
1920 api.channel.async.suggest()
2021 }
2122 }
config.jsView
@@ -14,9 +14,9 @@
1414 if (config) return config
1515
1616 console.log('LOADING config')
1717 config = Config(appName, opts)
18- config.keys = ssbKeys.loadOrCreateSync(Path.join(config.path, 'secret'))
18 + // config.keys = ssbKeys.loadOrCreateSync(Path.join(config.path, 'secret'))
1919
2020 config = merge(
2121 config,
2222 Connections(config),
server.jsView
@@ -23,8 +23,9 @@
2323 .use(require('ssb-meme'))
2424 .use(require('ssb-private'))
2525 .use(require('ssb-query'))
2626 .use(require('ssb-search'))
27 + .use(require('ssb-suggest'))
2728 .use(require('ssb-unread'))
2829 .use(require('ssb-ws'))
2930 // .use(require('ssb-mutual')) // this is has recursion problems atm
3031

Built with git-ssb-web