summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorXavier Dubuc <xdu@odoo.com>2020-10-09 13:50:45 +0000
committerXavier Dubuc <xdu@odoo.com>2020-10-29 11:45:42 +0000
commitecb56a6893dd7b76402c2262fb93f8dea079fde0 (patch)
tree1dd18589fbdbbb1efbba2a300fddaaae5fb49385 /addons
parent1525dc7e4481cf9e24e6c5fff9a73df874670c97 (diff)
[FIX] mail: fix handling of lastVisibleMessage in channel seen condition
also fix a problem with composer.hasFocus field not always correctly updated (e.g. when switching from a channel to another in discuss) task-2278915 closes odoo/odoo#60079 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/mail/static/src/components/composer/composer.xml1
-rw-r--r--addons/mail/static/src/components/composer_text_input/composer_text_input.js2
-rw-r--r--addons/mail/static/src/components/discuss/tests/discuss_tests.js47
-rw-r--r--addons/mail/static/src/models/composer/composer.js15
-rw-r--r--addons/mail/static/src/models/thread_view/thread_view.js6
5 files changed, 69 insertions, 2 deletions
diff --git a/addons/mail/static/src/components/composer/composer.xml b/addons/mail/static/src/components/composer/composer.xml
index ddd3368c21a..c85b5802863 100644
--- a/addons/mail/static/src/components/composer/composer.xml
+++ b/addons/mail/static/src/components/composer/composer.xml
@@ -83,6 +83,7 @@
t-on-o-composer-suggestion-clicked="_onComposerSuggestionClicked"
t-on-o-composer-text-input-send-shortcut="_onComposerTextInputSendShortcut"
t-on-paste="_onPasteTextInput"
+ t-key="composer.localId"
t-ref="textInput"
/>
<div class="o_Composer_buttons" t-att-class="{ 'o-composer-is-compact': props.isCompact, 'o-mobile': env.messaging.device.isMobile }">
diff --git a/addons/mail/static/src/components/composer_text_input/composer_text_input.js b/addons/mail/static/src/components/composer_text_input/composer_text_input.js
index 068bdd303d4..9921b2912ae 100644
--- a/addons/mail/static/src/components/composer_text_input/composer_text_input.js
+++ b/addons/mail/static/src/components/composer_text_input/composer_text_input.js
@@ -179,7 +179,7 @@ class ComposerTextInput extends Component {
* @private
*/
_onFocusinTextarea() {
- this.composer.update({ hasFocus: true });
+ this.composer.focus();
}
/**
diff --git a/addons/mail/static/src/components/discuss/tests/discuss_tests.js b/addons/mail/static/src/components/discuss/tests/discuss_tests.js
index 989bb75235e..77f7e875e42 100644
--- a/addons/mail/static/src/components/discuss/tests/discuss_tests.js
+++ b/addons/mail/static/src/components/discuss/tests/discuss_tests.js
@@ -4206,6 +4206,53 @@ QUnit.test('auto-focus composer on opening thread', async function (assert) {
);
});
+QUnit.test('mark channel as seen if last message is visible when switching channels when the previous channel had a more recent last message than the current channel', async function (assert) {
+ assert.expect(1);
+
+ this.data['mail.channel'].records.push(
+ { id: 10, message_unread_counter: 1, name: 'Bla' },
+ { id: 11, message_unread_counter: 1, name: 'Blu' },
+ );
+ this.data['mail.message'].records.push({
+ body: 'oldest message',
+ channel_ids: [10],
+ id: 10,
+ }, {
+ body: 'newest message',
+ channel_ids: [11],
+ id: 11,
+ });
+ await this.start({
+ discuss: {
+ context: {
+ active_id: 'mail.channel_11',
+ },
+ },
+ });
+ await afterNextRender(() => {
+ document.querySelector(`
+ .o_DiscussSidebar_item[data-thread-local-id="${
+ this.env.models['mail.thread'].findFromIdentifyingData({
+ id: 10,
+ model: 'mail.channel',
+ }).localId
+ }"]
+ `).click();
+ });
+ assert.doesNotHaveClass(
+ document.querySelector(`
+ .o_DiscussSidebar_item[data-thread-local-id="${
+ this.env.models['mail.thread'].findFromIdentifyingData({
+ id: 10,
+ model: 'mail.channel',
+ }).localId
+ }"]
+ `),
+ 'o-unread',
+ "sidebar item of channel ID 10 should no longer be unread"
+ );
+});
+
});
});
});
diff --git a/addons/mail/static/src/models/composer/composer.js b/addons/mail/static/src/models/composer/composer.js
index 25052fd1b38..0a1d817466e 100644
--- a/addons/mail/static/src/models/composer/composer.js
+++ b/addons/mail/static/src/models/composer/composer.js
@@ -103,6 +103,21 @@ function factory(dependencies) {
}
/**
+ * Focus this composer and remove focus from all others.
+ * Focus is a global concern, it makes no sense to have multiple composers focused at the
+ * same time.
+ */
+ focus() {
+ const allComposers = this.env.models['mail.composer'].all();
+ for (const otherComposer of allComposers) {
+ if (otherComposer !== this && otherComposer.hasFocus) {
+ otherComposer.update({ hasFocus: false });
+ }
+ }
+ this.update({ hasFocus: true });
+ }
+
+ /**
* Inserts text content in text input based on selection.
*
* @param {string} content
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 6e875133a4b..895732f8872 100644
--- a/addons/mail/static/src/models/thread_view/thread_view.js
+++ b/addons/mail/static/src/models/thread_view/thread_view.js
@@ -136,6 +136,7 @@ function factory(dependencies) {
if (this.threadCache) {
this.threadCache.update({ isCacheRefreshRequested: true });
}
+ this.update({ lastVisibleMessage: [['unlink']] });
}
/**
@@ -225,12 +226,15 @@ function factory(dependencies) {
* hint `message-received`.
*/
hasAutoScrollOnMessageReceived: attr(),
+ /**
+ * Last message in the context of the currently displayed thread cache.
+ */
lastMessage: many2one('mail.message', {
related: 'thread.lastMessage',
}),
/**
* Most recent message in this ThreadView that has been shown to the
- * current partner.
+ * current partner in the currently displayed thread cache.
*/
lastVisibleMessage: many2one('mail.message'),
messages: many2many('mail.message', {