summaryrefslogtreecommitdiff
path: root/addons/mail/static/src
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2015-11-26 10:48:29 +0100
committerGéry Debongnie <ged@odoo.com>2015-11-26 14:27:11 +0100
commit7137891a8a5d024a7f36a5af1d3a3c2686a9a96a (patch)
tree4ac17ad2c8cdaee63a92ba3dc73b44cc422ab483 /addons/mail/static/src
parentbef0da3a7aff74fecce7b418164257ad0cd37c4d (diff)
[FIX] mail, im_livechat: correctly displayed message date
Messages are required to be displayed in a smarter way: relative to the current date, if it's a recent message, or absolute if not. This commits rework most of the date processing code to comply with these requirements. Messages were preprocessed each time a thread is rendered, which is stupid. It should be preprocessed only when the message is created. This was a small problem because livechat does not use the chat manager, so a simplified version of the preprocessing had to be done.
Diffstat (limited to 'addons/mail/static/src')
-rw-r--r--addons/mail/static/src/js/chat_manager.js26
-rw-r--r--addons/mail/static/src/js/thread.js36
-rw-r--r--addons/mail/static/src/xml/thread.xml14
3 files changed, 43 insertions, 33 deletions
diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js
index d638ddaf45f..331fd6772a5 100644
--- a/addons/mail/static/src/js/chat_manager.js
+++ b/addons/mail/static/src/js/chat_manager.js
@@ -6,6 +6,7 @@ var core = require('web.core');
var data = require('web.data');
var Model = require('web.Model');
var session = require('web.session');
+var time = require('web.time');
var web_client = require('web.web_client');
var _t = core._t;
@@ -80,7 +81,7 @@ function make_message (data) {
author_id: data.author_id,
body_short: data.body_short || "",
body: data.body || "",
- date: data.date,
+ date: moment(time.str_to_datetime(data.date)),
message_type: data.message_type,
subtype_description: data.subtype_description,
is_note: data.is_note,
@@ -136,6 +137,29 @@ function make_message (data) {
msg.origin_name = channel.name;
}
}
+
+ // Compute displayed author name or email
+ if ((!msg.author_id || !msg.author_id[0]) && msg.email_from) {
+ msg.mailto = msg.email_from;
+ } else {
+ msg.displayed_author = msg.author_id && msg.author_id[1] ||
+ msg.email_from || _t('Anonymous');
+ }
+
+ // Compute the avatar_url
+ if (msg.author_id && msg.author_id[0]) {
+ msg.avatar_src = "/web/image/res.partner/" + msg.author_id[0] + "/image_small";
+ } else if (msg.message_type === 'email') {
+ msg.avatar_src = "/mail/static/src/img/email_icon.png";
+ } else {
+ msg.avatar_src = "/mail/static/src/img/smiley/avatar.jpg";
+ }
+
+ // Compute url of attachments
+ _.each(msg.attachment_ids, function(a) {
+ a.url = '/web/content/' + a.id + '?download=true';
+ });
+
return msg;
}
diff --git a/addons/mail/static/src/js/thread.js b/addons/mail/static/src/js/thread.js
index 6fd5838aa48..1f2404dfe47 100644
--- a/addons/mail/static/src/js/thread.js
+++ b/addons/mail/static/src/js/thread.js
@@ -2,7 +2,6 @@ odoo.define('mail.ChatThread', function (require) {
"use strict";
var core = require('web.core');
-var time = require('web.time');
var Widget = require('web.Widget');
var QWeb = core.qweb;
@@ -49,7 +48,6 @@ var Thread = Widget.extend({
display_order: ORDER.ASC,
display_needactions: true,
display_stars: true,
- default_username: _t('Anonymous'),
display_document_link: true,
display_avatar: true,
squash_close_messages: true,
@@ -67,7 +65,7 @@ var Thread = Widget.extend({
// one are both comments wrote by the same author at the same minute
var prev_msg;
_.each(msgs, function (msg) {
- if (!prev_msg || (Math.abs(moment(msg.date).diff(prev_msg.date)) > 60000) ||
+ if (!prev_msg || (Math.abs(msg.date.diff(prev_msg.date)) > 60000) ||
prev_msg.message_type !== 'comment' || msg.message_type !== 'comment' ||
(prev_msg.author_id[0] !== msg.author_id[0])) {
msg.display_author = true;
@@ -113,31 +111,19 @@ var Thread = Widget.extend({
var msg = _.extend({}, message);
// Set the date in the browser timezone
- msg.date = moment(time.str_to_datetime(msg.date)).format('YYYY-MM-DD HH:mm:ss');
-
- // Compute displayed author name or email
- if ((!msg.author_id || !msg.author_id[0]) && msg.email_from) {
- msg.mailto = msg.email_from;
- } else {
- msg.displayed_author = msg.author_id && msg.author_id[1] ||
- msg.email_from ||
- this.options.default_username;
- }
-
- // Compute the avatar_url
- if (msg.author_id && msg.author_id[0]) {
- msg.avatar_src = "/web/image/res.partner/" + msg.author_id[0] + "/image_small";
- } else if (msg.message_type === 'email') {
- msg.avatar_src = "/mail/static/src/img/email_icon.png";
+ var date = msg.date.format('YYYY-MM-DD');
+
+ if (date === moment().format('YYYY-MM-DD')) {
+ msg.day = _t("Today");
+ msg.hour = msg.date.fromNow();
+ } else if (date === moment().subtract(1, 'days').format('YYYY-MM-DD')) {
+ msg.day = _t("Yesterday");
+ msg.hour = msg.date.format('hh:mm');
} else {
- msg.avatar_src = "/mail/static/src/img/smiley/avatar.jpg";
+ msg.day = msg.date.format('LL');
+ msg.hour = msg.date.format('hh:mm');
}
- // Compute url of attachments
- _.each(msg.attachment_ids, function(a) {
- a.url = '/web/content/' + a.id + '?download=true';
- });
-
return msg;
},
diff --git a/addons/mail/static/src/xml/thread.xml b/addons/mail/static/src/xml/thread.xml
index 394627940cb..70996dd7d47 100644
--- a/addons/mail/static/src/xml/thread.xml
+++ b/addons/mail/static/src/xml/thread.xml
@@ -30,11 +30,11 @@
<t t-if="options.messages_separator_position == 'top'" t-call="mail.MessagesSeparator"/>
<t t-set="current_day" t-value="0"/>
<t t-foreach="messages" t-as="message">
- <div t-if="current_day != message.date.split(' ')[0]" class="o_thread_date_separator">
+ <div t-if="current_day != message.day" class="o_thread_date_separator">
<span class="o_thread_date">
- <t t-esc="moment(message.date, 'YYYY-MM-DD hh:mm:ss').format('LL')"/>
+ <t t-esc="message.day"/>
</span>
- <t t-set="current_day" t-value="message.date.split(' ')[0]"/>
+ <t t-set="current_day" t-value="message.day"/>
</div>
<t t-call="mail.ChatThread.Message"/>
@@ -56,8 +56,8 @@
t-att-src="message.avatar_src"
class="o_thread_message_avatar"/>
</t>
- <span t-if="!message.display_author" t-att-title="moment(message.date, 'YYYY-MM-DD hh:mm:ss').format('LLL')" class="o_thread_message_side_date">
- <t t-esc="moment(message.date, 'YYYY-MM-DD hh:mm:ss').format('hh:mm')"/>
+ <span t-if="!message.display_author" t-att-title="message.date" class="o_thread_message_side_date">
+ <t t-esc="message.date.format('hh:mm')"/>
</span>
<i t-if="!message.display_author &amp;&amp; options.display_stars &amp;&amp; message.message_type != 'notification'"
t-att-class="'fa o_thread_message_star ' + (message.is_starred ? 'fa-star' : 'fa-star-o')"
@@ -83,8 +83,8 @@
<t t-esc="message.displayed_author"/>
</strong>
- <small t-att-title="moment(message.date, 'YYYY-MM-DD hh:mm:ss').format('LLL')">
- - <t t-esc="moment(message.date, 'YYYY-MM-DD hh:mm:ss').format('hh:mm A')"/>
+ <small t-att-title="message.date">
+ - <t t-esc="message.hour"/>
</small>
<t t-if="message.model &amp;&amp; (message.model != 'mail.channel') &amp;&amp; options.display_document_link">
on <a class="o_mail_redirect" href="#" t-att-data-oe-model="message.model" t-att-data-oe-id="message.res_id"><t t-esc="message.record_name"/></a>