[FIX] im_support, mail: message with odoobot as author

Before this commit, the `author_id` of a message with odoobot was
`"ODOOBOT"`. This leads to some issues due to `author_id` being
considered as an array `[partnerID, name]`.

Because of this, mail status manager was registering a partner with
ID `"O"` (1st char of `"ODOOBOT"`) for fetching its `im_status`. Its
`im_status` was never updated, since no partner has such ID. However,
the mail status manager kept this partner flagged with missing
`im_status` and still attempted to fetch its `im_status`,
indefinitely.

This commit fixes the issue by turning `author_id` of a message with
odoobot into arrray `["ODOOBOT", "ODOOBOT"]`. That way, `author_id`
of a message is always an array, and the `im_status` of `"ODOOBOT"`
is no longer fetched.
This commit is contained in:
Alexandre Kühn
2019-05-20 07:35:12 +00:00
parent a31b7f4a3e
commit b5ce994762
5 changed files with 12 additions and 6 deletions
@@ -14,7 +14,10 @@ var SupportMessage = Message.extend({
*/
init: function () {
this._super.apply(this, arguments);
if (this._serverAuthorID !== this.call('mail_service', 'getOdoobotID')) {
if (
!this._serverAuthorID ||
this._serverAuthorID[0] !== this.call('mail_service', 'getOdoobotID')[0]
) {
if (!this._serverAuthorID[0]) {
// the author is the client
this._serverAuthorID = [session.partner_id, session.name];
@@ -578,7 +578,8 @@ var Message = AbstractMessage.extend(Mixins.EventDispatcherMixin, ServicesMixin
* @return {boolean}
*/
_isOdoobotAuthor: function () {
return this._serverAuthorID === this.call('mail_service', 'getOdoobotID');
return this._serverAuthorID &&
this._serverAuthorID[0] === this.call('mail_service', 'getOdoobotID')[0];
},
/**
* State whether the message is transient or not
@@ -46,7 +46,7 @@ var PREVIEW_MSG_MAX_SIZE = 350; // optimal for native english speakers
var MailManager = AbstractService.extend({
dependencies: ['ajax', 'bus_service', 'local_storage'],
_ODOOBOT_ID: "ODOOBOT", // default authorID for transient messages
_ODOOBOT_ID: ["ODOOBOT", "ODOOBOT"], // authorID for transient messages
/**
* @override
@@ -258,7 +258,7 @@ var MailManager = AbstractService.extend({
/**
* Get the OdooBot ID, which is the default authorID for transient messages
*
* @returns {string}
* @returns {Array<string>}
*/
getOdoobotID: function () {
return this._ODOOBOT_ID;
@@ -468,12 +468,11 @@ MailManager.include({
*
* @private
* @param {Object} data
* @param {string} data.author_id
*/
_handlePartnerTransientMessageNotification: function (data) {
var lastMessage = _.last(this._messages);
data.id = (lastMessage ? lastMessage.getID() : 0) + 0.01;
data.author_id = data.author_id || this.getOdoobotID();
data.author_id = this.getOdoobotID();
this.addMessage(data);
},
/**
@@ -30,6 +30,9 @@ MailManager.include({
getImStatus: function (data) {
var self = this;
var partnerID = data.partnerID;
if (partnerID === this.getOdoobotID()[0]) {
return 'bot';
}
if (!this._imStatus[partnerID]) {
// Add to list to call it in next bus update or _fetchMissingImStatus
this._imStatus[partnerID] = undefined;