Files: 1006d0c4dde00ee503cde396de716125b96524c1 / lib / depject / suggest.js
1414 bytesRaw
1 | const nest = require('depnest') |
2 | const addSuggest = require('suggest-box') |
3 | const resolve = require('mutant/resolve') |
4 | const h = require('mutant/h') |
5 | const emoji = require('node-emoji') |
6 | |
7 | exports.needs = nest({ |
8 | 'profile.async.suggest': 'first', |
9 | 'channel.async.suggest': 'first' |
10 | }) |
11 | |
12 | exports.gives = nest('suggest.hook') |
13 | |
14 | exports.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