I'm using version 11 and trying to override a plain function defined in mail.chat_manager.js
https://github.com/odoo/odoo/blob/3bc4d91e9b87286a2c0a43b775e80afbbb7c8122/addons/mail/static/src/js/chat_manager.js#L74
It's possible to override methods written in widget by using "widget.extend" and then returning the widget.
But how to override a function that is not written in a widget?
Here is what I tried.
The problem is it doesn't even enter my new redefined add_message.(console.log is not printing anything)
odoo.define('crm_extension.ChatManager', function (require) {
var ChatManager = require('mail.chat_manager');
var bus = require('bus.bus').bus;
var config = require('web.config');
function add_message(data, options) {
console.log("Enter here");
options = options || {};
var msg = _.findWhere(messages, { id: data.id });
if (!msg) {
msg = chat_manager.make_message(data);
messages.splice(_.sortedIndex(messages, msg, 'id'), 0, msg);
_.each(msg.channel_ids, function (channel_id) {
var channel = chat_manager.get_channel(channel_id);
if (channel) {
if (!channel.last_message || msg.id > channel.last_message.id) {
channel.last_message = msg;
}
add_to_cache(msg, []);
if (options.domain && options.domain !== []) {
add_to_cache(msg, options.domain);
}
if (channel.hidden) {
channel.hidden = false;
chat_manager.bus.trigger('new_channel', channel);
}
if (channel.type !== 'static' && !msg.is_author && !msg.is_system_notification) {
if (options.increment_unread) {
update_channel_unread_counter(channel, channel.unread_counter+1);
}
console.log("dddddddddd");
if (options.show_notification) {
if (!client_action_open && !config.device.isMobile) {
chat_manager.bus.trigger('open_chat', channel, { passively: true });
}
var query = {is_displayed: false};
chat_manager.bus.trigger('anyone_listening', channel, query);
notify_incoming_message(msg, query);
}
}
}
});
if (!options.silent) {
chat_manager.bus.trigger('new_message', msg);
}
} else if (options.domain && options.domain !== []) {
add_to_cache(msg, options.domain);
}
return msg;
}
});