Skip to content
Browse files

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.

Author: Donal McMullan <donal@catalyst.net.nz>
  • Loading branch information...
1 parent 7203acd commit 551d2b59bf60a65fa9ad696ec161d1aa9027d5dc martinlanghoff committed Jul 12, 2006
Showing with 21 additions and 5 deletions.
  1. +16 −4 mod/chat/gui_header_js/chatinput.php
  2. +1 −1 mod/chat/gui_header_js/insert.php
  3. +4 −0 theme/standard/styles_color.css
View
20 mod/chat/gui_header_js/chatinput.php
@@ -29,13 +29,25 @@
?>
<script type="text/javascript">
<!--
+ var waitFlag = false;
function empty_field_and_submit() {
- document.sendForm.chat_message.value = document.inputForm.chat_message.value;
- document.inputForm.chat_message.value = '';
+ if(waitFlag) return false;
+ waitFlag = true;
+ var input_chat_message = document.getElementById('input_chat_message');
+ document.sendForm.chat_message.value = input_chat_message.value;
+ input_chat_message.value = '';
+ input_chat_message.className = 'wait';
document.sendForm.submit();
- document.inputForm.chat_message.focus();
return false;
}
+
+ function enableForm() {
+ var input_chat_message = document.getElementById('input_chat_message');
+ waitFlag = false;
+ input_chat_message.className = '';
+ input_chat_message.focus();
+ }
+
// -->
</script>
<?php
@@ -46,7 +58,7 @@ function empty_field_and_submit() {
?>
<form action="../empty.php" method="POST" target="empty" name="inputForm"
OnSubmit="return empty_field_and_submit()">
- &gt;&gt;<input type="text" name="chat_message" size="60" value="" />
+ &gt;&gt;<input type="text" id="input_chat_message" name="chat_message" size="60" value="" />
<?php helpbutton('chatting', get_string('helpchatting', 'chat'), 'chat', true, false); ?>
</form>
View
2 mod/chat/gui_header_js/insert.php
@@ -58,7 +58,7 @@
if ($chatuser->version == 'header_js') {
/// force msg referesh ASAP
- echo '<script type="text/javascript">parent.jsupdate.location.href = parent.jsupdate.document.anchors[0].href;</script>';
+ echo '<script type="text/javascript">parent.jsupdate.location.href = parent.jsupdate.document.anchors[0].href;parent.input.enableForm();</script>';
}
redirect('../empty.php');
View
4 theme/standard/styles_color.css
@@ -709,6 +709,10 @@ table.message_search_results td {
color:#888
}
+#mod-chat-gui_header_js-chatinput .wait {
+ background: #dddddd;
+}
+
/***
*** Modules: Choice
***/

0 comments on commit 551d2b5

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