From 60b0e0f8014aeef37f983cd701b674d25aa6e477 Mon Sep 17 00:00:00 2001 From: Harshit Bansal Date: Sun, 27 Aug 2017 09:04:30 +0000 Subject: [PATCH] emoji_picker: Add `get_alias_to_be_used()` function. Given a `message_id` and `emoji_name` this function returns the alias of the emoji user used for reacting to this message, otherwise, if he has not reacted returns the passed `emoji_name` as it is. --- static/js/emoji_picker.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/static/js/emoji_picker.js b/static/js/emoji_picker.js index 71c621d5fa..b6570ec8b3 100644 --- a/static/js/emoji_picker.js +++ b/static/js/emoji_picker.js @@ -263,6 +263,31 @@ function filter_emojis() { } } +function get_alias_to_be_used(message_id, emoji_name) { + // If the user has reacted to this message, then this function + // returns the alias of this emoji he used, otherwise, returns + // the passed name as it is. + var message = message_store.get(message_id); + var aliases = [emoji_name]; + if (!emoji.active_realm_emojis.hasOwnProperty(emoji_name)) { + if (emoji_codes.name_to_codepoint.hasOwnProperty(emoji_name)) { + var codepoint = emoji_codes.name_to_codepoint[emoji_name]; + aliases = emoji.default_emoji_aliases[codepoint]; + } else { + blueslip.error("Invalid emoji name."); + return; + } + } + var user_id = page_params.user_id; + var reaction = _.find(message.reactions, function (reaction) { + return (reaction.user.id === user_id) && (_.contains(aliases, reaction.emoji_name)); + }); + if (reaction) { + return reaction.emoji_name; + } + return emoji_name; +} + function maybe_select_emoji(e) { if (e.keyCode === 13) { // enter key e.preventDefault();