summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/composers/basic_composer.js
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2018-08-11 21:02:55 +0200
committerAlexandre Kühn <aku@odoo.com>2018-08-13 14:17:40 +0200
commit5f1d32f3fb89f40740b25491caafb9a5710d555a (patch)
treed94aab4d0a6fb36d60079391216b3dd4c89b23c7 /addons/mail/static/src/js/composers/basic_composer.js
parent614f9f84d7da281b0feacc39a612c19193f3a4d8 (diff)
[IMP] mail, im_livechat: 'is typing...' indicator on mail channels
With this commit, most threads show an indicator when a member is typing something. e.g. "Mitchell Stephens is typing..." Supported threads: - DM - (public & private) channels - Livechat (Website & Backend) Unsupported threads: - mailboxes (e.g. 'Inbox') - document thread (= 'Chatter') - support channel (with `im_support` module) Some technical details: - This is a mix between 'start'/'stop' and 'regular notify' strategies. - On typing text in composer: notify 'start typing' to all members of thread. - On clearing text in composer: notify 'stop typing' to all members of thread. - A member can only notify once every 2.5 seconds to the server when he starts or stops typing something (throttled, buffered notify call). - On receiving a message from someone that is typing: determine that he is no longer typing. - On non-empty and unchanged composer text for 5.0 seconds: automatically notifies all members of thread that he is no longer typing anything. (This is like a 'soft / cooperative sender' timeout). - On non-receiving a typing notification of someone after 60 seconds: determine that he is not longer typing something (This is like a 'hard / receiver assumption' timeout). - When some types for more than 50 seconds straight: notify that he is still typing something (again and again every 50 seconds). - When two or more people are typing something (Multi-User channels), it displays at most 2 typing users (ordering rule: longer typers first): "Mitchell Stephens, Marc Brown and more are typing..." - Timing summary: - Usually 2.5 seconds uncertainty. - Up to 5.0 seconds uncertainty on typer inactivity. - Up to 60 seconds uncertainty on typer page reload / browser tab closed / etc. Future Improvements: - Detect page reload or browser tab close with loose of longpolling connection Task-ID 28188
Diffstat (limited to 'addons/mail/static/src/js/composers/basic_composer.js')
-rw-r--r--addons/mail/static/src/js/composers/basic_composer.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/addons/mail/static/src/js/composers/basic_composer.js b/addons/mail/static/src/js/composers/basic_composer.js
index bba52c3f8b2..a6cdb39e2de 100644
--- a/addons/mail/static/src/js/composers/basic_composer.js
+++ b/addons/mail/static/src/js/composers/basic_composer.js
@@ -28,6 +28,7 @@ var BasicComposer = Widget.extend({
'focusout .o_composer_button_emoji': '_onEmojiButtonFocusout',
'click .o_mail_emoji_container .o_mail_emoji': '_onEmojiImageClick',
'focus .o_mail_emoji_container .o_mail_emoji': '_onEmojiImageFocus',
+ 'input .o_input': '_onInput',
'keydown .o_composer_input textarea': '_onKeydown',
'keyup .o_composer_input': '_onKeyup',
'click .o_composer_button_send': '_sendMessage',
@@ -185,6 +186,14 @@ var BasicComposer = Widget.extend({
this.$input.val(state.text);
},
/**
+ * Set the thread that this composer refers to.
+ *
+ * @param {mail.model.Thread} thread
+ */
+ setThread: function (thread) {
+ this.options.thread = thread;
+ },
+ /**
* Set the list of command suggestions on the thread.
*
* When the user partially types a command, matching commands are displayed
@@ -562,6 +571,17 @@ var BasicComposer = Widget.extend({
clearTimeout(this._hideEmojisTimeout);
},
/**
+ * Called when the input in the composer changes
+ *
+ * @private
+ */
+ _onInput: function () {
+ if (this.options.thread && this.options.thread.hasTypingNotification()) {
+ var isTyping = this.$input.val().length > 0;
+ this.options.thread.setMyselfTyping({ typing: isTyping });
+ }
+ },
+ /**
* _onKeydown event is triggered when is key is pressed
* - on UP and DOWN arrow is pressed then event prevents it's default
* behaviour if mention manager is open else it break it.