summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/models/thread_view/thread_view.js
diff options
context:
space:
mode:
authorPriyanka Kakadiya <pka@odoo.com>2021-01-29 11:55:19 +0000
committerPriyanka Kakadiya <pka@odoo.com>2021-03-10 13:30:18 +0000
commit2542f731c5b06c3b451ecde7992d3bb45adb2c60 (patch)
treed590eab9af3504ca9c4932cca13d36070ac3489a /addons/mail/static/src/models/thread_view/thread_view.js
parenta8b43d02066b2299ac2f4b88056c37725e9ce6cd (diff)
[FIX] mail: fix keyboard shortcut issue for small screen
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) <seb@odoo.com>
Diffstat (limited to 'addons/mail/static/src/models/thread_view/thread_view.js')
-rw-r--r--addons/mail/static/src/models/thread_view/thread_view.js71
1 files changed, 71 insertions, 0 deletions
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
@@ -69,6 +69,33 @@ function factory(dependencies) {
/**
* @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}
*/
_computeThreadCacheInitialScrollHeight() {
@@ -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',
}),
@@ -288,6 +333,20 @@ function factory(dependencies) {
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`.
*/
thread: many2one('mail.thread', {
@@ -336,6 +395,18 @@ function factory(dependencies) {
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.
*/