Files: 2aba282967b6a030aeb637a4592a0572ac1451b7 / lib / depject / profile / async / suggest.js
1219 bytesRaw
1 | const nest = require('depnest') |
2 | |
3 | const { onceTrue } = require('mutant') |
4 | const fallbackImageUrl = 'data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==' |
5 | |
6 | exports.needs = nest({ |
7 | 'blob.sync.url': 'first', |
8 | 'sbot.obs.connection': 'first' |
9 | }) |
10 | |
11 | exports.gives = nest('profile.async.suggest') |
12 | |
13 | exports.create = function (api) { |
14 | return nest('profile.async.suggest', function () { |
15 | return function (text, defaultIds, cb) { |
16 | if (arguments.length === 2 && typeof defaultIds === 'function') { |
17 | cb = defaultIds |
18 | defaultIds = null |
19 | } |
20 | onceTrue(api.sbot.obs.connection, sbot => { |
21 | sbot.patchwork.suggest.profile({ text, defaultIds, limit: 20 }, (err, items) => { |
22 | if (err) return cb(err) |
23 | cb(null, getSuggestions(items)) |
24 | }) |
25 | }) |
26 | } |
27 | }) |
28 | |
29 | function getSuggestions (items) { |
30 | return items.map(item => { |
31 | return { |
32 | title: item.name, |
33 | id: item.id, |
34 | subtitle: item.id.substring(0, 10), |
35 | value: `[@${item.name}](${item.id})`, |
36 | cls: item.following ? 'following' : null, |
37 | image: item.image ? api.blob.sync.url(item.image) : fallbackImageUrl, |
38 | showBoth: true |
39 | } |
40 | }) |
41 | } |
42 | } |
43 |
Built with git-ssb-web