diff options
| author | Xavier Dubuc <xdu@odoo.com> | 2020-06-11 15:19:26 +0000 |
|---|---|---|
| committer | Xavier Dubuc <xdu@odoo.com> | 2020-06-16 15:52:34 +0000 |
| commit | 4ca549253be2c099294f05d8ba57384e1b7bc0d6 (patch) | |
| tree | ef439fd6acc1b61c8fa44dc0e3d9b7e8351e8a50 /addons/mail/static/src/models/thread_viewer/thread_viewer.js | |
| parent | 57a32316afdd82843d0fe2381a7db5846affdb2d (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/thread_viewer/thread_viewer.js')
| -rw-r--r-- | addons/mail/static/src/models/thread_viewer/thread_viewer.js | 56 |
1 files changed, 55 insertions, 1 deletions
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', }), |
