From b0e5acc92c956cb684deaff62a81e73314eee102 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 3 Apr 2020 20:26:34 +0200 Subject: [PATCH] Parser supports custom emojis --- assets/js/components/emoji/parser.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/assets/js/components/emoji/parser.js b/assets/js/components/emoji/parser.js index c21de3b3..4649c407 100644 --- a/assets/js/components/emoji/parser.js +++ b/assets/js/components/emoji/parser.js @@ -33,7 +33,7 @@ ComunicWeb.components.emoji.parser = { // Parse custom semicolons if(info.user) - console.log(info.user);//info.element.innerHTML = this.parseCustomEmojis(infos.elements.innerHTML) + info.element.innerHTML = this.parseCustomEmojis(info.user, info.element.innerHTML) else console.error("User information are missing!") @@ -103,7 +103,19 @@ ComunicWeb.components.emoji.parser = { //Return result return string; - } + }, + /** + * Apply custom emojies + * + * @param {User} user Information about the user + * @param {String} input Text to transform + */ + parseCustomEmojis: function(user, input) { + for(const e of user.customEmojis) { + input = input.replace(new RegExp(e.shorcut, "g"), ""+e.shorcut+"") + } + return input + }, } \ No newline at end of file