diff --git a/addons/mail/static/src/components/channel_preview_view/channel_preview_view.xml b/addons/mail/static/src/components/channel_preview_view/channel_preview_view.xml index 1c898ca68e7..d3d6eae3e71 100644 --- a/addons/mail/static/src/components/channel_preview_view/channel_preview_view.xml +++ b/addons/mail/static/src/components/channel_preview_view/channel_preview_view.xml @@ -46,7 +46,7 @@ - + diff --git a/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview.xml b/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview.xml index 5cfab1dc3ad..db46b9a4c32 100644 --- a/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview.xml +++ b/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview.xml @@ -42,7 +42,7 @@ - + diff --git a/addons/mail/static/src/models/message.js b/addons/mail/static/src/models/message.js index e8fcfed8427..44b4c1f1534 100644 --- a/addons/mail/static/src/models/message.js +++ b/addons/mail/static/src/models/message.js @@ -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(), diff --git a/addons/mail/static/src/models/message_view.js b/addons/mail/static/src/models/message_view.js index 48ff202bd98..736c5c4d613 100644 --- a/addons/mail/static/src/models/message_view.js +++ b/addons/mail/static/src/models/message_view.js @@ -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(); }, }), /** diff --git a/addons/mail/static/src/models/notification_group.js b/addons/mail/static/src/models/notification_group.js index fb189b86c6a..fe936f1de38 100644 --- a/addons/mail/static/src/models/notification_group.js +++ b/addons/mail/static/src/models/notification_group.js @@ -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(); } diff --git a/addons/mail/static/src/models/thread_view.js b/addons/mail/static/src/models/thread_view.js index 4ca001f0257..ad623a5ed40 100644 --- a/addons/mail/static/src/models/thread_view.js +++ b/addons/mail/static/src/models/thread_view.js @@ -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; }