summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/models
diff options
context:
space:
mode:
Diffstat (limited to 'addons/mail/static/src/models')
-rw-r--r--addons/mail/static/src/models/composer/composer.js3
-rw-r--r--addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js23
-rw-r--r--addons/mail/static/src/models/thread_view/thread_view.js14
3 files changed, 34 insertions, 6 deletions
diff --git a/addons/mail/static/src/models/composer/composer.js b/addons/mail/static/src/models/composer/composer.js
index e2a7ab4fb83..7ea2e5fbc60 100644
--- a/addons/mail/static/src/models/composer/composer.js
+++ b/addons/mail/static/src/models/composer/composer.js
@@ -291,7 +291,8 @@ function factory(dependencies) {
thread.loadNewMessages();
}
for (const threadView of this.thread.threadViews) {
- threadView.addComponentHint('current-partner-just-posted-message', { messageId });
+ // Reset auto scroll to be able to see the newly posted message.
+ threadView.update({ hasAutoScrollOnMessageReceived: true });
}
thread.refreshFollowers();
thread.fetchAndUpdateSuggestedRecipients();
diff --git a/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js b/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js
index ede9245602d..6eb06ee01af 100644
--- a/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js
+++ b/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js
@@ -207,6 +207,7 @@ function factory(dependencies) {
}
const message = this.env.models['mail.message'].insert(convertedData);
+ this._notifyThreadViewsMessageReceived(message);
// If the message was already known: nothing else should be done,
// except if it was pending moderation by the current partner, then
@@ -299,7 +300,7 @@ function factory(dependencies) {
// knowledge of the channel
return;
}
- const lastMessage = this.env.models['mail.message'].insert({id: last_message_id});
+ const lastMessage = this.env.models['mail.message'].insert({ id: last_message_id });
// restrict computation of seen indicator for "non-channel" channels
// for performance reasons
const shouldComputeSeenIndicators = channel.channel_type !== 'channel';
@@ -631,7 +632,7 @@ function factory(dependencies) {
starredMailbox.update({
counter: starred
? starredMailbox.counter + 1
- : starredMailbox.counter -1,
+ : starredMailbox.counter - 1,
});
}
}
@@ -648,11 +649,12 @@ function factory(dependencies) {
const convertedData = this.env.models['mail.message'].convertData(data);
const messageIds = this.env.models['mail.message'].all().map(message => message.id);
const partnerRoot = this.env.messaging.partnerRoot;
- this.env.models['mail.message'].create(Object.assign(convertedData, {
+ const message = this.env.models['mail.message'].create(Object.assign(convertedData, {
author: [['link', partnerRoot]],
id: (messageIds ? Math.max(...messageIds) : 0) + 0.01,
isTransient: true,
}));
+ this._notifyThreadViewsMessageReceived(message);
}
/**
@@ -756,6 +758,21 @@ function factory(dependencies) {
});
}
+ /**
+ * Notifies threadViews about the given message being just received.
+ * This can allow them adjust their scroll position if applicable.
+ *
+ * @private
+ * @param {mail.message}
+ */
+ _notifyThreadViewsMessageReceived(message) {
+ for (const thread of message.threads) {
+ for (const threadView of thread.threadViews) {
+ threadView.addComponentHint('message-received', { message });
+ }
+ }
+ }
+
}
MessagingNotificationHandler.fields = {
diff --git a/addons/mail/static/src/models/thread_view/thread_view.js b/addons/mail/static/src/models/thread_view/thread_view.js
index f2c64dabe2c..ee53e616b1c 100644
--- a/addons/mail/static/src/models/thread_view/thread_view.js
+++ b/addons/mail/static/src/models/thread_view/thread_view.js
@@ -47,8 +47,8 @@ function factory(dependencies) {
markComponentHintProcessed(hint) {
let filterFun;
switch (hint.type) {
- case 'current-partner-just-posted-message':
- filterFun = h => h.type !== hint.type && h.messageId !== hint.data.messageId;
+ case 'message-received':
+ filterFun = h => h.type !== hint.type && h.message !== hint.data.message;
break;
default:
filterFun = h => h.type !== hint.type;
@@ -57,6 +57,10 @@ function factory(dependencies) {
this.update({
componentHintList: this.componentHintList.filter(filterFun),
});
+ this.env.messagingBus.trigger('o-thread-view-hint-processed', {
+ hint,
+ threadViewer: this.threadViewer,
+ });
}
/**
@@ -197,6 +201,12 @@ function factory(dependencies) {
isPreparingLoading: attr({
default: false,
}),
+ /**
+ * Determines whether `this` should automatically scroll on receiving
+ * a new message. Detection of new message is done through the component
+ * hint `message-received`.
+ */
+ hasAutoScrollOnMessageReceived: attr(),
lastMessage: many2one('mail.message', {
related: 'thread.lastMessage',
}),