[IMP] mail: remove moment from the convert data and compute it

closes odoo/odoo#103935

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Didier (did)
2022-10-26 12:23:06 +02:00
parent d66569498a
commit 74b30cb480
6 changed files with 26 additions and 15 deletions
@@ -46,7 +46,7 @@
<span class="flex-grow-1"/>
<t t-if="channelPreviewView.thread.lastMessage and channelPreviewView.thread.lastMessage.date">
<small class="o_NotificationListItem_date o_ChannelPreviewView_date flex-shrink-0 text-500" t-att-class="{ 'o-muted': channelPreviewView.channel.localMessageUnreadCounter === 0 }">
<t t-esc="channelPreviewView.thread.lastMessage.date.fromNow()"/>
<t t-esc="channelPreviewView.thread.lastMessage.momentDate.fromNow()"/>
</small>
</t>
</div>
@@ -42,7 +42,7 @@
<span class="flex-grow-1"/>
<t t-if="threadNeedactionPreviewView.thread.lastNeedactionMessageAsOriginThread and threadNeedactionPreviewView.thread.lastNeedactionMessageAsOriginThread.date">
<small class="o_NotificationListItem_date o_ThreadNeedactionPreview_date flex-shrink-0 text-500">
<t t-esc="threadNeedactionPreviewView.thread.lastNeedactionMessageAsOriginThread.date.fromNow()"/>
<t t-esc="threadNeedactionPreviewView.thread.lastNeedactionMessageAsOriginThread.momentDate.fromNow()"/>
</small>
</t>
</div>
+19 -8
View File
@@ -28,7 +28,7 @@ registerModel({
data2.body = data.body;
}
if ('date' in data && data.date) {
data2.date = moment(str_to_datetime(data.date));
data2.date = data.date;
}
if ('email_from' in data) {
data2.email_from = data.email_from;
@@ -345,10 +345,21 @@ registerModel({
return !this.messaging.isCurrentUserGuest && !this.isTemporary && !this.isTransient;
},
}),
date: attr(),
/**
* Determines the date of the message as a moment object.
*/
date: attr(),
momentDate: attr({
compute() {
if (!this.date) {
return clear();
}
if (!moment.isMoment(this.date)) {
return moment(str_to_datetime(this.date));
}
return this.date;
}
}),
/**
* States the date of this message as a string (either a relative period
* in the near past or an actual date for older dates).
@@ -360,7 +371,7 @@ registerModel({
// mainly done to avoid flicker inside the UI.
return this.env._t("Today");
}
const date = this.date.format('YYYY-MM-DD');
const date = this.momentDate.format('YYYY-MM-DD');
if (date === moment().format('YYYY-MM-DD')) {
return this.env._t("Today");
} else if (
@@ -370,7 +381,7 @@ registerModel({
) {
return this.env._t("Yesterday");
}
return this.date.format('LL');
return this.momentDate.format('LL');
},
}),
/**
@@ -378,10 +389,10 @@ registerModel({
*/
datetime: attr({
compute() {
if (!this.date) {
if (!this.momentDate) {
return clear();
}
return this.date.format(getLangDatetimeFormat());
return this.momentDate.format(getLangDatetimeFormat());
},
}),
email_from: attr(),
@@ -705,10 +716,10 @@ registerModel({
recipients: many('Partner'),
shortTime: attr({
compute() {
if (!this.date) {
if (!this.momentDate) {
return clear();
}
return this.date.format('hh:mm');
return this.momentDate.format('hh:mm');
},
}),
subject: attr(),
@@ -380,10 +380,10 @@ registerModel({
return clear();
}
const now = moment(this.clockWatcher.clock.date.getTime());
if (now.diff(this.message.date, 'seconds') < 45) {
if (now.diff(this.message.momentDate, 'seconds') < 45) {
return this.env._t("now");
}
return this.message.date.fromNow();
return this.message.momentDate.fromNow();
},
}),
/**
@@ -72,8 +72,8 @@ registerModel({
*/
compute() {
const dates = this.notifications
.filter(notification => notification.message && notification.message.date)
.map(notification => notification.message.date);
.filter(notification => notification.message && notification.message.momentDate)
.map(notification => notification.message.momentDate);
if (dates.length === 0) {
return clear();
}
+1 -1
View File
@@ -169,7 +169,7 @@ registerModel({
if (!prevMessage.date && message.date) {
return false;
}
if (message.date && prevMessage.date && Math.abs(message.date.diff(prevMessage.date)) > 60000) {
if (message.momentDate && prevMessage.momentDate && Math.abs(message.momentDate.diff(prevMessage.momentDate)) > 60000) {
// more than 1 min. elasped
return false;
}