chat: emoji replace

This commit is contained in:
Matthieu Béteille 2017-06-28 20:36:24 +01:00 committed by Roman Volosovskyi
parent 173d4afbf3
commit 8a3b7372ab
4 changed files with 21 additions and 6 deletions

View File

@ -40,7 +40,8 @@
"react-native-autolink",
"instabug-reactnative",
"nfc-react-native",
"react-native-http-bridge"
"react-native-http-bridge",
"emojilib"
],
"imageDirs": [
"images"

View File

@ -29,6 +29,7 @@
"dns.js": "^1.0.1",
"domain-browser": "^1.1.7",
"eccjs": "0.3.1",
"emojilib": "^2.2.1",
"events": "^1.1.1",
"homoglyph-finder": "^1.1.1",
"https-browserify": "0.0.1",

View File

@ -14,10 +14,10 @@
[clojure.string :as str]))
(handlers/register-handler
:set-chat-input-text
(fn [{:keys [current-chat-id chats chat-ui-props] :as db} [_ text chat-id]]
(let [chat-id (or chat-id current-chat-id)
ends-with-space? (input-model/text-ends-with-space? text)]
:set-chat-input-text
(fn [{:keys [current-chat-id chats chat-ui-props] :as db} [_ text chat-id]]
(let [chat-id (or chat-id current-chat-id)
ends-with-space? (input-model/text-ends-with-space? text)]
(dispatch [:update-suggestions chat-id text])
(if-let [{command :command} (input-model/selected-chat-command db chat-id text)]
@ -26,7 +26,9 @@
new-args (rest text-splitted)
new-input-text (input-model/make-input-text text-splitted old-args)]
(assoc-in db [:chats chat-id :input-text] new-input-text))
(assoc-in db [:chats chat-id :input-text] text)))))
(->> text
(input-model/text->emoji)
(assoc-in db [:chats chat-id :input-text]))))))
(handlers/register-handler
:add-to-chat-input-text

View File

@ -9,6 +9,17 @@
[status-im.chat.utils :as chat-utils]
[status-im.bots.constants :as bots-constants]))
(def emojis (js/require "emojilib"))
(defn text->emoji [text]
(when text
(str/replace text
#":([a-z_\-+0-9]*):"
(fn [[original emoji-id]]
(if-let [emoji-map (aget emojis "lib" emoji-id)]
(aget emoji-map "char")
original)))))
(defn text-ends-with-space? [text]
(when text
(= (str/last-index-of text const/spacing-char)