Files: 439fbef15cdf6f2dfef52be98bc123702d6b9d2c / about / async / suggest.js
1186 bytesRaw
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 | } |
43 |
Built with git-ssb-web