[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[]}.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<!--
|
||||
@param {mail.model.AbstractMessage[]} messages
|
||||
@param {mail.model.AbstractThread} thread
|
||||
@param {Object[]} hideAuthorMessages dict where key is message ID and
|
||||
value is boolean. It tells whether the message with this ID should
|
||||
hide the author visually or not.
|
||||
@param {Object} options
|
||||
@param {boolean} [options.displayEmptyThread]
|
||||
@param {boolean} [options.displayLoadMore]
|
||||
@@ -13,17 +16,18 @@
|
||||
@param {integer} ORDER.DESC=-1
|
||||
-->
|
||||
<t t-name="mail.widget.Thread">
|
||||
<t t-if="messages.length">
|
||||
<t t-if="thread.hasMessages()">
|
||||
<t t-set="messages" t-value="thread.getMessages()"/>
|
||||
<t t-if="options.displayLoadMore and options.displayOrder == ORDER.ASC"
|
||||
t-call="mail.widget.Thread.LoadMore"/>
|
||||
<t t-call="mail.widget.Thread.Content"/>
|
||||
<t t-if="options.displayLoadMore and options.displayOrder == ORDER.DESC"
|
||||
t-call="mail.widget.Thread.LoadMore"/>
|
||||
</t>
|
||||
<t t-if="options.displayEmptyThread">
|
||||
<t t-elif="options.displayEmptyThread">
|
||||
<t t-call="mail.widget.Thread.Empty" />
|
||||
</t>
|
||||
<div t-if="options.displayNoMatchFound" class="o_mail_no_content">
|
||||
<div t-elif="options.displayNoMatchFound" class="o_mail_no_content">
|
||||
<div class="o_thread_title">No matches found</div>
|
||||
<div>No message matches your search. Try to change your search filters.</div>
|
||||
</div>
|
||||
@@ -116,32 +120,32 @@
|
||||
<!--
|
||||
When a thread is empty
|
||||
|
||||
@param {Object} options
|
||||
@param {string|integer} options.threadID
|
||||
@param {mail.model.Thread} thread
|
||||
-->
|
||||
<div t-name="mail.widget.Thread.Empty" class="o_mail_no_content">
|
||||
<t t-if="options.threadID === 'mailbox_inbox'">
|
||||
<t t-if="thread.getID() === 'mailbox_inbox'">
|
||||
<div class="o_thread_title">Congratulations, your inbox is empty</div>
|
||||
<div>New messages appear here.</div>
|
||||
</t>
|
||||
<t t-if="options.threadID === 'mailbox_starred'">
|
||||
<t t-if="thread.getID() === 'mailbox_starred'">
|
||||
<div class="o_thread_title">No starred message</div>
|
||||
<div>You can mark any message as 'starred', and it shows up in this mailbox.</div>
|
||||
</t>
|
||||
<t t-if="options.threadID === 'mailbox_moderation'">
|
||||
<t t-if="thread.getID() === 'mailbox_moderation'">
|
||||
<div class="o_thread_title">You have no message to moderate</div>
|
||||
<div>Pending moderation messages appear here.</div>
|
||||
</t>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
@param {mail.model.AbstractMessage[]} messages
|
||||
@param {mail.model.AbstractMessage[]} messages messages ordered by increasing IDs
|
||||
@param {string|integer} [options.messagesSeparatorPosition] 'top' or
|
||||
message ID, the separator is placed just after this message.
|
||||
-->
|
||||
<t t-name="mail.widget.Thread.Content">
|
||||
<t t-if="options.messagesSeparatorPosition == 'top'" t-call="mail.MessagesSeparator"/>
|
||||
<t t-set="current_day" t-value="0"/>
|
||||
<t t-if="options.displayOrder === ORDER.DESC" t-set="messages" t-value="messages.slice().reverse()"/>
|
||||
<t t-foreach="messages" t-as="message">
|
||||
<div t-if="current_day !== message.getDateDay()" class="o_thread_date_separator">
|
||||
<span class="o_thread_date">
|
||||
|
||||
Reference in New Issue
Block a user