Skip to content
Snippets Groups Projects
Commit 81287c0a authored by Alexandre Kühn's avatar Alexandre Kühn
Browse files

[FIX] mail: post message with emojis x'D (:joy:)

Before this commit, when posting a message with some emoji sources (e.g. "x'D"),
sometimes it was not transformed into the corresponding unicode representation
(e.g. ":joy:").

The emojis with this issue have different escaped and unescaped source
representations:

  - (unescaped) "x'D"
  - (escaped) "x'D".

The emoji converter was mistakenly using the escaped representation, instead of
the unescaped one.

Task-ID 1868892
parent da7b5904
Branches
Tags
No related merge requests found
......@@ -370,7 +370,7 @@ var Thread = AbstractThread.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
_generateEmojis: function (htmlString) {
_.each(emojis, function (emoji) {
_.each(emoji.sources, function (source) {
var escapedSource = String(_.escape(source)).replace(/([.*+?=^!:${}()|[\]/\\])/g, '\\$1');
var escapedSource = String(source).replace(/([.*+?=^!:${}()|[\]/\\])/g, '\\$1');
var regexp = new RegExp("(\\s|^)(" + escapedSource + ")(?=\\s|$)", 'g');
htmlString = htmlString.replace(regexp, '$1' + emoji.unicode);
});
......
......@@ -620,5 +620,71 @@ QUnit.test('confirm dialog when administrator leave (not chat) channel', functio
});
QUnit.test('convert emoji sources to unicodes on message_post', function (assert) {
assert.expect(2);
var done = assert.async();
var bus = this.services[1].prototype.bus;
var receiveMessageDef = $.Deferred();
this.data.initMessaging = {
channel_slots: {
channel_channel: [{
id: 1,
channel_type: "channel",
name: "general",
}],
},
};
createDiscuss({
id: 1,
context: {},
params: {},
data: this.data,
services: this.services,
mockRPC: function (route, args) {
if (args.method === 'message_post') {
assert.strictEqual(args.kwargs.body, "😊 😂",
"message_post data should have all emojis in their unicode representation");
var data = {
author_id: ["42", "Me"],
body: args.kwargs.body,
channel_ids: [1],
};
var notification = [[false, 'mail.channel'], data];
bus.trigger('notification', [notification]);
receiveMessageDef.resolve();
return $.when(42);
}
return this._super.apply(this, arguments);
},
})
.then(function (discuss) {
var $general = discuss.$('.o_mail_discuss_sidebar')
.find('.o_mail_discuss_item[data-thread-id=1]');
// click on general
$general.click();
var $input = discuss.$('textarea.o_composer_text_field').first();
$input.focus();
$input.val(":) x'D");
$input.trigger($.Event('keydown', {which: $.ui.keyCode.ENTER}));
receiveMessageDef
.then(concurrency.delay.bind(concurrency, 0))
.then(function () {
assert.strictEqual(discuss.$('.o_thread_message_content').text().replace(/\s/g, ""),
"😊😂",
"New posted message should contain all emojis in their unicode representation");
discuss.destroy();
done();
});
});
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment