]> git.mjollnir.org Git - moodle.git/commitdiff
CHAT_MOD/MDL-14651
authordongsheng <dongsheng>
Wed, 19 Nov 2008 04:22:10 +0000 (04:22 +0000)
committerdongsheng <dongsheng>
Wed, 19 Nov 2008 04:22:10 +0000 (04:22 +0000)
1. support BEEP message
2. add "console" object to debug

mod/chat/gui_ajax/common.php
mod/chat/gui_ajax/index.php
mod/chat/gui_ajax/post.php
mod/chat/gui_ajax/update.php

index 5ed757c82deb0b1968acdc3c739f09cde27a54ab..c9bbf666ee1242d3565c6d6bef1bde1394454d54 100755 (executable)
@@ -5,13 +5,14 @@ function microtime_float(){
     return ((float)$usec+(float)$sec);
 }
 
-function format_user_list(&$data, $course) {
+function format_user_list($data, $course) {
     global $CFG, $DB;
     $users = array();
     foreach($data as $v){
         $user['name'] = fullname($v);
         $user['url'] = $CFG->wwwroot.'/user/view.php?id='.$v->id.'&amp;course='.$course->id;
         $user['picture'] = print_user_picture($v->id, 0, $v->picture, false, true, false);
+        $user['id'] = $v->id;
         $users[] = $user;
     }
     return $users;
index 530ee23fabf0f0be161c89ab3af0c8242848cea0..f7f3555686e2e55ee455ad099d2bd3809536c925 100644 (file)
@@ -60,7 +60,7 @@ if (!$chat_sid = chat_login_user($chat->id, 'ajax', $groupid, $course)) {
 <link rel="stylesheet" type="text/css" href="<?php echo $CFG->httpswwwroot;?>/lib/yui/layout/assets/skins/sam/layout.css" />
 <link rel="stylesheet" type="text/css" href="<?php echo $CFG->httpswwwroot;?>/lib/yui/button/assets/skins/sam/button.css" />
 <?php
-print_js_config(array('sid'=>$chat_sid,'timer'=>5000, 'chat_lasttime'=>0,'chat_lastrow'=>null, 'header_title'=>$strchat), 'chat_cfg');
+print_js_config(array('userid'=>$USER->id, 'sid'=>$chat_sid,'timer'=>5000, 'chat_lasttime'=>0,'chat_lastrow'=>null,'header_title'=>$strchat,'chatroom_name'=>$str_title), 'chat_cfg');
 print_js_config(array('send'=>$str_send, 'sending'=>$str_sending), 'chat_lang');
 ?>
 <script type="text/javascript" src="<?php echo $CFG->httpswwwroot;?>/lib/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
@@ -93,5 +93,7 @@ print_js_config(array('send'=>$str_send, 'sending'=>$str_sending), 'chat_lang');
 <ul id="msg_list">
 <ul>
 </div>
+<div id="notify">
+</div>
 </body>
 </html>
index 6c0015a74f8cb1163359ad0eda804c1c6e46c7ef..2977548c675f244160803fc5c880bac56393f916 100755 (executable)
@@ -3,7 +3,8 @@ include('../../../config.php');
 include('../lib.php');
 
 $chat_sid     = required_param('chat_sid', PARAM_ALPHANUM);
-$chat_message = required_param('chat_message', PARAM_RAW);
+$chat_message = optional_param('chat_message', '', PARAM_RAW);
+$beep_id      = optional_param('beep', '', PARAM_RAW);
 
 if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
     echo 'invalid sid';
@@ -24,11 +25,9 @@ session_write_close();
 chat_delete_old_users();
 $chat_message = clean_text($chat_message, FORMAT_MOODLE);
 
-//TODO: Before insert the chat message into database, we should push the
-//message into a global object (which can hold 100 messages), when user request
-//the lastest messages, we compare the oldest messsage's timestamp $a to user's
-//timestamp $b, if $a<$b, directly return messages in global object, otherwise,
-//fetch the message from database.
+if (!empty($beep_id)) {
+    $chat_message = 'beep '.$beep_id;
+}
 
 if (!empty($chat_message)) {
     $message = new object();
@@ -49,4 +48,3 @@ if (!empty($chat_message)) {
 
     add_to_log($course->id, 'chat', 'talk', "view.php?id=$cm->id", $chat->id, $cm->id);
 }
-?>
index ae2c8d49e4e6ab3c2b6b1febb9e1a814c6575de9..5947488dda0273d85dfd5f682ba82e0b494e9b0d 100755 (executable)
@@ -109,10 +109,10 @@ header('Content-Type: text/html; charset=utf-8');
 
 ob_start();
 
-$beep = false;
 $sendlist = false;
 if ($messages && ($chat_lasttime != $chat_newlasttime)) {
     foreach ($messages as $n => &$message) {
+        $tmp = new stdclass;
         // when somebody enter room, user list will be updated
         if($message->system == 1){
             $sendlist = true;
@@ -123,11 +123,15 @@ if ($messages && ($chat_lasttime != $chat_newlasttime)) {
             }
             $users = format_user_list($users, $course);
         }
-        $html = chat_format_message($message, $chatuser->course, $USER, $chat_lastrow);
-        if ($html->beep) {
-             $beep = true;
+        if ($html = chat_format_message($message, $chatuser->course, $USER, $chat_lastrow)) {
+            if ($html->beep) {
+                $tmp->type = 'beep';
+            }
+            $tmp->msg  = $html->html;
+            $message = $tmp;
+        } else {
+            unset($message);
         }
-        $message = $html->html;
     }
 }
 
@@ -136,10 +140,6 @@ if($users && $sendlist){
     $response['users'] = $users;
 }
 
-if ($beep) {
-    $response['beep'] = true;
-}
-
 $response['lasttime'] = $chat_newlasttime;
 $response['lastrow']  = $chat_newrow;
 if($messages){