summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/models
diff options
context:
space:
mode:
authorXavier Dubuc <xdu@odoo.com>2020-06-11 15:19:26 +0000
committerXavier Dubuc <xdu@odoo.com>2020-06-16 15:52:34 +0000
commit4ca549253be2c099294f05d8ba57384e1b7bc0d6 (patch)
treeef439fd6acc1b61c8fa44dc0e3d9b7e8351e8a50 /addons/mail/static/src/models
parent57a32316afdd82843d0fe2381a7db5846affdb2d (diff)
[FIX] mail: mark message as seen only when thread composer is focused
task-2272510 closes odoo/odoo#53088 X-original-commit: edf356c2022b3039e53e82a092fc64533f59df27 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
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/thread/thread.js18
-rw-r--r--addons/mail/static/src/models/thread_viewer/thread_viewer.js56
3 files changed, 75 insertions, 2 deletions
diff --git a/addons/mail/static/src/models/composer/composer.js b/addons/mail/static/src/models/composer/composer.js
index 343e0d372c0..fa6e2698eb0 100644
--- a/addons/mail/static/src/models/composer/composer.js
+++ b/addons/mail/static/src/models/composer/composer.js
@@ -554,6 +554,9 @@ function factory(dependencies) {
'mainSuggestedPartners',
],
}),
+ hasFocus: attr({
+ default: false,
+ }),
hasSuggestedPartners: attr({
compute: '_computeHasSuggestedPartners',
dependencies: [
diff --git a/addons/mail/static/src/models/thread/thread.js b/addons/mail/static/src/models/thread/thread.js
index 16f52ab861f..e1fd74a5d77 100644
--- a/addons/mail/static/src/models/thread/thread.js
+++ b/addons/mail/static/src/models/thread/thread.js
@@ -11,6 +11,23 @@ function factory(dependencies) {
class Thread extends dependencies['mail.model'] {
/**
+ * FIXME With this, whenever client is aware of new thread, this will
+ * (almost) always focus its composer when displayed. This shouldn't be
+ * the case, instead auto-focus of composer is flow-specific.
+ * See task-2277537
+ *
+ * @override
+ */
+ static create(data) {
+ if (!data.composer) {
+ data.composer = [['create', {
+ isDoFocus: true,
+ }]];
+ }
+ return super.create(data);
+ }
+
+ /**
* @override
*/
init(...args) {
@@ -1140,7 +1157,6 @@ function factory(dependencies) {
dependencies: ['viewersChatWindow'],
}),
composer: one2one('mail.composer', {
- autocreate: true,
inverse: 'thread',
isCausal: true,
}),
diff --git a/addons/mail/static/src/models/thread_viewer/thread_viewer.js b/addons/mail/static/src/models/thread_viewer/thread_viewer.js
index 4da88fd9513..834c07d878a 100644
--- a/addons/mail/static/src/models/thread_viewer/thread_viewer.js
+++ b/addons/mail/static/src/models/thread_viewer/thread_viewer.js
@@ -68,6 +68,15 @@ function factory(dependencies) {
}
/**
+ * @param {mail.message} message
+ */
+ handleVisibleMessage(message) {
+ if (!this.lastVisibleMessage || this.lastVisibleMessage.id < message.id) {
+ this.update({ lastVisibleMessage: [['replace', message]] });
+ }
+ }
+
+ /**
* @param {string} scrollTop
*/
saveThreadCacheScrollPositionsAsInitial(scrollTop) {
@@ -97,6 +106,24 @@ function factory(dependencies) {
}
/**
+ * Not a real field, used to trigger `thread.markAsSeen` when one of
+ * the dependencies changes.
+ *
+ * @private
+ * @returns {boolean}
+ */
+ _computeThreadShouldBeSetAsSeen() {
+ // FIXME condition should not be on "composer is focused" but "thread viewer is active"
+ // See task-2277543
+ const lastMessageIsVisible = this.lastVisibleMessage &&
+ this.lastVisibleMessage === this.lastMessage;
+ if (lastMessageIsVisible && this.hasComposerFocus && this.thread) {
+ this.thread.markAsSeen();
+ }
+ return true;
+ }
+
+ /**
* @private
* @returns {integer|undefined}
*/
@@ -171,7 +198,7 @@ function factory(dependencies) {
}
if (
- this.thread && this.threadCache.isLoading &&
+ this.thread && this.threadCache && this.threadCache.isLoading &&
!this.isShowingLoading && !this._isPreparingLoading
) {
this._prepareLoading();
@@ -218,6 +245,20 @@ function factory(dependencies) {
componentHintList: attr({
default: [],
}),
+ composer: many2one('mail.composer', {
+ related: 'thread.composer',
+ }),
+ hasComposerFocus: attr({
+ related: 'composer.hasFocus',
+ }),
+ lastMessage: many2one('mail.message', {
+ related: 'threadCache.lastMessage',
+ }),
+ /**
+ * Most recent message in the current thread viewer that has been shown
+ * to the current partner.
+ */
+ lastVisibleMessage: many2one('mail.message'),
messages: many2many('mail.message', {
related: 'threadCache.messages',
}),
@@ -255,6 +296,19 @@ function factory(dependencies) {
threadCaches: many2many('mail.thread_cache', {
related: 'thread.caches',
}),
+ /**
+ * Not a real field, used to trigger `thread.markAsSeen` when one of
+ * the dependencies changes.
+ */
+ threadShouldBeSetAsSeen: attr({
+ compute: '_computeThreadShouldBeSetAsSeen',
+ dependencies: [
+ 'hasComposerFocus',
+ 'lastMessage',
+ 'lastVisibleMessage',
+ 'threadCache',
+ ],
+ }),
uncheckedMessages: many2many('mail.message', {
related: 'threadCache.uncheckedMessages',
}),