git ssb

10+

Matt McKegg / patchwork



Commit 8b3e0bbdac89aa4cd743500d35bbd504bd7a49b7

suggest emoji based on keywords from emojilib

close #664
Matt McKegg committed on 11/3/2017, 1:22:04 AM
Parent: 72b6c6ce34bbd3cdbde8d7ce8efb35bf50fbe7ef

Files changed

modules/message/html/compose.jschanged
package.jsonchanged
modules/message/html/compose.jsView
@@ -7,8 +7,9 @@
77 var nest = require('depnest')
88 var mentions = require('ssb-mentions')
99 var extend = require('xtend')
1010 var addSuggest = require('suggest-box')
11 +var emoji = require('emojilib')
1112
1213 exports.needs = nest({
1314 'blob.html.input': 'first',
1415 'profile.async.suggest': 'first',
@@ -141,12 +142,9 @@
141142 var word = inputText.slice(1)
142143 if (word[word.length - 1] === ':') {
143144 word = word.slice(0, -1)
144145 }
145- // TODO: when no emoji typed, list some default ones
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) {
149147 return {
150148 image: api.emoji.sync.url(emoji),
151149 title: emoji,
152150 subtitle: emoji,
@@ -205,8 +203,16 @@
205203 }
206204 }
207205 }
208206 })
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 + }
209215 }
210216
211217 function showDialog (opts) {
212218 var electron = require('electron')
package.jsonView
@@ -24,8 +24,9 @@
2424 "depnest": "^1.0.2",
2525 "electron-default-menu": "~1.0.0",
2626 "electron-spellchecker": "^1.0.4",
2727 "electron-window-state": "^4.1.0",
28 + "emojilib": "^2.2.9",
2829 "fix-path": "^2.1.0",
2930 "flatpickr": "^3.0.5-1",
3031 "flumeview-level": "^2.0.3",
3132 "hashlru": "^2.2.0",

Built with git-ssb-web