From bec6cefd0cd0d91ea13019bc75f70d629b2dafd2 Mon Sep 17 00:00:00 2001 From: "Didier (did)" Date: Wed, 17 Aug 2022 08:23:30 +0000 Subject: [PATCH] [IMP] mail: differentiate message and notification in channel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR changes the way notification are displayed inside the a channel. Currently, notification look exactly the same as a message send by the user. task-2918956 closes odoo/odoo#98262 Related: odoo/enterprise#30732 Signed-off-by: Alexandre Kühn (aku) --- .../components/message_list/message_list.xml | 3 +- .../notification_message_view.js | 23 +++++++++++++ .../notification_message_view.scss | 3 ++ .../notification_message_view.xml | 12 +++++++ addons/mail/static/src/models/message.js | 4 +++ .../src/models/message_list_view_item.js | 34 ++++++++++++++++--- .../src/models/message_notification_view.js | 19 +++++++++++ addons/mail/static/src/models/thread_view.js | 2 +- 8 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 addons/mail/static/src/components/notification_message_view/notification_message_view.js create mode 100644 addons/mail/static/src/components/notification_message_view/notification_message_view.scss create mode 100644 addons/mail/static/src/components/notification_message_view/notification_message_view.xml create mode 100644 addons/mail/static/src/models/message_notification_view.js diff --git a/addons/mail/static/src/components/message_list/message_list.xml b/addons/mail/static/src/components/message_list/message_list.xml index c345e2e6cda..28e560a5bfd 100644 --- a/addons/mail/static/src/components/message_list/message_list.xml +++ b/addons/mail/static/src/components/message_list/message_list.xml @@ -62,7 +62,8 @@ - + + diff --git a/addons/mail/static/src/components/notification_message_view/notification_message_view.js b/addons/mail/static/src/components/notification_message_view/notification_message_view.js new file mode 100644 index 00000000000..3d4df66fda8 --- /dev/null +++ b/addons/mail/static/src/components/notification_message_view/notification_message_view.js @@ -0,0 +1,23 @@ +/** @odoo-module **/ + +import { registerMessagingComponent } from '@mail/utils/messaging_component'; + +const { Component } = owl; + +class NotificationMessageView extends Component { + + /** + * @returns {NotificationMessageView} + */ + get notificationMessageView() { + return this.props.record; + } + +} + +Object.assign(NotificationMessageView, { + props: { record: Object }, + template: 'mail.NotificationMessageView', +}); + +registerMessagingComponent(NotificationMessageView); diff --git a/addons/mail/static/src/components/notification_message_view/notification_message_view.scss b/addons/mail/static/src/components/notification_message_view/notification_message_view.scss new file mode 100644 index 00000000000..7c32d36a680 --- /dev/null +++ b/addons/mail/static/src/components/notification_message_view/notification_message_view.scss @@ -0,0 +1,3 @@ +.o_mail_notification { + display: inline; +} diff --git a/addons/mail/static/src/components/notification_message_view/notification_message_view.xml b/addons/mail/static/src/components/notification_message_view/notification_message_view.xml new file mode 100644 index 00000000000..19888491a7b --- /dev/null +++ b/addons/mail/static/src/components/notification_message_view/notification_message_view.xml @@ -0,0 +1,12 @@ + + + +
+
+
+ +
+
+
+ + diff --git a/addons/mail/static/src/models/message.js b/addons/mail/static/src/models/message.js index 5da2072a71e..d5150b91394 100644 --- a/addons/mail/static/src/models/message.js +++ b/addons/mail/static/src/models/message.js @@ -817,6 +817,10 @@ registerModel({ compute: '_computeMessageTypeText', }), message_type: attr(), + notificationMessageViews: many('NotificationMessageView', { + inverse: 'message', + isCausal: true, + }), /** * States the views that are displaying this message. */ diff --git a/addons/mail/static/src/models/message_list_view_item.js b/addons/mail/static/src/models/message_list_view_item.js index d7c1e815bf4..81f8914a68a 100644 --- a/addons/mail/static/src/models/message_list_view_item.js +++ b/addons/mail/static/src/models/message_list_view_item.js @@ -2,6 +2,7 @@ import { registerModel } from '@mail/model/model_core'; import { attr, one } from '@mail/model/model_field'; +import { clear } from '@mail/model/model_field_command'; /** * Models a relation between a message list view and a message view where @@ -9,6 +10,28 @@ import { attr, one } from '@mail/model/model_field'; */ registerModel({ name: 'MessageListViewItem', + recordMethods: { + /** + * @private + * @returns {FieldCommand} + */ + _computeNotificationMessageView() { + if (this.message.message_type === 'notification' && this.message.originThread.channel) { + return {}; + } + return clear(); + }, + /** + * @private + * @returns {FieldCommand} + */ + _computeMessageView() { + if (this.message.message_type !== 'notification' || !this.message.originThread.channel) { + return {}; + } + return clear(); + }, + }, fields: { isSquashed: attr({ required: true, @@ -21,12 +44,15 @@ registerModel({ identifying: true, inverse: 'messageListViewItems', }), - messageView: one('MessageView', { - default: {}, + notificationMessageView: one('NotificationMessageView', { + compute: '_computeNotificationMessageView', + inverse: 'messageListViewItemOwner', + isCausal: true, + }), + messageView: one('MessageView', { + compute: '_computeMessageView', inverse: 'messageListViewItemOwner', isCausal: true, - readonly: true, - required: true, }), }, }); diff --git a/addons/mail/static/src/models/message_notification_view.js b/addons/mail/static/src/models/message_notification_view.js new file mode 100644 index 00000000000..e288294d361 --- /dev/null +++ b/addons/mail/static/src/models/message_notification_view.js @@ -0,0 +1,19 @@ +/** @odoo-module **/ + +import { registerModel } from '@mail/model/model_core'; +import { one } from '@mail/model/model_field'; + +registerModel({ + name: 'NotificationMessageView', + fields: { + message: one('Message', { + related: 'messageListViewItemOwner.message', + inverse: 'notificationMessageViews', + required: true, + }), + messageListViewItemOwner: one('MessageListViewItem', { + identifying: true, + inverse: 'notificationMessageView', + }), + }, +}); diff --git a/addons/mail/static/src/models/thread_view.js b/addons/mail/static/src/models/thread_view.js index 224691881b1..0d5b89ce989 100644 --- a/addons/mail/static/src/models/thread_view.js +++ b/addons/mail/static/src/models/thread_view.js @@ -155,7 +155,7 @@ registerModel({ return clear(); } const { length, [length - 1]: messageListViewItem } = this.messageListView.messageListViewItems; - return messageListViewItem ? messageListViewItem.messageView : clear(); + return messageListViewItem && messageListViewItem.messageView ? messageListViewItem.messageView : clear(); }, /** * @private