From 79831dad81beedff8657b14ff51166f3d54bd18a Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Thu, 4 Jan 2018 19:47:41 +0530 Subject: [PATCH] load emojis async, covers all emojis --- frappe/public/js/frappe/ui/comment.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/frappe/public/js/frappe/ui/comment.js b/frappe/public/js/frappe/ui/comment.js index e37724ddb3..0f37fa4650 100644 --- a/frappe/public/js/frappe/ui/comment.js +++ b/frappe/public/js/frappe/ui/comment.js @@ -18,6 +18,10 @@ frappe.ui.CommentArea = class CommentArea { this.no_wrapper = no_wrapper; this.make(); + + // Load emojis initially from https://git.io/frappe-emoji + frappe.chat.emoji(); + // All good. } make() { @@ -70,24 +74,32 @@ frappe.ui.CommentArea = class CommentArea { keyword = keyword.substr(1); items = this.mentions; } else if (keyword.startsWith(':')) { - items = frappe.ui.emoji_keywords - .filter(k => k.startsWith(keyword)) - .slice(0, 7); + frappe.chat.emoji(emojis => { // Returns cached, else fetch. + const query = keyword.slice(1) + const items = [ ] + for (const emoji of emojis) + for (const alias of emoji.aliases) + if ( alias.indexOf(query) === 0 ) + items.push({ emoji: true, name: alias, value: emoji.emoji }) + + callback(items) + }); } + callback($.grep(items, function (item) { return item.indexOf(keyword) == 0; })); }, template: function (item) { - if (item.startsWith(':')) { - return frappe.ui.get_emoji(item) + ' ' + item; + if ( item.emoji ) { + return item.value + ' ' + item.name; } else { return item; } }, content: function (item) { - if(item.startsWith(':')) { - return frappe.ui.get_emoji(item); + if ( item.emoji ) { + return item.value; } else { return '@' + item; }