summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/models
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2020-08-24 10:37:47 +0000
committerSébastien Theys <seb@odoo.com>2020-08-24 13:21:45 +0000
commit72b9335334c076d8deaa36e404feaa3f4d30c351 (patch)
treeaea8c816b33d89b409fedbc75bcca3d2d6597717 /addons/mail/static/src/models
parent0834d241624330ab3fd3925366a3217fe8145dfc (diff)
[FIX] mail, im_livechat: make livechat work properly
- fix traceback on receiving first livechat message due to bad computation of correspondent - fix missing [0] in return of country name_get in channel_info - fix visitor/correspondent computation to work when chatting with oneself - reintroduce livechat ordered by last message in discuss sidebar - improve mock server to make these fixes possible to test - introduce corresponding tests PR: #56243 task-2323670 closes odoo/odoo#56414 X-original-commit: f623bfd2c8819604c709bc723153c071dca6e3cc Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail/static/src/models')
-rw-r--r--addons/mail/static/src/models/message/message.js9
-rw-r--r--addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js15
-rw-r--r--addons/mail/static/src/models/thread/thread.js12
3 files changed, 27 insertions, 9 deletions
diff --git a/addons/mail/static/src/models/message/message.js b/addons/mail/static/src/models/message/message.js
index 582745e28f2..e982df36667 100644
--- a/addons/mail/static/src/models/message/message.js
+++ b/addons/mail/static/src/models/message/message.js
@@ -607,12 +607,13 @@ function factory(dependencies) {
tracking_value_ids: attr({
default: [],
}),
-
/**
- * All channels that this message is linked to (from server message
- * format).
+ * All channels containing this message on the server.
+ * Equivalent of python field `channel_ids`.
*/
- serverChannels: many2many('mail.thread'),
+ serverChannels: many2many('mail.thread', {
+ inverse: 'messagesAsServerChannel',
+ }),
};
Message.modelName = 'mail.message';
diff --git a/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js b/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js
index 49f07bc5423..d89992d8a4b 100644
--- a/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js
+++ b/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js
@@ -56,7 +56,7 @@ function factory(dependencies) {
/**
* @private
* @param {Object[]} notifications
- * @param {Array} notifications[i][0] meta-data of the notification.
+ * @param {Array|string} notifications[i][0] meta-data of the notification.
* @param {string} notifications[i][0][0] name of database this
* notification comes from.
* @param {string} notifications[i][0][1] type of notification.
@@ -68,20 +68,25 @@ function factory(dependencies) {
async _handleNotifications(notifications) {
const filteredNotifications = this._filterNotificationsOnUnsubscribe(notifications);
const proms = filteredNotifications.map(notification => {
- const [[, model, id], data] = notification;
+ const [channel, message] = notification;
+ if (typeof channel === 'string') {
+ // uuid notification, only for (livechat) public handler
+ return;
+ }
+ const [, model, id] = channel;
switch (model) {
case 'ir.needaction':
- return this._handleNotificationNeedaction(data);
+ return this._handleNotificationNeedaction(message);
case 'mail.channel':
return this._handleNotificationChannel(Object.assign({
channelId: id,
- }, data));
+ }, message));
case 'res.partner':
if (id !== this.env.messaging.currentPartner.id) {
// ignore broadcast to other partners
return;
}
- return this._handleNotificationPartner(Object.assign({}, data));
+ return this._handleNotificationPartner(Object.assign({}, message));
default:
console.warn(`mail.messaging_notification_handler: Unhandled notification "${model}"`);
return;
diff --git a/addons/mail/static/src/models/thread/thread.js b/addons/mail/static/src/models/thread/thread.js
index 74cae5d25ab..e3d48d54e35 100644
--- a/addons/mail/static/src/models/thread/thread.js
+++ b/addons/mail/static/src/models/thread/thread.js
@@ -779,8 +779,13 @@ function factory(dependencies) {
partner !== this.env.messaging.currentPartner
);
if (correspondents.length === 1) {
+ // 2 members chat
return [['link', correspondents[0]]];
}
+ if (this.members.length === 1) {
+ // chat with oneself
+ return [['link', this.members[0]]];
+ }
return [['unlink']];
}
@@ -1360,6 +1365,13 @@ function factory(dependencies) {
messages: many2many('mail.message', {
inverse: 'threads',
}),
+ /**
+ * All messages that are contained on this channel on the server.
+ * Equivalent to the inverse of python field `channel_ids`.
+ */
+ messagesAsServerChannel: many2many('mail.message', {
+ inverse: 'serverChannels',
+ }),
messageSeenIndicators: one2many('mail.message_seen_indicator', {
inverse: 'thread',
isCausal: true,