diff options
| author | Rohan Patel <rop@odoo.com> | 2017-06-30 12:41:09 +0530 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-09-11 12:20:49 +0200 |
| commit | 8c1f6a7cc6aea43aa9ef99b7b7ae70f5abbe3d92 (patch) | |
| tree | 1f96835762a6c57fadc6ba4f11409b5406856b5d /addons/mail/static/src/js/chat_manager.js | |
| parent | a58fb415fc6465b1a150d7cc295c260b6ac0b9d5 (diff) | |
[IMP] mail,*: replace emojis by unicode in chat messages
*im_livechat,rating.
Emojis are now encoded in unicode characters in messages. This
allows to copy/paste messages including emojis, ensures that
emojis are properly displayed in mail interfaces (at least those
that support unicode, e.g. GMAIL, counter-example: outlook), and
allows the user to directly use emojis of its smartphone in mobile.
This commit also adds several new emojis.
PR #11095
Diffstat (limited to 'addons/mail/static/src/js/chat_manager.js')
| -rw-r--r-- | addons/mail/static/src/js/chat_manager.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js index d0c41ad67b3..807d5352180 100644 --- a/addons/mail/static/src/js/chat_manager.js +++ b/addons/mail/static/src/js/chat_manager.js @@ -29,6 +29,7 @@ var chat_unread_counter = 0; var unread_conversation_counter = 0; var emojis = []; var emoji_substitutions = {}; +var emoji_unicodes = {}; var needaction_counter = 0; var starred_counter = 0; var mention_partner_suggestions = []; @@ -670,8 +671,12 @@ var ChatManager = Class.extend(Mixins.EventDispatcherMixin, ServicesMixin, { if (s.shortcode_type === 'text') { canned_responses.push(_.pick(s, ['id', 'source', 'substitution'])); } else { - emojis.push(_.pick(s, ['id', 'source', 'substitution', 'description'])); + emojis.push(_.pick(s, ['id', 'source', 'unicode_source', 'substitution', 'description'])); emoji_substitutions[_.escape(s.source)] = s.substitution; + if (s.unicode_source) { + emoji_substitutions[_.escape(s.unicode_source)] = s.substitution; + emoji_unicodes[_.escape(s.source)] = s.unicode_source; + } } }); bus.start_polling(); @@ -760,6 +765,14 @@ var ChatManager = Class.extend(Mixins.EventDispatcherMixin, ServicesMixin, { body: body, attachment_ids: data.attachment_ids, }; + + // Replace emojis by their unicode character + _.each(_.keys(emoji_unicodes), function (key) { + var escaped_key = String(key).replace(/([.*+?=^!:${}()|[\]\/\\])/g, '\\$1'); + var regexp = new RegExp("(\\s|^)(" + escaped_key + ")(?=\\s|$)", "g"); + msg.body = msg.body.replace(regexp, "$1" + emoji_unicodes[key]); + }); + if ('subject' in data) { msg.subject = data.subject; } |
