From 2542f731c5b06c3b451ecde7992d3bb45adb2c60 Mon Sep 17 00:00:00 2001 From: Priyanka Kakadiya Date: Fri, 29 Jan 2021 11:55:19 +0000 Subject: [FIX] mail: fix keyboard shortcut issue for small screen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Current behavior before PR: When having a small screen, the composer in a chat window has no actual shortcut to send the message. Desired behavior after PR is merged: 'CTRL-Enter' keyboard shortcut will work for small screen size. LINKS: PR https://github.com//pull/65241 Task-2446076 closes odoo/odoo#65241 Signed-off-by: Sébastien Theys (seb) --- .../static/src/models/thread_view/thread_view.js | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'addons/mail/static/src/models/thread_view/thread_view.js') 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 534fd2769a9..a7ccf0c7d4d 100644 --- a/addons/mail/static/src/models/thread_view/thread_view.js +++ b/addons/mail/static/src/models/thread_view/thread_view.js @@ -67,6 +67,33 @@ function factory(dependencies) { // Private //---------------------------------------------------------------------- + /** + * @private + * @returns {mail.messaging} + */ + _computeMessaging() { + return [['link', this.env.messaging]]; + } + + /** + * @private + * @returns {string[]} + */ + _computeTextInputSendShortcuts() { + if (!this.thread) { + return; + } + const isMailingList = this.thread.model === 'mail.channel' && this.thread.mass_mailing; + // Actually in mobile there is a send button, so we need there 'enter' to allow new line. + // Hence, we want to use a different shortcut 'ctrl/meta enter' to send for small screen + // size with a non-mailing channel. + // here send will be done on clicking the button or using the 'ctrl/meta enter' shortcut. + if (this.env.messaging.device.isMobile || isMailingList) { + return ['ctrl-enter', 'meta-enter']; + } + return ['enter']; + } + /** * @private * @returns {integer|undefined} @@ -199,6 +226,18 @@ function factory(dependencies) { composer: many2one('mail.composer', { related: 'thread.composer', }), + /** + * Serves as compute dependency. + */ + device: one2one('mail.device', { + related: 'messaging.device', + }), + /** + * Serves as compute dependency. + */ + deviceIsMobile: attr({ + related: 'device.isMobile', + }), hasComposerFocus: attr({ related: 'composer.hasFocus', }), @@ -255,6 +294,12 @@ function factory(dependencies) { messages: many2many('mail.message', { related: 'threadCache.messages', }), + /** + * Serves as compute dependency. + */ + messaging: many2one('mail.messaging', { + compute: '_computeMessaging', + }), nonEmptyMessages: many2many('mail.message', { related: 'threadCache.nonEmptyMessages', }), @@ -287,6 +332,20 @@ function factory(dependencies) { stringifiedDomain: attr({ related: 'threadViewer.stringifiedDomain', }), + /** + * Determines the keyboard shortcuts that are available to send a message + * from the composer of this thread viewer. + */ + textInputSendShortcuts: attr({ + compute: '_computeTextInputSendShortcuts', + dependencies: [ + 'device', + 'deviceIsMobile', + 'thread', + 'threadMassMailing', + 'threadModel', + ], + }), /** * Determines the `mail.thread` currently displayed by `this`. */ @@ -335,6 +394,18 @@ function factory(dependencies) { default: {}, related: 'threadViewer.threadCacheInitialScrollPositions', }), + /** + * Serves as compute dependency. + */ + threadMassMailing: attr({ + related: 'thread.mass_mailing', + }), + /** + * Serves as compute dependency. + */ + threadModel: attr({ + related: 'thread.model', + }), /** * Not a real field, used to trigger `thread.markAsSeen` when one of * the dependencies changes. -- cgit v1.2.3