Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

chat: Prevent user from submitting a 2nd message before his 1st is re…

…ceived.

Some users reported that mod/chat was silently dropping some messages. The
user's browser may not be able to keep up with the rate at which he submits
chat messages. This update keeps things sane.

Merged from MOODLE_16_STABLE

Author: Donal McMullan <donal@catalyst.net.nz>
  • Loading branch information...
commit 07b76bad6af1b31bfaf40728fce791f611e0d497 1 parent 1a9b9a0
martinlanghoff authored
20 mod/chat/gui_header_js/chatinput.php
@@ -29,13 +29,25 @@
29 29 ?>
30 30 <script type="text/javascript">
31 31 <!--
  32 + var waitFlag = false;
32 33 function empty_field_and_submit() {
33   - document.sendForm.chat_message.value = document.inputForm.chat_message.value;
34   - document.inputForm.chat_message.value = '';
  34 + if(waitFlag) return false;
  35 + waitFlag = true;
  36 + var input_chat_message = document.getElementById('input_chat_message');
  37 + document.sendForm.chat_message.value = input_chat_message.value;
  38 + input_chat_message.value = '';
  39 + input_chat_message.className = 'wait';
35 40 document.sendForm.submit();
36   - document.inputForm.chat_message.focus();
37 41 return false;
38 42 }
  43 +
  44 + function enableForm() {
  45 + var input_chat_message = document.getElementById('input_chat_message');
  46 + waitFlag = false;
  47 + input_chat_message.className = '';
  48 + input_chat_message.focus();
  49 + }
  50 +
39 51 // -->
40 52 </script>
41 53 <?php
@@ -46,7 +58,7 @@ function empty_field_and_submit() {
46 58 ?>
47 59 <form action="../empty.php" method="POST" target="empty" name="inputForm"
48 60 OnSubmit="return empty_field_and_submit()">
49   - &gt;&gt;<input type="text" name="chat_message" size="60" value="" />
  61 + &gt;&gt;<input type="text" id="input_chat_message" name="chat_message" size="60" value="" />
50 62 <?php helpbutton('chatting', get_string('helpchatting', 'chat'), 'chat', true, false); ?>
51 63 </form>
52 64
2  mod/chat/gui_header_js/insert.php
@@ -58,7 +58,7 @@
58 58
59 59 if ($chatuser->version == 'header_js') {
60 60 /// force msg referesh ASAP
61   - echo '<script type="text/javascript">parent.jsupdate.location.href = parent.jsupdate.document.anchors[0].href;</script>';
  61 + echo '<script type="text/javascript">parent.jsupdate.location.href = parent.jsupdate.document.anchors[0].href;parent.input.enableForm();</script>';
62 62 }
63 63
64 64 redirect('../empty.php');
4 theme/standard/styles_color.css
@@ -709,6 +709,10 @@ table.message_search_results td {
709 709 color:#888
710 710 }
711 711
  712 +#mod-chat-gui_header_js-chatinput .wait {
  713 + background: #dddddd;
  714 +}
  715 +
712 716 /***
713 717 *** Modules: Choice
714 718 ***/

0 comments on commit 07b76ba

Please sign in to comment.
Something went wrong with that request. Please try again.