From: moodler Date: Sat, 14 Aug 2004 16:45:13 +0000 (+0000) Subject: Latest goodness from PJ the MAN! X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=dfd629d7687e543e6818ca42ea5c9cc875299d9e;p=moodle.git Latest goodness from PJ the MAN! --- diff --git a/mod/chat/chatd.php b/mod/chat/chatd.php index 91dcbb5f2c..714fd0c4ca 100755 --- a/mod/chat/chatd.php +++ b/mod/chat/chatd.php @@ -135,9 +135,9 @@ class ChatDaemon { else { foreach ($this->sets_info as $usersid => $userinfo) { $lastping = $timenow - $userinfo['chatuser']->lastmessageping; + $popuppar = '\'/user/view.php?id='.$userinfo['user']->id.'&course='.$userinfo['courseid'].'\',\'user'.$userinfo['chatuser']->id.'\',\'\''; echo ''; - - echo ''; + echo ''; print_user_picture($userinfo['user']->id, 0, $userinfo['user']->picture, false, false, false); echo ""; echo "

"; @@ -282,6 +282,20 @@ class ChatDaemon { break; case CHAT_SIDEKICK_MESSAGE: // Incoming message + + // Browser stupidity protection from duplicate messages: + $messageindex = intval($customdata['index']); + + if($this->sets_info[$sessionid]['lastmessageindex'] >= $messageindex) { + // We have already broadcasted that! + trace('discarding message with stale index'); + break; + } + else { + // Update our info + $this->sets_info[$sessionid]['lastmessageindex'] = $messageindex; + } + $msg = &New stdClass; $msg->chatid = $this->sets_info[$sessionid]['chatid']; $msg->userid = $this->sets_info[$sessionid]['userid']; @@ -377,6 +391,7 @@ class ChatDaemon { // code base to follow suit. But AFTER development is done. $this->sets_info[$sessionid] = array( 'lastinfocommit' => 0, + 'lastmessageindex' => 0, 'courseid' => $course->id, 'chatuser' => $chatuser, 'chatid' => $chatuser->chatid, @@ -795,13 +810,13 @@ while(true) { break; case 'message': $type = CHAT_SIDEKICK_MESSAGE; - if(!ereg('chat_message=([^&]*)[& ]', $data, $info)) { + if(!ereg('chat_message=([^&]*)[& ]chat_msgidnr=([^&]*)[& ]', $data, $info)) { trace('Message sidekick did not contain a valid message', E_USER_WARNING); $DAEMON->dismiss_ufo($handle); continue; } else { - $customdata = array('message' => $info[1]); + $customdata = array('message' => $info[1], 'index' => $info[2]); } break; default: diff --git a/mod/chat/gui_sockets/chatinput.php b/mod/chat/gui_sockets/chatinput.php index 01d5f1dd3f..990c43d3be 100644 --- a/mod/chat/gui_sockets/chatinput.php +++ b/mod/chat/gui_sockets/chatinput.php @@ -32,7 +32,8 @@ optional_variable($chat_pretext, ''); scroll_active = true; function empty_field_and_submit() { cf = document.getElementById('chatform'); - cf.chat_message.value=document.f.chat_message.value; + cf.chat_msgidnr.value = parseInt(cf.chat_msgidnr.value) + 1; + cf.chat_message.value = document.f.chat_message.value; cf.submit(); document.f.chat_message.value=''; document.f.chat_message.focus(); @@ -42,10 +43,7 @@ function empty_field_and_submit() { - - - + - - - - - + + + + + +