[IMP] mail: turn 'MessageView/hasAuthorOpenChat' into field

Task-2793280

closes odoo/odoo#86466

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Alexandre Kühn
2022-03-18 15:11:45 +01:00
parent 642cec94c4
commit 73db2d735f
3 changed files with 29 additions and 25 deletions
@@ -95,28 +95,6 @@ export class Message extends Component {
return this.messageView.message.date.format(getLangDatetimeFormat());
}
/**
* Determines whether author open chat feature is enabled on message.
*
* @returns {boolean}
*/
get hasAuthorOpenChat() {
if (this.messaging.currentGuest) {
return false;
}
if (!this.messageView.message.author) {
return false;
}
if (
this.messageView.threadView &&
this.messageView.threadView.thread &&
this.messageView.threadView.thread.correspondent === this.messageView.message.author
) {
return false;
}
return true;
}
/**
* Whether the message is "active", ie: hovered or clicked, and should
* display additional things (date in sidebar, message actions, etc.)
@@ -406,7 +384,7 @@ export class Message extends Component {
*/
_onClickAuthorAvatar(ev) {
markEventHandled(ev, 'Message.ClickAuthorAvatar');
if (!this.hasAuthorOpenChat) {
if (!this.messageView.hasAuthorOpenChat) {
return;
}
this.messageView.message.author.openChat();
@@ -29,7 +29,7 @@
<div class="o_Message_sidebar" t-att-class="{ 'o-message-squashed align-items-start': messageView.isSquashed }">
<t t-if="!messageView.isSquashed">
<div class="o_Message_authorAvatarContainer o_Message_sidebarItem">
<img class="o_Message_authorAvatar rounded-circle" t-att-class="{ o_Message_authorRedirect: hasAuthorOpenChat, o_redirect: hasAuthorOpenChat }" t-att-src="messageView.message.avatarUrl" t-on-click="_onClickAuthorAvatar" t-att-title="hasAuthorOpenChat ? OPEN_CHAT : ''" alt="Avatar"/>
<img class="o_Message_authorAvatar rounded-circle" t-att-class="{ o_Message_authorRedirect: messageView.hasAuthorOpenChat, o_redirect: messageView.hasAuthorOpenChat }" t-att-src="messageView.message.avatarUrl" t-on-click="_onClickAuthorAvatar" t-att-title="messageView.hasAuthorOpenChat ? OPEN_CHAT : ''" alt="Avatar"/>
<t t-if="messageView.message.author and messageView.message.author.im_status">
<PartnerImStatusIcon
className="'o_Message_partnerImStatusIcon'"
@@ -37,7 +37,7 @@
'o-message-selected': isSelected,
'o_Message_partnerImStatusIcon-mobile': messaging.device.isMobile,
}"
hasOpenChat="hasAuthorOpenChat"
hasOpenChat="messageView.hasAuthorOpenChat"
partnerLocalId="messageView.message.author.localId"
/>
</t>
@@ -117,6 +117,26 @@ registerModel({
}
return clear();
},
/**
* @private
* @returns {boolean}
*/
_computeHasAuthorOpenChat() {
if (this.messaging.currentGuest) {
return false;
}
if (!this.message.author) {
return false;
}
if (
this.threadView &&
this.threadView.thread &&
this.threadView.thread.correspondent === this.message.author
) {
return false;
}
return true;
},
/**
* @private
* @returns {FieldCommand}
@@ -183,6 +203,12 @@ registerModel({
compute: '_computeExtraClass',
default: '',
}),
/**
* Determines whether author open chat feature is enabled on message.
*/
hasAuthorOpenChat: attr({
compute: '_computeHasAuthorOpenChat',
}),
/**
* id of the current timeout that will reset isHighlighted to false.
*/