Skip to content

Commit

Permalink
chat: Prevent user from submitting a 2nd message before his 1st is re…
Browse files Browse the repository at this point in the history
…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
martinlanghoff committed Jul 12, 2006
1 parent 1a9b9a0 commit 07b76ba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
20 changes: 16 additions & 4 deletions mod/chat/gui_header_js/chatinput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion mod/chat/gui_header_js/insert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 4 additions & 0 deletions theme/standard/styles_color.css
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,10 @@ table.message_search_results td {
color:#888
}

#mod-chat-gui_header_js-chatinput .wait {
background: #dddddd;
}

/***
*** Modules: Choice
***/
Expand Down

0 comments on commit 07b76ba

Please sign in to comment.