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", "react-native-autolink",
"instabug-reactnative", "instabug-reactnative",
"nfc-react-native", "nfc-react-native",
"react-native-http-bridge" "react-native-http-bridge",
"emojilib"
], ],
"imageDirs": [ "imageDirs": [
"images" "images"

View File

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

View File

@ -26,7 +26,9 @@
new-args (rest text-splitted) new-args (rest text-splitted)
new-input-text (input-model/make-input-text text-splitted old-args)] 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] 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 (handlers/register-handler
:add-to-chat-input-text :add-to-chat-input-text

View File

@ -9,6 +9,17 @@
[status-im.chat.utils :as chat-utils] [status-im.chat.utils :as chat-utils]
[status-im.bots.constants :as bots-constants])) [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] (defn text-ends-with-space? [text]
(when text (when text
(= (str/last-index-of text const/spacing-char) (= (str/last-index-of text const/spacing-char)