modules/message/html/compose.jsView |
---|
7 | 7 | var nest = require('depnest') |
8 | 8 | var mentions = require('ssb-mentions') |
9 | 9 | var extend = require('xtend') |
10 | 10 | var addSuggest = require('suggest-box') |
| 11 | +var emoji = require('emojilib') |
11 | 12 | |
12 | 13 | exports.needs = nest({ |
13 | 14 | 'blob.html.input': 'first', |
14 | 15 | 'profile.async.suggest': 'first', |
141 | 142 | var word = inputText.slice(1) |
142 | 143 | if (word[word.length - 1] === ':') { |
143 | 144 | word = word.slice(0, -1) |
144 | 145 | } |
145 | | - |
146 | | - cb(null, api.emoji.sync.names().filter(function (name) { |
147 | | - return name.slice(0, word.length) === word |
148 | | - }).slice(0, 100).map(function (emoji) { |
| 146 | + cb(null, suggestEmoji(word).slice(0, 100).map(function (emoji) { |
149 | 147 | return { |
150 | 148 | image: api.emoji.sync.url(emoji), |
151 | 149 | title: emoji, |
152 | 150 | subtitle: emoji, |
205 | 203 | } |
206 | 204 | } |
207 | 205 | } |
208 | 206 | }) |
| 207 | + |
| 208 | + function suggestEmoji (prefix) { |
| 209 | + var availableEmoji = api.emoji.sync.names() |
| 210 | + return emoji.ordered.filter(key => { |
| 211 | + if (!availableEmoji.includes(key)) return false |
| 212 | + return key.startsWith(prefix) || key.includes('_' + prefix) || emoji.lib[key].keywords.some(word => word.startsWith(prefix) || word.startsWith(':' + prefix)) |
| 213 | + }) |
| 214 | + } |
209 | 215 | } |
210 | 216 | |
211 | 217 | function showDialog (opts) { |
212 | 218 | var electron = require('electron') |