summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/widgets
diff options
context:
space:
mode:
authorXavier Dubuc <xdu@odoo.com>2020-09-03 16:24:19 +0000
committerSébastien Theys <seb@odoo.com>2020-09-04 14:59:01 +0000
commit8d3413ff647de8d98c6858062dd07dde4160af95 (patch)
tree3dc134e83c874d5c7f7bf739f13a88ab986ddb1b /addons/mail/static/src/widgets
parenta5ab687be4e7890262ce9429e18dd011021513d5 (diff)
[FIX] mail, sms, snailmail: prevent message_fetch for hidden threads
Automatically load messages from a thread cache only if the thread cache is used in at least one thread view. Ensure thread viewer don't keep thread view records alive when they are not displayed. This change is particularly important for performance, to avoid spamming RPC at init if many threads are opened in chat windows. task-2310623 closes odoo/odoo#57061 X-original-commit: dd6981c7812134e0588f80a157eaba45512cd68e Related: odoo/enterprise#12936 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail/static/src/widgets')
-rw-r--r--addons/mail/static/src/widgets/discuss/discuss.js12
-rw-r--r--addons/mail/static/src/widgets/form_renderer/form_renderer.js2
-rw-r--r--addons/mail/static/src/widgets/form_renderer/form_renderer_tests.js12
3 files changed, 21 insertions, 5 deletions
diff --git a/addons/mail/static/src/widgets/discuss/discuss.js b/addons/mail/static/src/widgets/discuss/discuss.js
index bf389ee69bc..53ed2f73b00 100644
--- a/addons/mail/static/src/widgets/discuss/discuss.js
+++ b/addons/mail/static/src/widgets/discuss/discuss.js
@@ -186,6 +186,7 @@ const DiscussWidget = AbstractAction.extend({
}
// Mark All Read
if (
+ this.discuss.threadView &&
this.discuss.thread &&
this.discuss.thread === this.env.messaging.inbox
) {
@@ -200,6 +201,7 @@ const DiscussWidget = AbstractAction.extend({
}
// Unstar All
if (
+ this.discuss.threadView &&
this.discuss.thread &&
this.discuss.thread === this.env.messaging.starred
) {
@@ -243,8 +245,11 @@ const DiscussWidget = AbstractAction.extend({
const $unselectAll = this.$buttons.find('.o_widget_Discuss_controlPanelButtonUnselectAll');
if (
- this.discuss.threadView.checkedMessages.length > 0 ||
- this.discuss.threadView.uncheckedMessages.length > 0
+ this.discuss.threadView &&
+ (
+ this.discuss.threadView.checkedMessages.length > 0 ||
+ this.discuss.threadView.uncheckedMessages.length > 0
+ )
) {
$selectAll.removeClass('o_hidden');
$selectAll.toggleClass('disabled', this.discuss.threadView.uncheckedMessages.length === 0);
@@ -260,6 +265,7 @@ const DiscussWidget = AbstractAction.extend({
// Moderation Actions
const $moderationButtons = this.$buttons.find('.o_widget_Discuss_controlPanelButtonModeration');
if (
+ this.discuss.threadView &&
this.discuss.threadView.checkedMessages.length > 0 &&
this.discuss.threadView.checkedMessages.filter(
message => !message.isModeratedByCurrentPartner
@@ -371,7 +377,7 @@ const DiscussWidget = AbstractAction.extend({
* @param {Object} searchQuery
*/
_onSearch: function (searchQuery) {
- this.discuss.threadView.update({
+ this.discuss.update({
stringifiedDomain: JSON.stringify(searchQuery.domain),
});
},
diff --git a/addons/mail/static/src/widgets/form_renderer/form_renderer.js b/addons/mail/static/src/widgets/form_renderer/form_renderer.js
index 266d8c60f38..375f036addd 100644
--- a/addons/mail/static/src/widgets/form_renderer/form_renderer.js
+++ b/addons/mail/static/src/widgets/form_renderer/form_renderer.js
@@ -102,7 +102,7 @@ FormRenderer.include({
followerIds,
hasActivities: this.chatterFields.hasActivityIds,
hasFollowers: this.chatterFields.hasMessageFollowerIds,
- hasThread: this.chatterFields.hasMessageIds,
+ hasMessageList: this.chatterFields.hasMessageIds,
isAttachmentBoxVisible: this.chatterFields.isAttachmentBoxVisible,
messageIds,
threadAttachmentCount,
diff --git a/addons/mail/static/src/widgets/form_renderer/form_renderer_tests.js b/addons/mail/static/src/widgets/form_renderer/form_renderer_tests.js
index 235c95fb19d..cffd73b252f 100644
--- a/addons/mail/static/src/widgets/form_renderer/form_renderer_tests.js
+++ b/addons/mail/static/src/widgets/form_renderer/form_renderer_tests.js
@@ -468,9 +468,17 @@ QUnit.test('chatter updating', async function (assert) {
{ display_name: "first partner", id: 11 },
{ display_name: "second partner", id: 12 }
);
+ const messageFetchChannelDef = makeDeferred();
await this.createView({
data: this.data,
hasView: true,
+ async mockRPC(route, args) {
+ const res = await this._super(...arguments);
+ if (route.includes('message_fetch')) {
+ messageFetchChannelDef.resolve();
+ }
+ return res;
+ },
// View params
View: FormView,
model: 'res.partner',
@@ -501,8 +509,10 @@ QUnit.test('chatter updating', async function (assert) {
"there should be no message"
);
- await afterNextRender(() => {
+ await afterNextRender(async () => {
document.querySelector('.o_pager_next').click();
+ // wait until messages are fetched, ignore other renders that are too early
+ await messageFetchChannelDef;
});
assert.containsOnce(
document.body,