[IMP] mail: turn 'MessageAuthorPrefixView/message' into field

Task-2793280

closes odoo/odoo#86980

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Alexandre Kühn
2022-03-24 18:58:26 +01:00
parent 6b8bf0dd41
commit c44f35f61d
5 changed files with 23 additions and 14 deletions
@@ -13,13 +13,6 @@ export class MessageAuthorPrefix extends Component {
return this.messaging && this.messaging.models['MessageAuthorPrefixView'].get(this.props.localId);
}
/**
* @returns {Message}
*/
get message() {
return this.messaging && this.messaging.models['Message'].get(this.props.messageLocalId);
}
/**
* @returns {Thread|undefined}
*/
@@ -32,7 +25,6 @@ export class MessageAuthorPrefix extends Component {
Object.assign(MessageAuthorPrefix, {
props: {
localId: String,
messageLocalId: String,
threadLocalId: {
type: String,
optional: true,
@@ -4,12 +4,12 @@
<t t-name="mail.MessageAuthorPrefix" owl="1">
<t t-if="messageAuthorPrefixView">
<span class="o_MessageAuthorPrefix" t-attf-class="{{ className }}" t-ref="root">
<t t-if="message">
<t t-if="message.author and message.author === messaging.currentPartner">
<t t-if="messageAuthorPrefixView.message">
<t t-if="messageAuthorPrefixView.message.author and messageAuthorPrefixView.message.author === messaging.currentPartner">
<i class="o_MessageAuthorPrefixIcon fa fa-mail-reply"/>You:
</t>
<t t-elif="thread and message.author !== thread.correspondent">
<t t-esc="message.author.nameOrDisplayName"/>:
<t t-elif="thread and messageAuthorPrefixView.message.author !== thread.correspondent">
<t t-esc="messageAuthorPrefixView.message.author.nameOrDisplayName"/>:
</t>
</t>
</span>
@@ -42,7 +42,6 @@
<t t-if="threadNeedactionPreviewView.messageAuthorPrefixView">
<MessageAuthorPrefix
localId="threadNeedactionPreviewView.messageAuthorPrefixView.localId"
messageLocalId="threadNeedactionPreviewView.thread.lastNeedactionMessageAsOriginThread.localId"
threadLocalId="threadNeedactionPreviewView.thread.localId"
/>
</t>
@@ -48,7 +48,6 @@
<t t-if="threadPreviewView.messageAuthorPrefixView">
<MessageAuthorPrefix
localId="threadPreviewView.messageAuthorPrefixView.localId"
messageLocalId="threadPreviewView.thread.lastMessage.localId"
threadLocalId="threadPreviewView.thread.localId"
/>
</t>
@@ -2,11 +2,30 @@
import { registerModel } from '@mail/model/model_core';
import { one } from '@mail/model/model_field';
import { clear, replace } from '@mail/model/model_field_command';
registerModel({
name: 'MessageAuthorPrefixView',
identifyingFields: [['threadNeedactionPreviewViewOwner', 'threadPreviewViewOwner']],
recordMethods: {
/**
* @private
* @returns {FieldCommand}
*/
_computeMessage() {
if (this.threadNeedactionPreviewViewOwner) {
return replace(this.threadNeedactionPreviewViewOwner.thread.lastNeedactionMessageAsOriginThread);
}
if (this.threadPreviewViewOwner) {
return replace(this.threadPreviewViewOwner.thread.lastMessage);
}
return clear();
},
},
fields: {
message: one('Message', {
compute: '_computeMessage',
}),
threadNeedactionPreviewViewOwner: one('ThreadNeedactionPreviewView', {
inverse: 'messageAuthorPrefixView',
readonly: true,