git ssb

1+

Daan Patchwork / patchwork



Tree: bfad9d94f6fd6b6ee044e8305e9ce1f7bc1dc32b

Files: bfad9d94f6fd6b6ee044e8305e9ce1f7bc1dc32b / lib / depject / suggest.js

1414 bytesRaw
1const nest = require('depnest')
2const addSuggest = require('suggest-box')
3const resolve = require('mutant/resolve')
4const h = require('mutant/h')
5const emoji = require('node-emoji')
6
7exports.needs = nest({
8 'profile.async.suggest': 'first',
9 'channel.async.suggest': 'first'
10})
11
12exports.gives = nest('suggest.hook')
13
14exports.create = function (api) {
15 return nest('suggest.hook', function SuggestHook ({ participants = null } = {}) {
16 const getProfileSuggestions = api.profile.async.suggest()
17 const getChannelSuggestions = api.channel.async.suggest()
18
19 return function (textArea) {
20 addSuggest(textArea, (inputText, cb) => {
21 if (inputText[0] === '@') {
22 getProfileSuggestions(inputText.slice(1), resolve(participants), cb)
23 } else if (inputText[0] === '#') {
24 getChannelSuggestions(inputText.slice(1), cb)
25 } else if (inputText[0] === ':') {
26 // suggest emojis
27 let word = inputText.slice(1)
28 if (word[word.length - 1] === ':') {
29 word = word.slice(0, -1)
30 }
31 cb(null, emoji.search(word).slice(0, 100).map(function (result) {
32 // result = { key: emoji}
33 return {
34 title: h('span Emoji -suggest', result.emoji),
35 subtitle: result.key,
36 value: result.emoji
37 }
38 }))
39 }
40 }, { cls: 'SuggestBox' })
41 }
42 })
43}
44

Built with git-ssb-web