From ec8c505bc1c9ec21939e9ffef53a9cc6f63f30c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Wed, 4 Jul 2018 14:40:59 +0200 Subject: [PATCH] [IMP] mail: abstract thread in thread template With this commit, the template for thread uses a {mail.model.AbstractThread} object, instead of a list of {mail.model.AbstractMessage[]}. --- addons/mail/static/src/js/discuss.js | 1 - .../js/models/messages/abstract_message.js | 8 ------- addons/mail/static/src/js/thread_widget.js | 21 +++++++++++----- addons/mail/static/src/xml/thread.xml | 24 +++++++++++-------- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/addons/mail/static/src/js/discuss.js b/addons/mail/static/src/js/discuss.js index 84faa908f3e..4b6bd2efacc 100644 --- a/addons/mail/static/src/js/discuss.js +++ b/addons/mail/static/src/js/discuss.js @@ -411,7 +411,6 @@ var Discuss = AbstractAction.extend(ControlPanelMixin, { } } return { - threadID: this._thread.getID(), displayLoadMore: !this._thread.isAllHistoryLoaded(this.domain), displayMarkAsRead: this._thread.getID() === 'mailbox_inbox', messagesSeparatorPosition: this.messagesSeparatorPosition, diff --git a/addons/mail/static/src/js/models/messages/abstract_message.js b/addons/mail/static/src/js/models/messages/abstract_message.js index 4cdb2273008..6c5f247386f 100644 --- a/addons/mail/static/src/js/models/messages/abstract_message.js +++ b/addons/mail/static/src/js/models/messages/abstract_message.js @@ -56,14 +56,6 @@ var AbstractMessage = Class.extend({ // Public //-------------------------------------------------------------------------- - /** - * Set whether the message should display the author or not - * - * @param {boolean} bool if set, display the author of this message - */ - displayAuthor: function (bool) { - this._displayAuthor = bool; - }, /** * Get the list of files attached to this message. * Note that attachments are stored with server-format diff --git a/addons/mail/static/src/js/thread_widget.js b/addons/mail/static/src/js/thread_widget.js index 7d4833e81cd..78efdcde707 100644 --- a/addons/mail/static/src/js/thread_widget.js +++ b/addons/mail/static/src/js/thread_widget.js @@ -20,7 +20,9 @@ var READ_MORE = _t("read more"); var READ_LESS = _t("read less"); /** - * This is a generic widget to render a chat thread + * This is a generic widget to render a thread. + * Any thread that extends mail.model.AbstractThread can be used with this + * widget. */ var ThreadWidget = Widget.extend({ className: 'o_mail_thread', @@ -89,6 +91,7 @@ var ThreadWidget = Widget.extend({ * @param {mail.model.AbstractMessage[]} messages list of messages of the * thread, ordered by increasing IDs (a higher ID means a more recent * message). + * @param {} * @param {Object} [options] * @param {integer} [options.displayOrder=ORDER.ASC] order of displaying * messages in the thread: @@ -98,11 +101,11 @@ var ThreadWidget = Widget.extend({ * @param {boolean} [options.isCreateMode] * @param {boolean} [options.squashCloseMessages] */ - render: function (messages, options) { + render: function (thread, options) { var self = this; // copy so that reverse do not alter order in the thread object - messages = _.clone(messages); + var messages = _.clone(thread.getMessages()); var modeOptions = options.isCreateMode ? this._disabledOptions : this._enabledOptions; @@ -119,6 +122,10 @@ var ThreadWidget = Widget.extend({ selectedMessageID: this._selectedMessageID, }); + // dict where key is message ID, and value is whether it should hide + // the author of message or not visually + var hideAuthorMessages = {}; + // Hide avatar and info of a message if that message and the previous // one are both comments wrote by the same author at the same minute // and in the same document (users can now post message in documents @@ -147,14 +154,16 @@ var ThreadWidget = Widget.extend({ ) ) ) { - message.displayAuthor(true); + hideAuthorMessages[message.getID()] = false; } else { - message.displayAuthor(!options.squashCloseMessages); + hideAuthorMessages[message.getID()] = options.squashCloseMessages; } prevMessage = message; }); this.$el.html(QWeb.render('mail.widget.Thread', { - messages: messages, + thread: thread, + hideAuthorMessages: hideAuthorMessages, + // messages: messages, options: options, ORDER: ORDER, dateFormat: time.getLangDatetimeFormat(), diff --git a/addons/mail/static/src/xml/thread.xml b/addons/mail/static/src/xml/thread.xml index 9917c1ba653..6bd704fd784 100644 --- a/addons/mail/static/src/xml/thread.xml +++ b/addons/mail/static/src/xml/thread.xml @@ -2,7 +2,10 @@ - + + - + -
+
No matches found
No message matches your search. Try to change your search filters.
@@ -116,32 +120,32 @@
- +
Congratulations, your inbox is empty
New messages appear here.
- +
No starred message
You can mark any message as 'starred', and it shows up in this mailbox.
- +
You have no message to moderate
Pending moderation messages appear here.
+