git ssb

1+

Daan Patchwork / patchwork



Tree: 4d9f238ff73f7136cd292da88f06c17fe1a8c445

Files: 4d9f238ff73f7136cd292da88f06c17fe1a8c445 / lib / depject / channel / async / suggest.js

850 bytesRaw
1const nest = require('depnest')
2
3const { onceTrue } = require('mutant')
4
5exports.needs = nest({
6 'sbot.obs.connection': 'first'
7})
8
9exports.gives = nest('channel.async.suggest')
10
11exports.create = function (api) {
12 return nest('channel.async.suggest', function () {
13 return function (text, cb) {
14 onceTrue(api.sbot.obs.connection, sbot => {
15 sbot.patchwork.channels.suggest({ text, limit: 20 }, (err, items) => {
16 if (err) return cb(err)
17 cb(null, getSuggestions(items))
18 })
19 })
20 }
21 })
22
23 function getSuggestions (items) {
24 return items.map(item => {
25 return {
26 title: `#${item.id}`,
27 id: `#${item.id}`,
28 subtitle: item.count ? `(${item.count})` : null,
29 value: `#${item.id}`,
30 cls: 'channel' + (item.subscribed ? ' .-subscribed' : '')
31 }
32 })
33 }
34}
35

Built with git-ssb-web