From f7fa3b7677ae1271b6e67d312b75f5eda5fce8eb Mon Sep 17 00:00:00 2001 From: Romain Estievenart Date: Tue, 6 Aug 2019 06:32:02 +0000 Subject: [PATCH] [REF] mail: MessagingMenu: extract "mark as read" code to dedicated method This allow us to reuse this logic in enterprise when you swipe. Note that we could have directly called the handler but the name wasn't appropriate. So we preferred to extract some code in a well named function. Task ID : 1895453 --- .../src/js/systray/systray_messaging_menu.js | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/addons/mail/static/src/js/systray/systray_messaging_menu.js b/addons/mail/static/src/js/systray/systray_messaging_menu.js index f4c4eb48f39..9a9b21fe953 100644 --- a/addons/mail/static/src/js/systray/systray_messaging_menu.js +++ b/addons/mail/static/src/js/systray/systray_messaging_menu.js @@ -126,6 +126,34 @@ var MessagingMenu = Widget.extend({ _isShown: function () { return this.$el.hasClass('show'); }, + /** + * Process Preview Mark As Read + * + * @private + * @param {Element} $preview + */ + _markAsRead: function ($preview) { + var previewID = $preview.data('preview-id'); + if (previewID === 'mailbox_inbox') { + var messageIDs = [].concat($preview.data('message-ids')); + this.call('mail_service', 'markMessagesAsRead', messageIDs); + } else if (previewID === 'mail_failure') { + var documentModel = $preview.data('document-model'); + var unreadCounter = $preview.data('unread-counter'); + this.do_action('mail.mail_resend_cancel_action', { + additional_context: { + default_model: documentModel, + unread_counter: unreadCounter + } + }); + } else { + // this is mark as read on a thread + var thread = this.call('mail_service', 'getThread', previewID); + if (thread) { + thread.markAsRead(); + } + } + }, /** * Open discuss * @@ -315,28 +343,8 @@ var MessagingMenu = Widget.extend({ */ _onClickPreviewMarkAsRead: function (ev) { ev.stopPropagation(); - var thread; var $preview = $(ev.currentTarget).closest('.o_mail_preview'); - var previewID = $preview.data('preview-id'); - if (previewID === 'mailbox_inbox') { - var messageIDs = [].concat($preview.data('message-ids')); - this.call('mail_service', 'markMessagesAsRead', messageIDs); - } else if (previewID === 'mail_failure') { - var documentModel = $preview.data('document-model'); - var unreadCounter = $preview.data('unread-counter'); - this.do_action('mail.mail_resend_cancel_action', { - additional_context: { - default_model: documentModel, - unread_counter: unreadCounter - } - }); - } else { - // this is mark as read on a thread - thread = this.call('mail_service', 'getThread', previewID); - if (thread) { - thread.markAsRead(); - } - } + this._markAsRead($preview); }, });